removing unneeded files from repo and plugin
All checks were successful
Create Release / build (push) Successful in 3s

This commit is contained in:
2025-09-10 06:02:50 -07:00
parent a160fe3964
commit cec5daa0b0
6 changed files with 343 additions and 47 deletions

View File

@@ -5,7 +5,21 @@
* Include this file in your WordPress plugin to enable automatic updates
* and license validation through the WP Digital Download licensing system.
*
* @version 1.0.0
* Usage example:
*
* // Initialize the updater
* if (!class_exists('WPDD_Plugin_Updater')) {
* require_once 'path/to/wpdd-plugin-updater.php';
* }
*
* $updater = new WPDD_Plugin_Updater(
* __FILE__, // Main plugin file path
* get_option('my_plugin_license_key', ''), // License key from options
* 'https://your-site.com', // Update server URL
* array('add_settings_page' => true) // Optional: Add license settings page
* );
*
* @version 1.1.0
* @author WP Digital Download
*/
@@ -33,9 +47,20 @@ class WPDD_Plugin_Updater {
* @param array $args Additional arguments
*/
public function __construct($plugin_file, $license_key, $update_server, $args = array()) {
// Validate required parameters
if (empty($plugin_file) || !file_exists($plugin_file)) {
error_log('WPDD Updater: Invalid plugin file path provided');
return;
}
if (empty($update_server) || !filter_var($update_server, FILTER_VALIDATE_URL)) {
error_log('WPDD Updater: Invalid update server URL provided');
return;
}
$this->plugin_file = $plugin_file;
$this->plugin_slug = basename($plugin_file, '.php');
$this->license_key = $license_key;
$this->license_key = trim($license_key);
$this->update_server = trailingslashit($update_server);
// Get plugin version from header
@@ -43,7 +68,7 @@ class WPDD_Plugin_Updater {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data($plugin_file);
$this->version = $plugin_data['Version'];
$this->version = $plugin_data['Version'] ?? '1.0.0';
$this->transient_key = 'wpdd_update_' . $this->plugin_slug;
@@ -90,15 +115,16 @@ class WPDD_Plugin_Updater {
$update_info = $this->request_update_info();
if ($update_info && isset($update_info['update_available']) && $update_info['update_available']) {
// API returns proper structure - use it directly
$plugin_data = array(
'slug' => $this->plugin_slug,
'plugin' => $this->plugin_file,
'new_version' => $update_info['version'],
'url' => $update_info['url'],
'package' => $update_info['package'],
'tested' => $update_info['tested'],
'requires' => $update_info['requires'],
'requires_php' => $update_info['requires_php'],
'slug' => $update_info['slug'] ?? $this->plugin_slug,
'plugin' => $update_info['plugin'] ?? $this->plugin_file,
'new_version' => $update_info['version'] ?? $update_info['new_version'],
'url' => $update_info['url'] ?? '',
'package' => $update_info['package'] ?? $update_info['download_url'],
'tested' => $update_info['tested'] ?? get_bloginfo('version'),
'requires' => $update_info['requires'] ?? '5.0',
'requires_php' => $update_info['requires_php'] ?? '7.0',
'compatibility' => new stdClass()
);
@@ -133,19 +159,25 @@ class WPDD_Plugin_Updater {
return $false;
}
// Extract product name from plugin file if available
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data($this->plugin_file);
return (object) array(
'slug' => $this->plugin_slug,
'name' => $update_info['name'] ?? $this->plugin_slug,
'version' => $update_info['version'] ?? $this->version,
'author' => $update_info['author'] ?? '',
'homepage' => $update_info['url'] ?? '',
'name' => $plugin_data['Name'] ?? $this->plugin_slug,
'version' => $update_info['version'] ?? $update_info['new_version'] ?? $this->version,
'author' => $plugin_data['Author'] ?? $update_info['author'] ?? '',
'homepage' => $plugin_data['PluginURI'] ?? $update_info['url'] ?? '',
'requires' => $update_info['requires'] ?? '5.0',
'tested' => $update_info['tested'] ?? get_bloginfo('version'),
'requires_php' => $update_info['requires_php'] ?? '7.0',
'download_link' => $update_info['package'] ?? '',
'download_link' => $update_info['package'] ?? $update_info['download_url'] ?? '',
'sections' => array(
'changelog' => $update_info['changelog'] ?? '',
'description' => $update_info['description'] ?? ''
'changelog' => $update_info['changelog'] ?? $update_info['release_notes'] ?? '',
'description' => $plugin_data['Description'] ?? $update_info['description'] ?? ''
),
'banners' => array(),
'icons' => array()
@@ -157,7 +189,17 @@ class WPDD_Plugin_Updater {
*/
public function maybe_download_package($reply, $package, $upgrader) {
// Check if this is our plugin's package
if (strpos($package, $this->update_server) === false || strpos($package, $this->plugin_slug) === false) {
// More flexible URL checking - handle different URL structures
$server_host = parse_url($this->update_server, PHP_URL_HOST);
$package_host = parse_url($package, PHP_URL_HOST);
if ($server_host !== $package_host && strpos($package, $this->plugin_slug) === false) {
return $reply;
}
// Also check if this is a WPDD download URL pattern
if (strpos($package, 'wp-json/wpdd/v1/download-update') === false &&
strpos($package, $this->update_server) === false) {
return $reply;
}
@@ -182,10 +224,15 @@ class WPDD_Plugin_Updater {
), $url);
$response = wp_remote_get($url, array(
'timeout' => 15,
'timeout' => 30,
'redirection' => 3,
'httpversion' => '1.1',
'user-agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url(),
'headers' => array(
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url()
)
'Accept' => 'application/json',
'Content-Type' => 'application/json'
),
'sslverify' => true
));
if (is_wp_error($response)) {
@@ -193,9 +240,25 @@ class WPDD_Plugin_Updater {
return false;
}
$http_code = wp_remote_retrieve_response_code($response);
if ($http_code !== 200) {
error_log('WPDD Updater: HTTP error ' . $http_code . ' when checking for updates');
return false;
}
$body = wp_remote_retrieve_body($response);
if (empty($body)) {
error_log('WPDD Updater: Empty response body when checking for updates');
return false;
}
$data = json_decode($body, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log('WPDD Updater: Invalid JSON response: ' . json_last_error_msg());
return false;
}
if (!$data || !isset($data['success'])) {
error_log('WPDD Updater: Invalid response from update server');
return false;
@@ -208,6 +271,7 @@ class WPDD_Plugin_Updater {
return false;
}
// Return the data array directly - API already provides proper structure
return $data;
}
@@ -222,15 +286,19 @@ class WPDD_Plugin_Updater {
$url = $this->update_server . 'wp-json/wpdd/v1/validate-license';
$response = wp_remote_post($url, array(
'timeout' => 15,
'timeout' => 30,
'redirection' => 3,
'httpversion' => '1.1',
'body' => array(
'license_key' => $this->license_key,
'product_slug' => $this->plugin_slug,
'site_url' => home_url()
),
'headers' => array(
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url()
)
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url(),
'Accept' => 'application/json'
),
'sslverify' => true
));
if (is_wp_error($response)) {
@@ -261,7 +329,9 @@ class WPDD_Plugin_Updater {
$url = $this->update_server . 'wp-json/wpdd/v1/activate-license';
$response = wp_remote_post($url, array(
'timeout' => 15,
'timeout' => 30,
'redirection' => 3,
'httpversion' => '1.1',
'body' => array(
'license_key' => $this->license_key,
'site_url' => home_url(),
@@ -270,8 +340,10 @@ class WPDD_Plugin_Updater {
'php_version' => PHP_VERSION
),
'headers' => array(
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url()
)
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url(),
'Accept' => 'application/json'
),
'sslverify' => true
));
if (is_wp_error($response)) {
@@ -308,14 +380,18 @@ class WPDD_Plugin_Updater {
$url = $this->update_server . 'wp-json/wpdd/v1/deactivate-license';
$response = wp_remote_post($url, array(
'timeout' => 15,
'timeout' => 30,
'redirection' => 3,
'httpversion' => '1.1',
'body' => array(
'license_key' => $this->license_key,
'site_url' => home_url()
),
'headers' => array(
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url()
)
'User-Agent' => 'WPDD-Updater/' . $this->version . '; ' . home_url(),
'Accept' => 'application/json'
),
'sslverify' => true
));
if (is_wp_error($response)) {