WordPress Plugin Integration
PackEdge provides drop-in license validation and automatic update support for WordPress plugins.
Overview
Your WordPress plugin needs to handle two things:
- License validation — verify the license key is valid
- Auto-updates — check for and deliver updates from PackEdge
License Validation
Add a settings page where customers enter their license key, then validate it against the PackEdge API.
php
class MyPlugin_License {
private $api_url = 'https://api.packedge.dev/v1';
private $product_slug = 'my-plugin';
public function validate($license_key) {
$response = wp_remote_post($this->api_url . '/licenses/validate', [
'body' => json_encode([
'license_key' => $license_key,
'product_slug' => $this->product_slug,
'domain' => home_url(),
]),
'headers' => ['Content-Type' => 'application/json'],
'timeout' => 15,
]);
if (is_wp_error($response)) {
return ['valid' => false, 'error' => $response->get_error_message()];
}
return json_decode(wp_remote_retrieve_body($response), true);
}
public function activate($license_key) {
$response = wp_remote_post($this->api_url . '/licenses/activate', [
'body' => json_encode([
'license_key' => $license_key,
'domain' => home_url(),
]),
'headers' => ['Content-Type' => 'application/json'],
'timeout' => 15,
]);
return json_decode(wp_remote_retrieve_body($response), true);
}
public function deactivate($license_key) {
$response = wp_remote_post($this->api_url . '/licenses/deactivate', [
'body' => json_encode([
'license_key' => $license_key,
'domain' => home_url(),
]),
'headers' => ['Content-Type' => 'application/json'],
'timeout' => 15,
]);
return json_decode(wp_remote_retrieve_body($response), true);
}
}Auto-Updates
Hook into WordPress update system to check for updates from PackEdge.
php
class MyPlugin_Updater {
private $plugin_slug = 'my-plugin';
private $plugin_file = 'my-plugin/my-plugin.php';
private $api_url = 'https://api.packedge.dev/v1';
private $license_key;
public function __construct($license_key) {
$this->license_key = $license_key;
add_filter('pre_set_site_transient_update_plugins', [$this, 'check_update']);
add_filter('plugins_api', [$this, 'plugin_info'], 10, 3);
}
public function check_update($transient) {
if (empty($transient->checked)) {
return $transient;
}
$current_version = $transient->checked[$this->plugin_file] ?? '0.0.0';
$response = wp_remote_get(add_query_arg([
'slug' => $this->plugin_slug,
'license_key' => $this->license_key,
'version' => $current_version,
], $this->api_url . '/wp/update-check'));
if (is_wp_error($response)) {
return $transient;
}
$update = json_decode(wp_remote_retrieve_body($response));
if ($update && version_compare($update->version, $current_version, '>')) {
$transient->response[$this->plugin_file] = (object) [
'slug' => $this->plugin_slug,
'plugin' => $this->plugin_file,
'new_version' => $update->version,
'url' => $update->url ?? '',
'package' => $update->package ?? '',
'icons' => (array) ($update->icons ?? []),
'banners' => (array) ($update->banners ?? []),
'tested' => $update->tested ?? '',
'requires' => $update->requires ?? '',
'requires_php' => $update->requires_php ?? '',
];
}
return $transient;
}
public function plugin_info($result, $action, $args) {
if ($action !== 'plugin_information' || $args->slug !== $this->plugin_slug) {
return $result;
}
$response = wp_remote_get(add_query_arg([
'slug' => $this->plugin_slug,
'license_key' => $this->license_key,
'version' => '0.0.0',
], $this->api_url . '/wp/update-check'));
if (is_wp_error($response)) {
return $result;
}
return json_decode(wp_remote_retrieve_body($response));
}
}Initialization
In your main plugin file:
php
$license_key = get_option('my_plugin_license_key', '');
if ($license_key) {
new MyPlugin_Updater($license_key);
}Update Check Response
The /v1/wp/update-check endpoint returns WordPress-compatible update data including:
- Version info and download package URL
- Plugin icons and banners
- WordPress compatibility (
tested,requires,requires_php) - Changelog and description sections
The download URL is only included if the license key is valid.
