2017 © Pedro Peláez
 

library plugin-update-checker

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

image

yahnis-elsts/plugin-update-checker

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  • Tuesday, July 17, 2018
  • by YahnisElsts
  • Repository
  • 76 Watchers
  • 795 Stars
  • 25,044 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 173 Forks
  • 33 Open issues
  • 23 Versions
  • 15 % Grown

The README.md

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., (*1)

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., (*2)

Table of Contents, (*3)

Getting Started

Note: In each of the below examples, part of the instructions is to create an instance of the update checker class. It's recommended to do this either during the plugins_loaded action or outside of any hooks. If you do it only during an admin_* action, then updates will not be visible to a wide variety of WordPress management tools; they will only be visible to logged-in users on dashboard pages., (*4)

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., (*5)

    • Plugin example:, (*6)

      {
          "name" : "Plugin Name",
          "version" : "2.0",
          "download_url" : "https://example.com/plugin-name-2.0.zip",
          "sections" : {
              "description" : "Plugin description here. You can use HTML."
          }
      }
      

      This is a minimal example that leaves out optional fields. See this table for a full list of supported fields and their descriptions., (*7)

    • Theme example:, (*8)

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

      This is actually a complete example that shows all theme-related fields. version and download_url should be self-explanatory. The details_url key specifies the page that the user will see if they click the "View version 1.2.3 details" link in an update notification., (*9)

  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:, (*10)

    require 'path/to/plugin-update-checker/plugin-update-checker.php';
    use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
    
    $myUpdateChecker = PucFactory::buildUpdateChecker(
        'https://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., (*11)

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., (*12)

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:, (*13)

  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

  • The second argument passed to buildUpdateChecker must be the absolute path to the main plugin file or any file in the theme directory. If you followed the "getting started" instructions, you can just use the __FILE__ constant.
  • The third argument - i.e. the slug - is optional but recommended. In most cases, the slug should be the same as the name of your plugin directory. For example, if your plugin lives in /wp-content/plugins/my-plugin, set the slug to my-plugin. If the slug is omitted, the update checker will use the name of the main plugin file as the slug (e.g. my-cool-plugin.phpmy-cool-plugin). This can lead to conflicts if your plugin has a generic file name like plugin.php., (*14)

    This doesn't affect themes because PUC uses the theme directory name as the default slug. Still, if you're planning to use 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., (*15)

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:, (*16)

    require 'plugin-update-checker/plugin-update-checker.php';
    use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
    
    $myUpdateChecker = PucFactory::buildUpdateChecker(
        'https://github.com/user-name/repo-name/',
        __FILE__,
        'unique-plugin-or-theme-slug'
    );
    
    //Set the branch that contains the stable release.
    $myUpdateChecker->setBranch('stable-branch-name');
    
    //Optional: If you're using a private repository, specify the access token like this:
    $myUpdateChecker->setAuthentication('your-token-here');
    
  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., (*17)

  • GitHub releases, (*18)

    Create a new release using the "Releases" feature on GitHub. The tag name and release title don't matter. The description is optional, but if you do provide one, it will be displayed when the user clicks the "View version x.y.z details" link on the "Plugins" page. Note that PUC ignores releases marked as "This is a pre-release"., (*19)

    If you want to use release assets, call the enableReleaseAssets() method after creating the update checker instance:, (*20)

    $myUpdateChecker->getVcsApi()->enableReleaseAssets();
    
  • Tags, (*21)

    To release version 1.2.3, create a new Git tag named v1.2.3 or 1.2.3. That's it., (*22)

    PUC doesn't require strict adherence to SemVer. These are all valid tag names: v1.2.3, v1.2-foo, 1.2.3_rc1-ABC, 1.2.3.4.5. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitHub releases or branches instead., (*23)

  • Stable branch, (*24)

    Point the update checker at a stable, production-ready branch: php $updateChecker->setBranch('branch-name'); PUC will periodically check the Version header in the main plugin file or style.css and display a notification if it's greater than the installed version., (*25)

    Caveat: If you set the branch to master (the default), the update checker will look for recent releases and tags first. It'll only use the master branch if it doesn't find anything else suitable., (*26)

Notes

The library will pull update details from the following parts of a release/tag/branch:, (*27)

  • Version number
    • The "Version" plugin header.
    • The latest GitHub release or tag name.
  • Changelog
    • The "Changelog" section of readme.txt.
    • One of the following files: CHANGES.md, CHANGELOG.md, changes.md, changelog.md
    • GitHub release notes.
  • Required and tested WordPress versions
    • The "Requires at least" and "Tested up to" fields in readme.txt.
    • The following plugin headers: Required WP, Tested WP, Requires at least, Tested up to
  • "Last updated" timestamp
    • The creation timestamp of the latest GitHub release.
    • The latest commit in the selected tag or branch.
  • Number of downloads
    • The download_count statistic of the latest release.
    • If you're not using GitHub releases, there will be no download stats.
  • Other plugin details - author, homepage URL, description
    • The "Description" section of readme.txt.
    • Remote plugin headers (i.e. the latest version on GitHub).
    • Local plugin headers (i.e. the currently installed version).
  • Ratings, banners, screenshots
    • Not supported.

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:, (*28)

    require 'plugin-update-checker/plugin-update-checker.php';
    use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
    
    $myUpdateChecker = PucFactory::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:, (*29)

  • Stable tag header, (*30)

    This is the recommended approach if you're using tags to mark each version. Add a readme.txt file formatted according to the WordPress.org plugin readme standard to your repository. Set the "stable tag" header to the tag that represents the latest release. Example:, (*31)

    Stable tag: v1.2.3
    

    The tag doesn't have to start with a "v" or follow any particular format. You can use any name you like as long as it's a valid Git tag., (*32)

    Tip: If you explicitly set a stable branch, the update checker will look for a readme.txt in that branch. Otherwise it will only look at the master branch., (*33)

  • Tags, (*34)

    You can skip the "stable tag" bit and just create a new Git tag named v1.2.3 or 1.2.3. The update checker will look at the most recent tags and pick the one that looks like the highest version number., (*35)

    PUC doesn't require strict adherence to SemVer. These are all valid tag names: v1.2.3, v1.2-foo, 1.2.3_rc1-ABC, 1.2.3.4.5. However, be warned that it's not smart enough to filter out alpha/beta/RC versions., (*36)

  • Stable branch, (*37)

    Point the update checker at a stable, production-ready branch: php $updateChecker->setBranch('branch-name'); PUC will periodically check the Version header in the main plugin file or style.css and display a notification if it's greater than the installed version. Caveat: If you set the branch to master, the update checker will still look for tags first., (*38)

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 and define how you want to check for updates from Gitlab (refer to: Gitlab: How to Release an Update):, (*39)

    require 'plugin-update-checker/plugin-update-checker.php';
    use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
    
    $myUpdateChecker = PucFactory::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');
    

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

    use YahnisElsts\PluginUpdateChecker\v5p5\Vcs\PluginUpdateChecker;
    use YahnisElsts\PluginUpdateChecker\v5p5\Vcs\GitLabApi;
    
    $myUpdateChecker = new PluginUpdateChecker(
        new GitLabApi('https://myserver.com/user-name/repo-name/'),
        __FILE__,
        'unique-plugin-or-theme-slug'
    );
    //Optional: Add setAuthentication(...) and setBranch(...) as shown above.  
    

    If you're using a self-hosted GitLab instance and subgroups or nested groups, you have to tell the update checker which parts of the URL are subgroups:, (*41)

    use YahnisElsts\PluginUpdateChecker\v5p5\Vcs\PluginUpdateChecker;
    use YahnisElsts\PluginUpdateChecker\v5p5\Vcs\GitLabApi;
    
    $myUpdateChecker = new PluginUpdateChecker(
        new GitLabApi(
            'https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/', 
            null, 
            'subgroup-level1/subgroup-level2/subgroup-level3'
        ),
        __FILE__,
        'unique-plugin-or-theme-slug'
    );
    
  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., (*42)

How to Release a GitLab Update

A GitLab repository can be checked for updates in 3 different ways., (*43)

  • GitLab releases, (*44)

    Create a new release using the "Releases" feature on GitLab. The tag name should match the version number. You can add a v prefix to the tag, like v1.2.3. Releases that are marked as "Upcoming Release" will be automatically ignored., (*45)

    If you want to use custom release assets, call the enableReleaseAssets() method after creating the update checker instance:, (*46)

    $myUpdateChecker->getVcsApi()->enableReleaseAssets();
    

    By default, PUC will use the first available asset link, regardless of type. You can pass a regular expression to enableReleaseAssets() to make it pick the first link where the URL matches the regex. For example:, (*47)

    $myUpdateChecker->getVcsApi()->enableReleaseAssets('/\.zip($|[?&#])/i');
    

    Tip: You can use a Gitlab CI/CD Pipeline to automatically generate your update on release using a Generic Package. For more information about generic packages, refer to the following links: - Gitlab CI/CD Release Documentation - Gitlab Release Assets as Generic Package Documentation - Example .gitlab-ci.yml file using Release Generic Packages for generating a update package from the Sensei-LMS wordpress plugin, (*48)

  • Tags, (*49)

    To release version 1.2.3, create a new Git tag named v1.2.3 or 1.2.3. The update checker will look at recent tags and use the one that looks like the highest version number., (*50)

    PUC doesn't require strict adherence to SemVer. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead., (*51)

  • Stable branch, (*52)

    Point the update checker at any stable, production-ready branch:, (*53)

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

    PUC will periodically check the Version header in the main plugin file or style.css and display a notification if it's greater than the installed version. Caveat: Even if you set the branch to main (the default) or master (the historical default), the update checker will still look for recent releases and tags first., (*54)

Migrating from 4.x

Older versions of the library didn't use namespaces. Code that was written for those versions will need to be updated to work with the current version. At a minimum, you'll need to change the factory class name., (*55)

Old code:, (*56)

$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://example.com/info.json',
    __FILE__,
    'my-slug'
);

New code:, (*57)

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

$myUpdateChecker = PucFactory::buildUpdateChecker(
    'https://example.com/info.json',
    __FILE__,
    'my-slug'
);

Other classes have also been renamed, usually by simply removing the Puc_vXpY_ prefix and converting Category_Thing to Category\Thing. Here's a table of the most commonly used classes and their new names:, (*58)

Old class name New class name
Puc_v4_Factory YahnisElsts\PluginUpdateChecker\v5\PucFactory
Puc_v4p13_Factory YahnisElsts\PluginUpdateChecker\v5p5\PucFactory
Puc_v4p13_Plugin_UpdateChecker YahnisElsts\PluginUpdateChecker\v5p5\Plugin\UpdateChecker
Puc_v4p13_Theme_UpdateChecker YahnisElsts\PluginUpdateChecker\v5p5\Theme\UpdateChecker
Puc_v4p13_Vcs_PluginUpdateChecker YahnisElsts\PluginUpdateChecker\v5p5\Vcs\PluginUpdateChecker
Puc_v4p13_Vcs_ThemeUpdateChecker YahnisElsts\PluginUpdateChecker\v5p5\Vcs\ThemeUpdateChecker
Puc_v4p13_Vcs_GitHubApi YahnisElsts\PluginUpdateChecker\v5p5\Vcs\GitHubApi
Puc_v4p13_Vcs_GitLabApi YahnisElsts\PluginUpdateChecker\v5p5\Vcs\GitLabApi
Puc_v4p13_Vcs_BitBucketApi YahnisElsts\PluginUpdateChecker\v5p5\Vcs\BitBucketApi

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., (*59)

Resources

The Versions

17/07 2018

dev-master

9999999-dev https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

22/12 2017

v4.4

4.4.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

03/11 2017

v4.3.1

4.3.1.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

03/11 2017

v4.3

4.3.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

21/07 2017

v4.2

4.2.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

07/04 2017

v4.1

4.1.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

24/01 2017

v4.0.3

4.0.3.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

13/01 2017

v4.0.2

4.0.2.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

12/01 2017

v4.0.1

4.0.1.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

12/01 2017

dev-version4

dev-version4 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

11/01 2017

v4.0

4.0.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

10/01 2017

dev-theme-support

dev-theme-support https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates theme updates

08/12 2016

v3.2

3.2.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

11/05 2016

v3.1

3.1.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

05/05 2016

dev-language-packs

dev-language-packs https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

18/02 2016

v3.0

3.0.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

28/07 2015

v2.2

2.2.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

26/06 2015

v2.1

2.1.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

10/02 2015

v2.0

2.0.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

17/12 2014

v1.6.1

1.6.1.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

17/12 2014

v1.6

1.6.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

24/10 2014

1.6

1.6.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

GPL

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates

10/09 2014

v1.5

1.5.0.0 https://github.com/YahnisElsts/plugin-update-checker/

A custom update checker for WordPress plugins. Useful if you can't host your plugin in the official WP plugin repository but still want it to support automatic plugin updates.

  Sources   Download

GPL

The Requires

  • php >=5.2.0

 

wordpress automatic updates plugin updates