WordPress Plugin Updater SDK #
Integrate auto-updates into a WordPress plugin using the native WordPress update system.
Files #
sdk/php/wordpress/class-dmsi-wp-plugin-updater.php
sdk/php/examples/wordpress-plugin.php
How It Works #
The DMSI_WP_Plugin_Updater class hooks into WordPress's built-in plugin update system. When WordPress checks for plugin updates, the updater queries your Update Server. If an update is available, WordPress shows the standard "update available" notice in the Plugins screen and users can update with one click — exactly like a WordPress.org plugin.
Requirements #
- A
DMSI_Update_Clientinstance (the base PHP SDK) - The customer's license key stored in a WordPress option
Basic Integration #
Add this code to your plugin's main file:
require_once plugin_dir_path(__FILE__) . 'updater/class-dmsi-update-client.php';
require_once plugin_dir_path(__FILE__) . 'updater/class-dmsi-wp-plugin-updater.php';
add_action('init', function() {
$client = new DMSI_Update_Client([
'api_url' => 'https://yoursite.com',
'product_id' => 42,
]);
$updater = new DMSI_WP_Plugin_Updater([
'client' => $client,
'plugin_file' => plugin_basename(__FILE__),
'plugin_slug' => 'your-plugin/your-plugin.php',
'version' => '1.0.0', // current installed version
'license_key' => get_option('your_plugin_license_key', ''),
]);
$updater->init();
});
Updating the License Key #
If the user enters or changes their license key (e.g., in your plugin's settings):
$updater->set_license_key($new_license_key);
Forcing a Check #
To force an immediate update check (e.g., after activation or license key change):
$update_info = $updater->force_check();
Constructor Options #
| Option | Required | Description |
|---|---|---|
client | Yes | DMSI_Update_Client instance |
plugin_file | Yes | plugin_basename() of your plugin |
plugin_slug | Yes | Plugin slug (folder/file.php) |
version | Yes | Currently installed version |
license_key | Yes | Customer's license key (empty string if not yet entered) |
cache_ttl | No | Cache duration in seconds (default: 43200 = 12 hours) |
