Menü schliessen
Created: September 25th 2022
Last updated: September 25th 2022
Categories: IT Development,  Php,  Wordpress
Author: Miljan Puzovic

WordPress: Plugin updater for external (self-hosted) resources

Tags:  github,  package,  PHP,  wordpress
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

While I was working on internal WP plugin, I had to find a way to automatically check and update that plugin. Therefore, I have created a PHP class PluginUpdater which would make it easy for the whole team to implement on multiple plugins. PluginUpdater has GPL-2.0 licence and it's free to use.

Installation

It's available on GitHub, from where it can be downloaded and included manually. However, the recommended way is to use Composer, because it's also available on Packagist. In that case it can be easy included using:

composer require lexo/plugin-updater

Keep in mind that PluginUpdater requires PHP >=7.4.1 and it's tested up to PHP 8.1.9

Versioning

Release tags are created with Semantic versioning in mind. Commit messages were following convention of Conventional Commits.

Usage example

(new PluginUpdater())
    ->setBasename(BASENAME)
    ->setSlug(PLUGIN_SLUG)
    ->setVersion(VERSION)
    ->setRemotePath('https://website.tld/path/info.json')
    ->setCacheKey(CACHE_KEY)
    ->setCacheExpiration(12 * HOUR_IN_SECONDS)
    ->setCache(true)
    ->run();

For more details you can check out GitHub or Packagist pages.