Plugin Update Checker

This is a custom update checker library for WordPress plugins and themes. It lets you add automatic update notifications and one-click upgrades to your commercial plugins, private themes, and so on. All you need to do is put your plugin/theme details in a JSON file, place the file on your server, and pass the URL to the library. The library periodically checks the URL to see if there's a new version available and displays an update notification to the user if necessary.

From the users' perspective, it works just like with plugins and themes hosted on WordPress.org. The update checker uses the default upgrade UI that is familiar to most WordPress users.

Table of Contents

Getting Started

Self-hosted Plugins and Themes

  1. Download the latest release and copy the plugin-update-checker directory to your plugin or theme.
  2. Go to the examples subdirectory and open the .json file that fits your project type. Replace the placeholder data with your plugin/theme details.

  3. Upload the JSON file to a publicly accessible location.
  4. Add the following code to the main plugin file or to the functions.php file:

     require 'path/to/plugin-update-checker/plugin-update-checker.php';
     $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
         'http://example.com/path/to/details.json',
         __FILE__, //Full path to the main plugin file or functions.php.
         'unique-plugin-or-theme-slug'
     );
    

    Note: If you're using the Composer autoloader, you don't need to explicitly require the library.

How to Release an Update

Change the version number in the JSON file and make sure that download_url points to the latest version. Update the other fields if necessary. Tip: You can use wp-update-server to automate this process.

By default, the library will check the specified URL for changes every 12 hours. You can force it to check immediately by clicking the "Check for updates" link on the "Plugins" page (it's next to the "Visit plugin site" link). Themes don't have that link, but you can also trigger an update check like this:

  1. Install Debug Bar.
  2. Click the "Debug" menu in the Admin Bar (a.k.a Toolbar).
  3. Open the "PUC (your-slug)" panel.
  4. Click the "Check Now" button.

Notes

GitHub Integration

  1. Download the latest release and copy the plugin-update-checker directory to your plugin or theme.
  2. Add the following code to the main plugin file or functions.php:

     require 'plugin-update-checker/plugin-update-checker.php';
     $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
         'https://github.com/user-name/repo-name/',
         __FILE__,
         'unique-plugin-or-theme-slug'
     );
    
     //Optional: If you're using a private repository, specify the access token like this:
     $myUpdateChecker->setAuthentication('your-token-here');
    
     //Optional: Set the branch that contains the stable release.
     $myUpdateChecker->setBranch('stable-branch-name');
    
  3. Plugins only: Add a readme.txt file formatted according to the WordPress.org plugin readme standard to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.

How to Release an Update

This library supports a couple of different ways to release updates on GitHub. Pick the one that best fits your workflow.

Notes

The library will pull update details from the following parts of a release/tag/branch:

BitBucket Integration

  1. Download the latest release and copy the plugin-update-checker directory to your plugin or theme.
  2. Add the following code to the main plugin file or functions.php:

     require 'plugin-update-checker/plugin-update-checker.php';
     $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
         'https://bitbucket.org/user-name/repo-name',
         __FILE__,
         'unique-plugin-or-theme-slug'
     );
    
     //Optional: If you're using a private repository, create an OAuth consumer
     //and set the authentication credentials like this:
     //Note: For now you need to check "This is a private consumer" when
     //creating the consumer to work around #134:
     // https://github.com/YahnisElsts/plugin-update-checker/issues/134
     $myUpdateChecker->setAuthentication(array(
         'consumer_key' => '...',
         'consumer_secret' => '...',
     ));
    
     //Optional: Set the branch that contains the stable release.
     $myUpdateChecker->setBranch('stable-branch-name');
    
  3. Optional: Add a readme.txt file formatted according to the WordPress.org plugin readme standard to your repository. For plugins, the contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.

How to Release an Update

BitBucket doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:

GitLab Integration

  1. Download the latest release and copy the plugin-update-checker directory to your plugin or theme.
  2. Add the following code to the main plugin file or functions.php:

     require 'plugin-update-checker/plugin-update-checker.php';
     $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
         'https://gitlab.com/user-name/repo-name/',
         __FILE__,
         'unique-plugin-or-theme-slug'
     );
    
     //Optional: If you're using a private repository, specify the access token like this:
     $myUpdateChecker->setAuthentication('your-token-here');
    
     //Optional: Set the branch that contains the stable release.
     $myUpdateChecker->setBranch('stable-branch-name');
    

    Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:

     $myUpdateChecker = new Puc_v4p7_Vcs_PluginUpdateChecker(
         new Puc_v4p7_Vcs_GitLabApi('https://myserver.com/user-name/repo-name/'),
         __FILE__,
         'unique-plugin-or-theme-slug'
     );
    //Optional: Add setAuthentication(...) and setBranch(...) as shown above.  
    
  3. Plugins only: Add a readme.txt file formatted according to the WordPress.org plugin readme standard to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.

How to Release an Update

GitLab doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:

License Management

Currently, the update checker doesn't have any built-in license management features. It only provides some hooks that you can use to, for example, append license keys to update requests ($updateChecker->addQueryArgFilter()). If you're looking for ways to manage and verify licenses, please post your feedback in this issue.

Resources