Plugin updater for WooCommerce Software Add-on
Published: – Leave a comment
When I held a talk at WordCamp Deutschland in 2023 about selling software with WooCommerce and WordPress, I made the claim that I want to publish my solution for an update server connected to WooCommerce Software Add-on after I rewrote it.
And now, just a little more than 3 years later, that will be the case. 😬
Meet WP Plugin Updater, a package that handles updating and license handling for WooCommerce Software Add-on in combination with Yahnis Elsts’ wp-update-server. It is designed to be imported as Composer dependency (composer require epiphyt/wp-plugin-updater) and its initialization requires only a few lines of code:
use epiphyt\Plugin_Updater\Config;
use epiphyt\Plugin_Updater\Registry;
use epiphyt\Plugin_Updater\Strings;
\add_action( 'init', static function (): void {
$config = new Config(
plugin_basename: \MY_PLUGIN_BASE,
plugin_key: 'my_plugin',
product_id: 'My Plugin',
update_slug: 'my-plugin',
license_option_name: 'my_plugin_license_options',
settings_url: \admin_url( 'options-general.php?page=my-plugin&tab=license' ),
settings_page_slug: 'my-plugin',
strings: new Strings( [
Strings::ACTIVATION_FAILED_NOTICE => \__( 'License activation of %s failed:', 'my-plugin' ),
Strings::UNKNOWN_ERROR => \__( 'Unknown error.', 'my-plugin' ),
// …
] )
);
Registry::register( $config )->init();
}, 20 );
Code language: PHP (php)
You can find a detailed usage guide in the repository’s README.md at GitHub.
While the package itself is designed to work with WooCommerce Software Add-on and Yahnis Elsts’ wp-update-server, it can be adjusted to use a custom solution as well. You can also find an example for this in the repository’s README.md.
Reposts