Given the recent concerns regarding publishing plugins or themes on wordpress.org, there has been much interest in other methods of distribution and updating within the ecosystem. Git Updater is a method of providing this type of service but it does have a drawback. The user must install and activate the Git Updater plugin along with any of the plugins or themes that are using it for updating.
Many developers would like a solution that can be directly incorporated into their projects. There are solutions out there to provide this functionality, but I feel they have a much higher overhead and are quite weighty. I have created a two part solution based upon Git Updater running on the developer’s site as an update server and a small composer library integrated with the plugin or theme.
Currently, an embedded updater must contain a fair amount of code to gather and create the necessary data to integrate with WordPress’ update transient. Git Updater performs all these functions with a series of API calls to the git host to gather data and then parse that data to a format that is tightly integrated into WP Core’s updating system. The integration with Git Updater is only a few additional headers in the main plugin file or in the theme’s style.css. Any embedded updater must accomplish something similar but for each individual plugin or theme. Consequently all the code to gather data from API calls to the git host must reside in the plugin or theme to be updated.
Since Git Updater already gathers and parses this data, Git Updater Lite only needs to query an update server run by the developer. Since the update server, and Git Updater, does all the heavy lifting the user has much less overhead and is able to gather the data in the proper format from the update server via a single REST API endpoint for each plugin or theme.
The primary advantage is that the most complicated code lies outside of the actual embedded updater library. It also means less overhead for the user’s site when that data needs to be refreshed.
Composer library
I have written a small composer library, afragen/git-updater-lite. Currently it is a single class file less than 300 lines and less than 7 Kb in size. This is significantly lighter weight than the current most popular embedded updater. The integration is only two lines of code. The reason that Git Updater Lite can be so lightweight is its tight integration with Git Updater on the update server.
REST API Endpoint
Git Updater has a REST API endpoint capable of providing a JSON response compatible with the plugins_api()
or themes_api()
. This REST endpoint requires that the plugin or theme is fully integrated with Git Updater. This integration is only a few additional headers in the main plugin file or the theme’s style.css file for Git Updater and only a small composer library and 2 lines of code to integrate git-updater-lite
.
Examples of the endpoints are as follows:
https://my-site.com/wp-json/git-updater/v1/plugins-api/?slug=my-plugin
https://my-site.com/wp-json/git-updater/v1/themes-api/?slug=my-theme
Obviously each individual distributed plugin or theme with git-updater-lite
must be active to receive updates.
Git Updater Lite is capable of serving updates from any of the following git hosts: GitHub, Bitbucket, GitLab, or Gitea. Currently Git Updater Lite supports public and private repositories. This support depends upon the developer having a complete integration of their own plugins and themes with Git Updater and that they host their own plugins/themes in a publicly accessible WordPress installation. These plugins and themes do not need to be active on their site to maintain the current versions.
The REST API endpoint returns a JSON response that provides all the information necessary to provide complete integration with the dashboard update system. The API data is cached via a transient for 6 hours.
Getting Started – For Developers
Step 1: Integrate your plugin or theme with Git Updater.
- Add the required headers to your plugin’s main file or your theme’s style.css
- Ensure that Git Updater is able to update your plugin or theme.
Step 2: Integrate your plugin or theme with Git Updater Lite
- Run
composer require afragen/git-updater-lite:^1
- Add the following lines to your main plugin file or theme’s functions.php
require_once __DIR__ . '/vendor/autoload.php';
( new \Fragen\Git_Updater\Lite( __FILE__ ) )->run('<URI>');
Code language: PHP (php)
- Change
<URI>
to your REST endpoint.- For a plugin:
https://my-site.com/wp-json/git-updater/v1/plugins-api/?slug=my-plugin
- For a theme:
https://my-site.com/wp-json/git-updater/v1/themes-api/?slug=my-theme
- For a plugin:
- Update your plugin or theme on the on the git host to this fully integrated version.
Step 3: Set up the update server.
- Have a publicly accessible WordPress installation, such as the plugin’s website.
- Install and activate Git Updater 12.7.0 or later.
- Install your plugin or theme via the Git Updater Install Plugin or Install Theme tabs. It doesn’t need to be active.
Access tokens
Any private repositories, or repositories on GitLab or Gitea, require an authentication token. If the tokens are set on the update server, they will be used via the API response for the Authentication header to download the update from the appropriate git host.
General Comments
This system puts slightly more work on the developer to have their plugins and themes integrated with both Git Updater and Git Updater Lite on their update server. After that, all they really need to do is set those plugins and themes to auto-update. This will help the update server continue to distribute up-to-date plugins and themes. Please refer to Git Updater’s Knowledge Base regarding versioning.
I believe this to be the simplest method of integrating an updater into your plugin or theme and update outside of the wp.org repositories.
There is more information at https://github.com/afragen/git-updater-lite. Please let me know if you have any issues integrating your projects with either Git Updater or Git Updater Lite. There is an example plugin at https://github.com/afragen/test-plugin-gu-lite. To test, I usually decrease the local version number.