Skip to content

Remote Management RESTful Endpoints

Andy Fragen edited this page Jan 15, 2020 · 10 revisions

Remote Management Services

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.

You must be using GitHub Updater v9.0.0+ on your sites for the Git Remote Updater.

The Git Remote Updater uses the Site URL and the REST API key associated with each individual site in it's Settings page.

make JSON file

Currently, GitHub 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 GitHub 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.

GitHub 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 GitHub 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/github-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 GitHub 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/github-updater/v1/update/?key=76bb2b7c819c36ee37292b6978a4ad61"
{
    "message": "No plugin or theme specified for update.",
    "success": false
}

This error message is given because GitHub 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/github-updater/v1/update/?key=76bb2b7c819c36ee37292b6978a4ad61&plugin=mickesplugin"
{
    "messages": [
        "Downloading update from <span class=\"code\">https:\/\/api.github.com\/repos\/limikael\/mickesplugin\/zipball\/master<\/span>&#8230;",
        "Unpacking the update&#8230;",
        "Installing the latest version&#8230;",
        "Removing the old version of the plugin&#8230;",
        "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 this 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, GitHub 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, GitHub 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.

NB: The previous /wp-admin/admin-ajax.php RESTful endpoint has been deprecated.

You can’t perform that action at this time.