Appearance
Auto Updates
Enable automatic updates for your WordPress plugin using PackEdge.
Installation
bash
composer require packedge-sdk/licenseQuick Setup
php
use PackEdge\License;
$license = License::init('pk_your_public_key', __FILE__);
$license->updater();That's it. The SDK hooks into WordPress's update system automatically.
How It Works
- WordPress checks for updates periodically
- The SDK queries PackEdge's update check endpoint
- If a newer version exists, it appears in the WordPress updates screen
- When the user clicks "Update", WordPress downloads the ZIP from PackEdge
- The SDK fixes folder names to match your plugin slug
Complete Example
php
<?php
/**
* Plugin Name: My Plugin
* Version: 1.0.0
*/
require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';
use PackEdge\License;
$license = License::init('pk_your_public_key', __FILE__);
// Enable auto-updates (only works if license is valid)
$license->updater();What the Updater Does
The Updater class hooks into three WordPress filters:
1. Update Check
pre_set_site_transient_update_plugins — Checks if a new version is available.
2. Plugin Info
plugins_api — Shows version details in the "View Details" popup.
3. Folder Fix
upgrader_source_selection — Renames the extracted folder to match your plugin slug.
Requirements
- Valid license key saved in WordPress options
- Release uploaded to PackEdge console
- Plugin slug matches your product slug
Manual Integration
If you prefer not to use the SDK, hook into WordPress directly:
php
add_filter('pre_set_site_transient_update_plugins', function($transient) {
$license_key = get_option('my_plugin_license')['key'] ?? '';
if (!$license_key) return $transient;
$response = wp_remote_get(add_query_arg([
'public_key' => 'pk_your_public_key',
'slug' => 'my-plugin',
'license_key' => $license_key,
'version' => MY_PLUGIN_VERSION,
], 'https://api.packedge.dev/public/v1/wp/update-check'));
if (is_wp_error($response)) return $transient;
$update = json_decode(wp_remote_retrieve_body($response));
if (isset($update->version) && version_compare(MY_PLUGIN_VERSION, $update->version, '<')) {
$transient->response['my-plugin/my-plugin.php'] = (object) [
'slug' => $update->slug,
'new_version' => $update->version,
'package' => $update->package,
];
}
return $transient;
});Troubleshooting
Updates not showing
- Check license is valid:
$license->is_valid() - Verify release is published in PackEdge console
- Check current version is older than release version
- Clear WordPress update transients:
delete_site_transient('update_plugins')
Wrong folder name after update
The SDK automatically fixes this, but if using manual integration, add:
php
add_filter('upgrader_source_selection', function($source, $remote_source, $upgrader, $hook_extra) {
if (!isset($hook_extra['plugin']) || $hook_extra['plugin'] !== 'my-plugin/my-plugin.php') {
return $source;
}
$correct_path = trailingslashit($remote_source) . 'my-plugin';
if ($source !== $correct_path) {
rename($source, $correct_path);
return $correct_path;
}
return $source;
}, 10, 4);