Project Zero

Push to GitHub

With the Plugin Update Checker, you can use GitHub as your release server. In functions.php, you will see the following code:

require_once STYLESHEETPATH . '/inc/functions/puc/plugin-update-checker.php';
$checkTheme = Puc_v4_Factory::buildUpdateChecker(
  $mytheme->get('ThemeURI'), // This can be any public repo on GitHub, or any file on your own server, defaults to the Theme URI value in style.css
  __FILE__,
  $mytheme->get('TextDomain'), // Uses the 'Text Domain' string as defined in style.css
);
// Enables releases via GitHub
$checkTheme->getVcsApi()->enableReleaseAssets();

To make it easier to call your repository, we have used the ‘Theme URI’ header in your style.css file to save your GitHub repo (in the format of https://github.com/{USER-NAME}/{REPO-NAME}/). We have also used the ‘Text Domain’ header to save your theme’s unique slug. This argument in the PHP array is optional, but it is recommended. In most cases, the slug should be the same as the name of your theme directory. By default, it uses the theme directory name as the slug. The PUC GitHub page says that, “if you intend on [using or enforcing] the slug in your own code – e.g. to filter updates or override update checker behaviour – it can be a good idea to set it explicitly.”

The script comes with the ability to select a different branch for your stable release branch. By default, it will select the main/master branch, but you can override this by adding this line after the function:

$checkTheme->setBranch('stable-branch-name');

It also allows you to push out updates from private repositories. To do this, GitHub requires a personal access token, which you can generate in your account settings. Go to Settings > Developer Settings > Personal access tokens to generate a token. Once it has been generated, add this line after the function:

$checkTheme->setAuthentication('your-token-here');

If you do not want to use GitHub, you can use your own server to push out updates. Instead of the code already in your functions.php file, you will need to use this code:

require 'path/to/plugin-update-checker/plugin-update-checker.php';
$checkTheme = Puc_v4_Factory::buildUpdateChecker(
  'http://example.com/path/to/details.json', // The JSON file should contain the code below.
  __FILE__, //Full path to the main plugin file or functions.php.
  $mytheme->get('TextDomain'), // Uses the 'Text Domain' string as defined in style.css
);

On your server, at the URL you stated above, you should save a JSON file with the following information:

{
  "version": "2.0",
  "details_url": "http://example.com/version-2.0-details.html",
  "download_url": "http://example.com/example-theme-2.0.zip"
}

The information should refer to files on your server.

Just to note …

If you develop a theme for the WordPress Theme Directory, using any other release server will be against their terms of service. You will only be able to use Plugin Update Checker to release your own themes or to push out themes for development purposes.

Join the conversation

Your email address will not be published.