How Can We Help?
Remote Management – REST API Endpoints
Remote Management Services
The current REST route namespace is git-updater/v1
.
I have written the Git Remote Updater plugin to provide a simple, consistent method of remote site management. It will not tell you whether or not the plugin or theme has an update pending. What it will do is provide a simple method of remotely updating/reinstalling your plugins or themes using a similar method to branch switching. If you have any issues with any of the remote management services listed below, I encourage you to try this method.
The Git Remote Updater uses the Site URL and the REST API key associated with each individual site in it’s Settings page.
Currently, Git Updater should work with iThemes Sync, InfiniteWP, ManageWP, MainWP, or any other remote management service.
There will be overhead which may impact performance if using the filter to disable WP-Cron background updating and Git Updater, but only in the dashboard. It is best to not use this filter except when troubleshooting issues.
REST API Endpoints for Remote Management
For a tutorial, see: Continuous Integration for WordPress. This does refer to a previous version.
Git Updater also supports other customized continuous integration workflows. It is possible to integrate with other services than those discussed above. For this, the REST API endpoints are available in Git Updater to update themes and plugins to the latest version from their repositories.
On the Remote Management tab, you will see a URL that serves as the endpoint for this. This url will look something like this:
http://localhost/wp-json/git-updater/v1/update/?key=76bb2b7c819c36ee37292b6978a4ad61
The exact URL will of course depend on your system. The value for the key
attribute is automatically generated on the first activation of the Git Updater plugin and is used for authentication. Any person or entity knowing this key will be able to change the versions of your installed plugins, but nothing else.
Now, if we would use curl
to access the url exactly like it appears on the Remote Management tab, we would see something like this:
$ curl "http://localhost/wp-json/git-updater/v1/update/?key=76bb2b7c819c36ee37292b6978a4ad61"
{
"message": "No plugin or theme specified for update.",
"success": false
}
This error message is given because Git Updater requires us to specify either a theme or a plugin that we wish to update. This is specified using the theme
or plugin
attributes, and the theme or plugin is identified by its slug. Let’s try to update a plugin:
$ curl "http://localhost/wordpress/wp-json/git-updater/v1/update/?key=76bb2b7c819c36ee37292b6978a4ad61&plugin=mickesplugin"
{
"messages": [
"Downloading update from <span class=\"code\">https:\/\/api.github.com\/repos\/limikael\/mickesplugin\/zipball\/master<\/span>…",
"Unpacking the update…",
"Installing the latest version…",
"Removing the old version of the plugin…",
"Plugin updated successfully."
],
"success": true
}
And our plugin is updated! The messages displayed are those that otherwise would be displayed in the non-shiny WordPress admin interface.
The full list of attributes accepted by the update
REST API endpoint is shown here:
- key – The key as displayed on the Remote Management tab. The key passed to the endpoint in the api call must match the key stored on the system.
- plugin – Specify this to update a plugin. This is the plugin’s slug.
- theme – Specify this to update a theme. This is the theme’s slug.
- committish – Specify a particular tag, branch or commit for the update. If nothing is specified, it defaults to “master”.
- tag – An alias for the committish attribute.
- branch – Specify a specific branch for updating.
- override – Switch to use when current branch and request branch differ.
When using the REST API endpoints for updating themes or plugins, you need to specify at least the key
attribute, as well as one of the attributes plugin
or theme
. All other attributes are optional.
The REST API endpoints are useful for automatically updating themes and plugins on events sent as webhooks from GitHub and the other services supported by this plugin. Specifically, Git Updater checks the headers to see if the incoming request is from a
GitHub Webhook, a Bitbucket Webhook or a GitLab Webhook. If this is the case, and if the branch that was pushed to matches the branch specified in the branch
attribute, then the update will be made according to the latest commit specified in the event. If you create a webhook that fires when a tag or release is created, Git Updater will update from that tagged release. The results of the webhook will write to debug.log
if you have this enabled.
Thanks to Mikael Lindqvist for the PRs, he really made this happen.
The previous /wp-admin/admin-ajax.php
RESTful endpoint has been deprecated.
WP Engine does not allow unauthenticated users from changing files in the filesystem. As such, REST endpoints to update or reset will not work.
Reset Branch Endpoint
There is now a REST endpoint to enable the resetting of the plugin or theme’s current branch. If for some reason you are on a branch that has been deleted upstream, you will no longer get a valid API response for updating. The reason is that the API will specifically look to the current branch. If you run into this issue you will see that the plugin or theme shows an error about not being able to connect to the API. Additionally the HTTP response is likely to show a 404.
To reset the branch you must send a REST API endpoint of reset-branch
with an arg of either plugin
or theme
with the slug as the value. As an example.
https://localhost/wp-json/git-updater/v1/reset-branch/?key=xxxxxxxxxxxxxx&plugin=my-plugin
The full list of attributes accepted by the update
REST API endpoint is shown here:
- key – The key as displayed on the Remote Management tab. The key passed to the endpoint in the api call must match the key stored on the system.
- plugin – Specify this to update a plugin. This is the plugin’s slug.
- theme – Specify this to update a theme. This is the theme’s slug.
Plugins API endpoint
As of Git Updater v12.0.0 there is an endpoint that will return data similar to the plugins_api()
. This may be useful at a later time. You must obviously send this API call to a site that has both the current versions of Git Updater and the referenced plugin installed and with the correct header so Git Updater is capable of gathering data.
https://localhost/wp-json/git-updater/v1/plugins-api/?slug=my-plugin
Themes API endpoint
As of Git Updater v12.7.0 there is an endpoint that will return data similar to the themes_api()
. This may be useful at a later time. You must obviously send this API call to a site that has both the current versions of Git Updater and the referenced theme installed and with the correct header so Git Updater is capable of gathering data.
https://localhost/wp-json/git-updater/v1/themes-api/?slug=my-theme