From 3cc982cd632a91e4de584dbb2832ba0199057f19 Mon Sep 17 00:00:00 2001 From: Jurriaan Koops Date: Mon, 14 Oct 2024 17:13:59 +0200 Subject: [PATCH 01/21] fix issue #9 --- src/LicenseHandler.php | 6 +++--- src/changelog.txt | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index a93f519..23bd73a 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -17,7 +17,7 @@ /** * Handles GWP Licenses. * - * @version 2.0.3 + * @version 2.0.5 */ class LicenseHandler { /** @@ -274,9 +274,9 @@ public function plugin_settings_license_fields() { 'error_message' => esc_html__( 'Invalid or expired license', 'gravitywp-license-handler' ), ); - $license_field['title'] = esc_html__( 'To unlock plugin updates and support, please enter your license key below', 'gravitywp-license-handler' ); $license_field['fields'] = array( $license_field ); - + $license_field['title'] = esc_html__( 'To unlock plugin updates and support, please enter your license key below', 'gravitywp-license-handler' ); + return $license_field; } diff --git a/src/changelog.txt b/src/changelog.txt index 48075db..20c85c2 100644 --- a/src/changelog.txt +++ b/src/changelog.txt @@ -1,3 +1,6 @@ += 2.0.5 = +- Fix non unique #id in plugin setting. + = 2.0.4 = - Optimizing the validation function caches the result. From 283bd70f22b143a123e8f4d65a1a9582faabff20 Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 29 Apr 2025 13:05:27 +0200 Subject: [PATCH 02/21] Implementing the global licensed key. --- src/LicenseHandler.php | 91 +++++++++++++----- src/changelog.txt | 3 + .../class-global-license-key-loader.php | 77 +++++++++++++++ .../class-global-license-key-registry.php | 93 +++++++++++++++++++ 4 files changed, 241 insertions(+), 23 deletions(-) create mode 100644 src/shared/class-global-license-key-loader.php create mode 100644 src/shared/class-global-license-key-registry.php diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 23bd73a..5ebd7dd 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -4,7 +4,6 @@ * * @package gravitywp-license-handler * @license MIT - * */ namespace GravityWP\LicenseHandler; @@ -53,7 +52,7 @@ class LicenseHandler { * * @var mixed|string */ - private $version = ''; + private $version = '2.0.6'; /** * WP Override flag @@ -175,37 +174,51 @@ class LicenseHandler { * @return void */ public function __construct( $gwp_addon_class, $plugin_file_path ) { + // Load the loader class (only once). + if ( ! class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { + require_once __DIR__ . '/shared/class-global-license-key-loader.php'; + } elseif ( $this->version ) { + // Register this plugin’s version. + \GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); + } + $doing_cron = defined( 'DOING_CRON' ) && DOING_CRON; if ( ! current_user_can( 'manage_options' ) && ! $doing_cron ) { return; } - $this->_addon_class = $gwp_addon_class; - $this->_addon_file_path = $plugin_file_path; - $this->_addon_slug = $gwp_addon_class::get_instance()->get_slug(); - $this->_addon_license = $gwp_addon_class::get_instance()->get_plugin_setting( $this->_addon_slug . '_license_key' ); - $this->_addon_title = $gwp_addon_class::get_instance()->plugin_page_title(); + $this->_addon_class = $gwp_addon_class; + $this->_addon_file_path = $plugin_file_path; + $this->_addon_slug = $gwp_addon_class::get_instance()->get_slug(); + $this->_addon_license = $gwp_addon_class::get_instance()->get_plugin_setting( $this->_addon_slug . '_license_key' ); + $this->_addon_title = $gwp_addon_class::get_instance()->plugin_page_title(); + $this->_global_license_key = get_option( 'gravitywp_global_license_key', '' ); $this->initialize_paddlepress_client(); } /** * Initialize or reinitialize the Paddlepress client. * - * @return bool + * @param string|null $field_setting Optional license key override from a field or custom setting. + * @return bool True if initialization succeeded, false otherwise. */ public function initialize_paddlepress_client( $field_setting = null ) { try { unset( $this->_paddlepress_client ); unset( $this->_license_handler ); - $license_key = ! empty( $field_setting ) ? $field_setting : $this->_addon_license; + $license_key = ! empty( $field_setting ) ? $field_setting : $this->_addon_license; + + if ( empty( $license_key ) ) { + $license_key = $this->_global_license_key; + } $this->_license_handler = new Plugin_Updater( $this->_addon_file_path, array( - 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. - 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error' - 'license_url' => home_url(), // license domain. - 'download_tag' => $this->_addon_slug, // download tag slug. - 'beta' => false, + 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. + 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error'. + 'license_url' => home_url(), // license domain. + 'download_tag' => $this->_addon_slug, // download tag slug. + 'beta' => false, 'handler_class' => $this, ) ); @@ -216,7 +229,6 @@ public function initialize_paddlepress_client( $field_setting = null ) { } else { add_action( 'admin_notices', array( $this, 'action_admin_notices' ) ); } - } catch ( \Exception $e ) { $this->_addon_class::get_instance()->log_error( __CLASS__ . '::' . __METHOD__ . '(): License client failed to initialize: ' . $e->getMessage() ); return false; @@ -250,6 +262,13 @@ public function action_admin_notices() { GFCommon::add_dismissible_message( $message, $key, 'warning', false, true ); } + /** + * Define plugin settings fields. + * + * @since 1.0 + * + * @return array + */ /** * Define plugin settings fields. * @@ -258,25 +277,51 @@ public function action_admin_notices() { * @return array */ public function plugin_settings_license_fields() { - $this->_addon_license = $this->_addon_class::get_instance()->get_plugin_setting( $this->_addon_slug . '_license_key' ); + $this->_addon_license = $this->_addon_class::get_instance()->get_plugin_setting( + $this->_addon_slug . '_license_key' + ); + $license_key_name = $this->_addon_slug . '_license_key'; + + // Main license input field. $license_field = array( - 'name' => $this->_addon_slug . '_license_key', - 'tooltip' => esc_html__( 'Enter the license key you received after purchasing the plugin.', 'gravitywp-license-handler' ), + 'name' => $license_key_name, 'label' => esc_html__( 'License Key', 'gravitywp-license-handler' ), + 'tooltip' => esc_html__( 'Enter the license key you received after purchasing the plugin.', 'gravitywp-license-handler' ), 'type' => 'text', 'input_type' => 'password', 'class' => 'medium', 'default_value' => '', - 'required' => true, + 'required' => false, 'validation_callback' => array( $this, 'license_validation' ), 'feedback_callback' => array( $this, 'license_feedback' ), - 'error_message' => esc_html__( 'Invalid or expired license', 'gravitywp-license-handler' ), + 'error_message' => esc_html__( 'Invalid or expired license.', 'gravitywp-license-handler' ), + 'title' => esc_html__( 'To unlock plugin updates and support, please enter your license key below.', 'gravitywp-license-handler' ), + ); + + // Determine current license state. + $plugin_license_key = $this->_addon_license ?? ''; + $global_license_key = $this->_global_license_key ?? ''; + + // Add contextual note based on key presence. + $license_field['fields'][] = array( + 'name' => 'license_note', + 'type' => 'html', + 'html' => function () use ( $plugin_license_key, $global_license_key ) { + if ( ! empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { + $message = esc_html__( 'The plugin license key will override the global license key. To use the global key, leave this field empty.', 'gravitywp-license-handler' ); + } elseif ( empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { + $message = esc_html__( 'Using the global license key.', 'gravitywp-license-handler' ); + } else { + $message = esc_html__( 'No license key provided.', 'gravitywp-license-handler' ); + } + return '' . $message . ''; + }, ); - $license_field['fields'] = array( $license_field ); - $license_field['title'] = esc_html__( 'To unlock plugin updates and support, please enter your license key below', 'gravitywp-license-handler' ); - + // Nest the main license field inside the parent group. + $license_field['fields'][] = $license_field; + return $license_field; } diff --git a/src/changelog.txt b/src/changelog.txt index 20c85c2..5723a4c 100644 --- a/src/changelog.txt +++ b/src/changelog.txt @@ -1,3 +1,6 @@ += 2.0.6 = +- Implementing the global licensed key. + = 2.0.5 = - Fix non unique #id in plugin setting. diff --git a/src/shared/class-global-license-key-loader.php b/src/shared/class-global-license-key-loader.php new file mode 100644 index 0000000..bcbcc69 --- /dev/null +++ b/src/shared/class-global-license-key-loader.php @@ -0,0 +1,77 @@ + $version, + 'file' => $file_path, + ); + } + /** + * Loads the last (highest) version from the registered candidates. + * + * @return void + */ + public static function load_last_version() { + if ( empty( self::$candidates ) ) { + return; + } + + /* + * Sort candidates in descending order by version number. + */ + usort( + self::$candidates, + function ( $a, $b ) { + return version_compare( $b['version'], $a['version'] ); + } + ); + + $last = self::$candidates[0]; + require_once $last['file']; + + if ( class_exists( '\GravityWP\Shared\Global_License_Key_Registry' ) ) { + \GravityWP\Shared\Global_License_Key_Registry::init( $last['version'] ); // Load the UI and logic. + } + } + } + + + add_action( 'init', array( '\GravityWP\Shared\GlobalLicenseKeyLoader', 'load_last_version' ), 999 ); +} diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php new file mode 100644 index 0000000..c02b453 --- /dev/null +++ b/src/shared/class-global-license-key-registry.php @@ -0,0 +1,93 @@ + +
+

+
+ + + + + + +
+ +
+ +
+
+ Date: Tue, 29 Apr 2025 13:15:41 +0200 Subject: [PATCH 03/21] fix Global_License_Key_Loader --- src/shared/class-global-license-key-loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/class-global-license-key-loader.php b/src/shared/class-global-license-key-loader.php index bcbcc69..a547044 100644 --- a/src/shared/class-global-license-key-loader.php +++ b/src/shared/class-global-license-key-loader.php @@ -11,12 +11,12 @@ namespace GravityWP\Shared; /* - * Check if the GlobalLicenseKeyLoader class has already been defined. + * Check if the Global_License_Key_Loader class has already been defined. * If not, define it to avoid redeclaration issues. */ -if ( ! class_exists( '\GravityWP\Shared\GlobalLicenseKeyLoader' ) ) { +if ( ! class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { /** - * Class GlobalLicenseKeyLoader + * Class Global_License_Key_Loader * * Responsible for registering and loading the last version of a shared component. */ @@ -73,5 +73,5 @@ function ( $a, $b ) { } - add_action( 'init', array( '\GravityWP\Shared\GlobalLicenseKeyLoader', 'load_last_version' ), 999 ); + add_action( 'init', array( '\GravityWP\Shared\Global_License_Key_Loader', 'load_last_version' ), 999 ); } From 087bc72749477a7a6ba16d12d78df90b182d8476 Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 29 Apr 2025 13:19:39 +0200 Subject: [PATCH 04/21] fix missed echo --- src/shared/class-global-license-key-registry.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index c02b453..d2b09f3 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -74,12 +74,12 @@ public static function render_settings_page() { $global_key = get_option( 'gravitywp_global_license_key', '' ); ?>
-

+

- + From 3b16fce8628b28b17e477d9f873de039d0847a55 Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 29 Apr 2025 13:23:29 +0200 Subject: [PATCH 05/21] fix display $version --- src/shared/class-global-license-key-registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index d2b09f3..4c5e6a8 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -74,7 +74,7 @@ public static function render_settings_page() { $global_key = get_option( 'gravitywp_global_license_key', '' ); ?>
-

+

()

From 2d912f96451985348a1ccd5c97588c18acf41ebb Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 29 Apr 2025 13:28:26 +0200 Subject: [PATCH 06/21] fix display $version part 2 --- src/shared/class-global-license-key-registry.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 4c5e6a8..7d2e185 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -18,6 +18,14 @@ * used across GravityWP plugins and extensions. */ class Global_License_Key_Registry { + + /** + * Used version of plugin. + * + * @var mixed|string + */ + private static $version; + /** * Initializes the GravityWP settings page functionality. * @@ -25,9 +33,11 @@ class Global_License_Key_Registry { * - Add the settings page to the admin menu. * - Register the plugin settings. * + * @param string $version The current License handler version to assign to the settings loader. * @return void */ - public static function init() { + public static function init( $version ) { + self::$version = $version; add_action( 'admin_menu', array( self::class, 'add_admin_menu' ) ); add_action( 'admin_init', array( self::class, 'register_settings' ) ); } From 43bdd18788829b0d7e377422ccc96887c3555ac4 Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Tue, 29 Apr 2025 15:37:55 +0200 Subject: [PATCH 07/21] - changed messages - show correct message after saving plugin license key - fixed message being visible twice --- src/LicenseHandler.php | 72 +++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 5ebd7dd..885b1af 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -128,13 +128,13 @@ class LicenseHandler { private $_addon_license = ''; /** - * Store the GravityWP GF Addon license hash. + * Store the GravityWP Global License Key. * * @since 1.0 * @access private - * @var string $_addon_license_hash the GravityWP GF Addon license hash. + * @var string $_global_license_key Global License Key. */ - private $_addon_license_hash = ''; + private $_global_license_key = ''; /** * Store the GravityWP GF Addon title @@ -175,11 +175,11 @@ class LicenseHandler { */ public function __construct( $gwp_addon_class, $plugin_file_path ) { // Load the loader class (only once). - if ( ! class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { + if ( ! class_exists( '\GravityWP\GravityWP_List_Datepicker\GravityWP\Shared\Global_License_Key_Loader' ) ) { require_once __DIR__ . '/shared/class-global-license-key-loader.php'; } elseif ( $this->version ) { // Register this plugin’s version. - \GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); + \GravityWP\GravityWP_List_Datepicker\GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); } $doing_cron = defined( 'DOING_CRON' ) && DOING_CRON; @@ -262,13 +262,6 @@ public function action_admin_notices() { GFCommon::add_dismissible_message( $message, $key, 'warning', false, true ); } - /** - * Define plugin settings fields. - * - * @since 1.0 - * - * @return array - */ /** * Define plugin settings fields. * @@ -285,22 +278,32 @@ public function plugin_settings_license_fields() { // Main license input field. $license_field = array( - 'name' => $license_key_name, - 'label' => esc_html__( 'License Key', 'gravitywp-license-handler' ), - 'tooltip' => esc_html__( 'Enter the license key you received after purchasing the plugin.', 'gravitywp-license-handler' ), - 'type' => 'text', - 'input_type' => 'password', - 'class' => 'medium', - 'default_value' => '', - 'required' => false, - 'validation_callback' => array( $this, 'license_validation' ), - 'feedback_callback' => array( $this, 'license_feedback' ), - 'error_message' => esc_html__( 'Invalid or expired license.', 'gravitywp-license-handler' ), - 'title' => esc_html__( 'To unlock plugin updates and support, please enter your license key below.', 'gravitywp-license-handler' ), + 'title' => esc_html__( 'To unlock plugin updates and support, please enter your license key below.', 'gravitywp-license-handler' ), + 'fields' => array( + array( + 'name' => $license_key_name, + 'label' => esc_html__( 'Plugin License Key', 'gravitywp-license-handler' ), + 'tooltip' => esc_html__( 'Enter the license key you received after purchasing the plugin.', 'gravitywp-license-handler' ), + 'type' => 'text', + 'input_type' => 'password', + 'class' => 'medium', + 'default_value' => '', + 'required' => false, + 'validation_callback' => array( $this, 'license_validation' ), + 'feedback_callback' => array( $this, 'license_feedback' ), + 'error_message' => esc_html__( 'Invalid or expired license.', 'gravitywp-license-handler' ), + ), + ), ); // Determine current license state. - $plugin_license_key = $this->_addon_license ?? ''; + if ( isset( $_POST[ '_gform_setting_' . $this->_addon_slug . '_license_key' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing + // If the form is submitted, use the posted value. + $plugin_license_key = rgpost( '_gform_setting_' . $this->_addon_slug . '_license_key' ); + } else { + // Otherwise, use the stored value. + $plugin_license_key = $this->_addon_license ?? ''; + } $global_license_key = $this->_global_license_key ?? ''; // Add contextual note based on key presence. @@ -308,20 +311,25 @@ public function plugin_settings_license_fields() { 'name' => 'license_note', 'type' => 'html', 'html' => function () use ( $plugin_license_key, $global_license_key ) { + $global_settings_url = admin_url( 'admin.php?page=gravitywp-settings' ); + $global_settings_text = esc_html__( 'Global License Key', 'gravitywp-license-handler' ); + $message_color = 'inherit'; if ( ! empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { - $message = esc_html__( 'The plugin license key will override the global license key. To use the global key, leave this field empty.', 'gravitywp-license-handler' ); + /* translators: %s: link to global settings */ + $message = sprintf( esc_html__( 'This Plugin License Key overrides the %s. To use the global key, leave this field empty.', 'gravitywp-license-handler') , '' . esc_html( $global_settings_text ) . '' ); } elseif ( empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { - $message = esc_html__( 'Using the global license key.', 'gravitywp-license-handler' ); + /* translators: %s: link to global settings */ + $message = sprintf( esc_html__( 'A %s is active. If needed you can override the Global Key with the Plugin Key.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); + $message_color = 'green'; } else { - $message = esc_html__( 'No license key provided.', 'gravitywp-license-handler' ); + $message_color = 'red'; + /* translators: %s: link to global settings */ + $message = sprintf( esc_html__( 'No active license. If you have an All Access License you can set up a %s.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); } - return '' . $message . ''; + return '' . $message . ''; }, ); - // Nest the main license field inside the parent group. - $license_field['fields'][] = $license_field; - return $license_field; } From 89b618528f33f8cc38f050d6694f43c5f65b7f7d Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Wed, 30 Apr 2025 15:24:52 +0200 Subject: [PATCH 08/21] Added more informative messages --- src/pluginUpdater.php | 63 +++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/src/pluginUpdater.php b/src/pluginUpdater.php index f3967a3..0144fe8 100644 --- a/src/pluginUpdater.php +++ b/src/pluginUpdater.php @@ -224,7 +224,36 @@ public function request_is_activate( $field_setting ) { $this->error_messages = nl2br( $this->generateErrorMessage( $json_data['message'] ) ); return false; } else { - $this->error_messages = nl2br( $this->generateErrorMessage( 'Please try again later. If the issue persists, please contact support.' ) ); + // Retrieve HTTP status code and headers for additional context. + $http_code = wp_remote_retrieve_response_code( $response ); + $headers = wp_remote_retrieve_headers( $response ); + + // check for block by Cloudflare. + if ( $http_code === 403 && strpos( strtolower( $body ), 'cloudflare' ) !== false ) { + $this->error_messages = nl2br( + $this->generateErrorMessage( + 'Access to the license server was denied by Cloudflare. This happens when malicious activity was detected from your website\'s outgoing IP address. This often happens on shared hosting where other users use the same IP address for malicious activity. Contact your hosting provider to resolve this issue.' + ) + ); + return false; + } + + // Format additional information into a string for logging or support use. + $extra_info = sprintf( + "HTTP Status Code: %d\nResponse Headers: %s", + $http_code, + json_encode( $headers ) + ); + + // Provide a detailed error message including the response code and extra info. + $this->error_messages = nl2br( + $this->generateErrorMessage( + sprintf( + 'An unexpected error occurred. Please try again later. If the issue persists, provide the following information to support: %s', + esc_html( $extra_info ) // Ensure special characters in the info are safely included in a HTML context. + ) + ) + ); return false; } } @@ -260,7 +289,7 @@ public function generateErrorMessage( $error ) { } } else { $sanitized_message = sanitize_text_field( $messages ); - $error_message .= "- $sanitized_message\n"; + $error_message .= "- $sanitized_message\n"; } } } else { @@ -325,13 +354,13 @@ public function gwp_is_valid( $cached, $key = null ) { /** * Checks the plugin's license status and updates the transient data accordingly. * - * This method verifies the validity of the plugin's license key and updates the cached - * license status. It also manages admin notices based on the validation result. If the - * license key is valid, it removes any existing admin notices. Otherwise, it adds an + * This method verifies the validity of the plugin's license key and updates the cached + * license status. It also manages admin notices based on the validation result. If the + * license key is valid, it removes any existing admin notices. Otherwise, it adds an * admin notice to inform the user about the invalid license status. * * Key Details: - * - Verifies if the current context is not the plugins page in a multisite network, + * - Verifies if the current context is not the plugins page in a multisite network, * and returns early if true. * - Checks existing transient data for license status response, and skips further checks * if the data is already populated unless overridden. @@ -351,37 +380,37 @@ public function gwp_is_valid( $cached, $key = null ) { * @uses set_version_info_cache() Caches the result of the license key validation. * @uses gwp_is_valid() Validates the license key using cached data or via API. */ - public function check_update_license($_transient_data) { + public function check_update_license( $_transient_data ) { global $pagenow; // Ensure $_transient_data is an object. - if (!is_object($_transient_data)) { + if ( ! is_object( $_transient_data ) ) { $_transient_data = new stdClass(); } // Return early if on the plugins page in a multisite network. - if ('plugins.php' === $pagenow && is_multisite()) { + if ( 'plugins.php' === $pagenow && is_multisite() ) { return $_transient_data; } // Check if the transient data already has a response and is not being overridden. - if (!empty($_transient_data->response) && !empty($_transient_data->response[$this->name]) && false === $this->wp_override) { + if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) { return $_transient_data; } // Retrieve license key and generate a unique cache key. $license_key = $this->api_data['license_key']; - $status_cache_key = 'paddlepress_status_request_' . md5(serialize($this->slug . $this->api_data['license_key'] . $this->beta)); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize + $status_cache_key = 'paddlepress_status_request_' . md5( serialize( $this->slug . $this->api_data['license_key'] . $this->beta ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize // Validate the license key through the API and update the cache. - $status = $this->request_is_activate($license_key); - $this->set_version_info_cache($status, $status_cache_key); + $status = $this->request_is_activate( $license_key ); + $this->set_version_info_cache( $status, $status_cache_key ); // Validate the license key and manage admin notices based on validity. - if ($this->gwp_is_valid(false, $license_key)) { - remove_action('admin_notices', array($this->handler_class, 'action_admin_notices')); + if ( $this->gwp_is_valid( false, $license_key ) ) { + remove_action( 'admin_notices', array( $this->handler_class, 'action_admin_notices' ) ); } else { - add_action('admin_notices', array($this->handler_class, 'action_admin_notices')); + add_action( 'admin_notices', array( $this->handler_class, 'action_admin_notices' ) ); } return $_transient_data; @@ -522,7 +551,7 @@ public function show_update_notification( $file, $plugin ) { if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { - $version_info = $this->get_cached_version_info(); // || false; + $version_info = $this->get_cached_version_info(); // || false; if ( false === $version_info ) { $version_info = $this->api_request( From b5b40098db4d9919670b07ae17ae3a20f7019f4c Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Wed, 30 Apr 2025 15:34:10 +0200 Subject: [PATCH 09/21] added url --- src/pluginUpdater.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pluginUpdater.php b/src/pluginUpdater.php index 0144fe8..1d69f4c 100644 --- a/src/pluginUpdater.php +++ b/src/pluginUpdater.php @@ -228,11 +228,11 @@ public function request_is_activate( $field_setting ) { $http_code = wp_remote_retrieve_response_code( $response ); $headers = wp_remote_retrieve_headers( $response ); - // check for block by Cloudflare. + // Check for block by Cloudflare. if ( $http_code === 403 && strpos( strtolower( $body ), 'cloudflare' ) !== false ) { $this->error_messages = nl2br( $this->generateErrorMessage( - 'Access to the license server was denied by Cloudflare. This happens when malicious activity was detected from your website\'s outgoing IP address. This often happens on shared hosting where other users use the same IP address for malicious activity. Contact your hosting provider to resolve this issue.' + 'Access to the license server was denied by Cloudflare. This happens when malicious activity was detected from your website\'s outgoing IP address. This often happens on shared hosting where other users use the same IP address for malicious activity. Contact your hosting provider to resolve this issue. For more information, visit this page.' ) ); return false; @@ -245,12 +245,12 @@ public function request_is_activate( $field_setting ) { json_encode( $headers ) ); - // Provide a detailed error message including the response code and extra info. + // Provide a detailed error message including the response code, extra info, and a reference URL. $this->error_messages = nl2br( $this->generateErrorMessage( sprintf( - 'An unexpected error occurred. Please try again later. If the issue persists, provide the following information to support: %s', - esc_html( $extra_info ) // Ensure special characters in the info are safely included in a HTML context. + 'An unexpected error occurred. Please try again later. You can also refer to this page for more details. If the issue persists, provide the following information to support: %s.', + esc_html( $extra_info ) // Ensure special characters in the info are safely included in an HTML context. ) ) ); From a429a06ffd002613e11f0f508297e2e52ac14494 Mon Sep 17 00:00:00 2001 From: Karim Date: Wed, 30 Apr 2025 16:40:34 +0200 Subject: [PATCH 10/21] improving the licence handler and more error messages --- .../class-global-license-key-registry.php | 119 +++++++++++++++++- 1 file changed, 116 insertions(+), 3 deletions(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 7d2e185..c7e3530 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -81,15 +81,79 @@ public static function register_settings() { * @return void */ public static function render_settings_page() { - $global_key = get_option( 'gravitywp_global_license_key', '' ); + $global_key = get_option( 'gravitywp_global_license_key', '' ); + $data = null; + $error_message = ''; + $error_details = ''; + wp_enqueue_style( 'dashicons' ); + + if ( ! empty( $global_key ) ) { + $api_url = add_query_arg( + array( + 'license_key' => $global_key, + 'license_url' => home_url(), + 'action' => 'activate', + ), + 'https://my.gravitywp.com/wp-json/paddlepress-api/v1/license' + ); + + $response = wp_remote_get( esc_url_raw( $api_url ), array( 'timeout' => 15 ) ); + + if ( is_wp_error( $response ) ) { + $error_message = 'Network Error: ' . $response->get_error_message(); + } else { + $code = wp_remote_retrieve_response_code( $response ); + $body = wp_remote_retrieve_body( $response ); + $headers = wp_remote_retrieve_headers( $response ); + + // Check for block by Cloudflare. + if ( $code === 403 && strpos( strtolower( $body ), 'cloudflare' ) !== false ) { + $error_message = nl2br( 'Access to the license server was denied by Cloudflare. This happens when malicious activity was detected from your website\'s outgoing IP address. This often happens on shared hosting where other users use the same IP address for malicious activity. Contact your hosting provider to resolve this issue.' ); + } else { + switch ( $code ) { + case 200: + $decoded = json_decode( $body, true ); + if ( is_array( $decoded ) && ! empty( $decoded['success'] ) && $decoded['license_status'] === 'valid' ) { + $data = $decoded; + } else { + $error_message = 'Invalid license.'; + self::extract_error_details( $decoded, $error_details ); + } + break; + case 500: + $error_message = 'Server Error: The server encountered an internal error. Please try again later.'; + break; + default: + // Format additional information into a string for logging or support use. + $extra_info = sprintf( + "HTTP Status Code: %d\nResponse Headers: %s", + $code, + json_encode( $headers ) + ); + $error_message = nl2br( sprintf( 'An unexpected error occurred. Please try again later. If the issue persists, provide the following information to support: %s', esc_html( $extra_info ) ) ); + self::extract_error_details( json_decode( $body, true ), $error_details ); + break; + } + } + } + } ?>
-

()

+

+ + + () + +

- + @@ -97,7 +161,56 @@ public static function render_settings_page() {
+ +
+ + +
+

+ + +

+
    +
  • :
  • +
  • :
  • +
  • :
  • +
  • :
  • +
  • :
  • +
+
+ +
+

+ + +

+ +
+ +
+
$messages ) { + foreach ( (array) $messages as $msg ) { + $details[] = esc_html( $msg ); + } + } + $error_details = implode( '
', $details ); + } + } } From 9acbfb80cea2b20fb4875f0102fc15f97ee697b3 Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Thu, 1 May 2025 17:13:16 +0200 Subject: [PATCH 11/21] remove class prefix --- src/LicenseHandler.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 885b1af..12119da 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -175,11 +175,13 @@ class LicenseHandler { */ public function __construct( $gwp_addon_class, $plugin_file_path ) { // Load the loader class (only once). - if ( ! class_exists( '\GravityWP\GravityWP_List_Datepicker\GravityWP\Shared\Global_License_Key_Loader' ) ) { + if ( ! class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { require_once __DIR__ . '/shared/class-global-license-key-loader.php'; - } elseif ( $this->version ) { + } + + if ( $this->version ) { // Register this plugin’s version. - \GravityWP\GravityWP_List_Datepicker\GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); + \GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); } $doing_cron = defined( 'DOING_CRON' ) && DOING_CRON; @@ -316,7 +318,7 @@ public function plugin_settings_license_fields() { $message_color = 'inherit'; if ( ! empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { /* translators: %s: link to global settings */ - $message = sprintf( esc_html__( 'This Plugin License Key overrides the %s. To use the global key, leave this field empty.', 'gravitywp-license-handler') , '' . esc_html( $global_settings_text ) . '' ); + $message = sprintf( esc_html__( 'This Plugin License Key overrides the %s. To use the global key, leave this field empty.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); } elseif ( empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { /* translators: %s: link to global settings */ $message = sprintf( esc_html__( 'A %s is active. If needed you can override the Global Key with the Plugin Key.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); From 0d72547832cd52040530861577d2c194be0de8c5 Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Thu, 1 May 2025 17:13:58 +0200 Subject: [PATCH 12/21] remove existing dismissible message after saving the global key --- src/shared/class-global-license-key-loader.php | 17 +++++++++++++---- .../class-global-license-key-registry.php | 11 ++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/shared/class-global-license-key-loader.php b/src/shared/class-global-license-key-loader.php index a547044..0e35c8d 100644 --- a/src/shared/class-global-license-key-loader.php +++ b/src/shared/class-global-license-key-loader.php @@ -34,13 +34,15 @@ class Global_License_Key_Loader { * * @param string $version The version number of the candidate. * @param string $file_path The absolute path to the candidate file. + * @param string $gwp_addon_class The GF Addon class name. * * @return void */ - public static function register( $version, $file_path ) { + public static function register( $version, $file_path, $gwp_addon_class = '' ) { self::$candidates[] = array( - 'version' => $version, - 'file' => $file_path, + 'version' => $version, + 'file' => $file_path, + 'addon_class' => $gwp_addon_class, ); } /** @@ -70,8 +72,15 @@ function ( $a, $b ) { \GravityWP\Shared\Global_License_Key_Registry::init( $last['version'] ); // Load the UI and logic. } } + /** + * Returns the candidates array. + * + * @return array + */ + public static function get_registered_license_handlers() { + return self::$candidates; + } } - add_action( 'init', array( '\GravityWP\Shared\Global_License_Key_Loader', 'load_last_version' ), 999 ); } diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index c7e3530..9045dbc 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -115,6 +115,15 @@ public static function render_settings_page() { $decoded = json_decode( $body, true ); if ( is_array( $decoded ) && ! empty( $decoded['success'] ) && $decoded['license_status'] === 'valid' ) { $data = $decoded; + if ( class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { + $gwp_addons = \GravityWP\Shared\Global_License_Key_Loader::get_registered_license_handlers(); + foreach ( $gwp_addons as $gwp_addon ) { + if ( class_exists( $gwp_addon['gwp_addon_class'] ) ) { + $gwp_addon_slug = $gwp_addon['gwp_addon_class']::get_instance()->get_slug(); + \GFCommon::remove_dismissible_message( $gwp_addon_slug . '_license_message_notice' ); + } + } + } } else { $error_message = 'Invalid license.'; self::extract_error_details( $decoded, $error_details ); @@ -128,7 +137,7 @@ public static function render_settings_page() { $extra_info = sprintf( "HTTP Status Code: %d\nResponse Headers: %s", $code, - json_encode( $headers ) + wp_json_encode( $headers ) ); $error_message = nl2br( sprintf( 'An unexpected error occurred. Please try again later. If the issue persists, provide the following information to support: %s', esc_html( $extra_info ) ) ); self::extract_error_details( json_decode( $body, true ), $error_details ); From 78c25a062ece6ad18bd31f3c83902c495e183095 Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Thu, 1 May 2025 17:24:30 +0200 Subject: [PATCH 13/21] fix classname not being passed --- src/LicenseHandler.php | 2 +- src/shared/class-global-license-key-registry.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 12119da..158ad36 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -181,7 +181,7 @@ public function __construct( $gwp_addon_class, $plugin_file_path ) { if ( $this->version ) { // Register this plugin’s version. - \GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php' ); + \GravityWP\Shared\Global_License_Key_Loader::register( $this->version, __DIR__ . '/shared/class-global-license-key-registry.php', $gwp_addon_class ); } $doing_cron = defined( 'DOING_CRON' ) && DOING_CRON; diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 9045dbc..424c7a8 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -118,8 +118,9 @@ public static function render_settings_page() { if ( class_exists( '\GravityWP\Shared\Global_License_Key_Loader' ) ) { $gwp_addons = \GravityWP\Shared\Global_License_Key_Loader::get_registered_license_handlers(); foreach ( $gwp_addons as $gwp_addon ) { - if ( class_exists( $gwp_addon['gwp_addon_class'] ) ) { - $gwp_addon_slug = $gwp_addon['gwp_addon_class']::get_instance()->get_slug(); + $gwp_addon_class = $gwp_addon['addon_class'] ?? ''; + if ( $gwp_addon_class && class_exists( $gwp_addon_class ) ) { + $gwp_addon_slug = $gwp_addon_class::get_instance()->get_slug(); \GFCommon::remove_dismissible_message( $gwp_addon_slug . '_license_message_notice' ); } } From a7ffa1a0974503e3c376280c8796515e0e8a00e7 Mon Sep 17 00:00:00 2001 From: JurriaanK Date: Fri, 2 May 2025 11:11:00 +0200 Subject: [PATCH 14/21] implement message when global license is not valid for all plugins --- src/LicenseHandler.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 158ad36..1d760c4 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -321,8 +321,15 @@ public function plugin_settings_license_fields() { $message = sprintf( esc_html__( 'This Plugin License Key overrides the %s. To use the global key, leave this field empty.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); } elseif ( empty( $plugin_license_key ) && ! empty( $global_license_key ) ) { /* translators: %s: link to global settings */ - $message = sprintf( esc_html__( 'A %s is active. If needed you can override the Global Key with the Plugin Key.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); - $message_color = 'green'; + if ( $this->_license_handler->gwp_is_valid( true, $global_license_key ) ) { + /* translators: %s: link to global settings */ + $message = sprintf( esc_html__( 'A %s is active. If needed you can override the Global Key with the Plugin Key.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '' ); + $message_color = 'green'; + } else { + /* translators: %s: link to global settings, link to gravitywp.com */ + $message = sprintf( esc_html__( 'A %1$s is active, but it is not valid for this addon. You can override the Global Key with a specific Plugin Key or purchase an All Access license on %2$s.', 'gravitywp-license-handler' ), '' . esc_html( $global_settings_text ) . '', 'gravitywp.com' ); + $message_color = 'red'; + } } else { $message_color = 'red'; /* translators: %s: link to global settings */ From cb746f1295abcf9f33d13e39661b232f0f0833b0 Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 8 Jul 2025 13:03:36 +0200 Subject: [PATCH 15/21] fix uses capability --- src/LicenseHandler.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index a93f519..c96663f 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -4,7 +4,6 @@ * * @package gravitywp-license-handler * @license MIT - * */ namespace GravityWP\LicenseHandler; @@ -20,6 +19,7 @@ * @version 2.0.3 */ class LicenseHandler { + /** * Update endpoint of the API * @@ -167,16 +167,16 @@ class LicenseHandler { /** * Constructor. * - * @since 1.0 + * @since 1.0 * - * @param string $gwp_addon_class GravityWP GF Addon classname. + * @param string $gwp_addon_class GravityWP GF Addon classname. * @param string $plugin_file_path Path to main plugin file. * * @return void */ public function __construct( $gwp_addon_class, $plugin_file_path ) { $doing_cron = defined( 'DOING_CRON' ) && DOING_CRON; - if ( ! current_user_can( 'manage_options' ) && ! $doing_cron ) { + if ( ! ( current_user_can( 'gform_full_access' ) || current_user_can( 'gravityforms_edit_settings' ) || current_user_can( 'gravityforms_view_settings' ) ) && ! $doing_cron ) { return; } $this->_addon_class = $gwp_addon_class; @@ -196,27 +196,26 @@ public function initialize_paddlepress_client( $field_setting = null ) { try { unset( $this->_paddlepress_client ); unset( $this->_license_handler ); - $license_key = ! empty( $field_setting ) ? $field_setting : $this->_addon_license; + $license_key = ! empty( $field_setting ) ? $field_setting : $this->_addon_license; $this->_license_handler = new Plugin_Updater( $this->_addon_file_path, array( - 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. - 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error' - 'license_url' => home_url(), // license domain. - 'download_tag' => $this->_addon_slug, // download tag slug. - 'beta' => false, + 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. + 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error' + 'license_url' => home_url(), // license domain. + 'download_tag' => $this->_addon_slug, // download tag slug. + 'beta' => false, 'handler_class' => $this, ) ); $use_cached_info = ! empty( $field_setting ) ? false : true; if ( $this->_license_handler->gwp_is_valid( $use_cached_info, $license_key ) ) { - remove_action( 'admin_notices', array( $this, 'action_admin_notices' ) ); + remove_action( 'admin_notices', array( $this, 'action_admin_notices' ) ); } else { add_action( 'admin_notices', array( $this, 'action_admin_notices' ) ); } - } catch ( \Exception $e ) { $this->_addon_class::get_instance()->log_error( __CLASS__ . '::' . __METHOD__ . '(): License client failed to initialize: ' . $e->getMessage() ); return false; @@ -228,7 +227,7 @@ public function initialize_paddlepress_client( $field_setting = null ) { /** * Display an admin notice. * - * @since 1.0 + * @since 1.0 * * @return void */ @@ -253,7 +252,7 @@ public function action_admin_notices() { /** * Define plugin settings fields. * - * @since 1.0 + * @since 1.0 * * @return array */ @@ -283,9 +282,9 @@ public function plugin_settings_license_fields() { /** * Handle license key activation or deactivation and on save the settings. * - * @since 1.0 + * @since 1.0 * - * @param array $field The field properties. + * @param array $field The field properties. * @param string $field_setting The submitted value of the license_key field. */ public function license_validation( $field, $field_setting ) { @@ -310,7 +309,7 @@ public function license_validation( $field, $field_setting ) { * @param string $value The current value of the license_key field. * @param array $field The field properties. * - * @since 1.0 + * @since 1.0 * * @return bool|null */ From 942cb996ffa87463e231febda4620a2db000adee Mon Sep 17 00:00:00 2001 From: Karim Date: Tue, 8 Jul 2025 13:19:18 +0200 Subject: [PATCH 16/21] fixs and merge --- src/LicenseHandler.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 9aa8c82..8aa6241 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -217,15 +217,10 @@ public function initialize_paddlepress_client( $field_setting = null ) { $this->_license_handler = new Plugin_Updater( $this->_addon_file_path, array( - 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. - 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error'. - 'license_url' => home_url(), // license domain. - 'download_tag' => $this->_addon_slug, // download tag slug. - 'beta' => false, - 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. - 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error' - 'license_url' => home_url(), // license domain. - 'download_tag' => $this->_addon_slug, // download tag slug. + 'version' => $this->_addon_class::get_instance()->get_version(), // current version number. + 'license_key' => $license_key, // license key (used get_option above to retrieve from DB)..'error'. + 'license_url' => home_url(), // license domain. + 'download_tag' => $this->_addon_slug, // download tag slug. 'beta' => false, 'handler_class' => $this, ) From c258779fceb3afc87ad1a03a669cdf095074bd28 Mon Sep 17 00:00:00 2001 From: Karim Date: Fri, 25 Jul 2025 10:27:21 +0200 Subject: [PATCH 17/21] Implementing the global licensed key --- src/LicenseHandler.php | 2 +- src/changelog.txt | 2 +- .../class-global-license-key-registry.php | 177 +++++++++++----- src/shared/css/gwp-styles.css | 195 ++++++++++++++++++ src/shared/css/gwp-styles.min.css | 1 + 5 files changed, 324 insertions(+), 53 deletions(-) create mode 100644 src/shared/css/gwp-styles.css create mode 100644 src/shared/css/gwp-styles.min.css diff --git a/src/LicenseHandler.php b/src/LicenseHandler.php index 8aa6241..62b29e0 100644 --- a/src/LicenseHandler.php +++ b/src/LicenseHandler.php @@ -53,7 +53,7 @@ class LicenseHandler { * * @var mixed|string */ - private $version = '2.0.6'; + private $version = '2.1.0'; /** * WP Override flag diff --git a/src/changelog.txt b/src/changelog.txt index 5723a4c..51cced6 100644 --- a/src/changelog.txt +++ b/src/changelog.txt @@ -1,4 +1,4 @@ -= 2.0.6 = += 2.1.0 = - Implementing the global licensed key. = 2.0.5 = diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 424c7a8..592c456 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -41,6 +41,18 @@ public static function init( $version ) { add_action( 'admin_menu', array( self::class, 'add_admin_menu' ) ); add_action( 'admin_init', array( self::class, 'register_settings' ) ); } + + /** + * Registers the settings for the GravityWP plugin. + * + * This method registers the 'gravitywp_global_license_key' option + * under the 'gravitywp_settings_group' settings group. + * + * @return void + */ + public static function register_settings() { + register_setting( 'gravitywp_settings_group', 'gravitywp_global_license_key' ); + } /** * Adds the GravityWP settings page to the WordPress admin menu. @@ -60,17 +72,6 @@ public static function add_admin_menu() { array( self::class, 'render_settings_page' ) ); } - /** - * Registers the settings for the GravityWP plugin. - * - * This method registers the 'gravitywp_global_license_key' option - * under the 'gravitywp_settings_group' settings group. - * - * @return void - */ - public static function register_settings() { - register_setting( 'gravitywp_settings_group', 'gravitywp_global_license_key' ); - } /** * Renders the GravityWP plugin settings page. @@ -151,53 +152,127 @@ public static function render_settings_page() {

- + ()

- - - - - - -
- - - -
- -
- + +
+ +
+ + +
+ +
+ -
-

- - -

-
    -
  • :
  • -
  • :
  • -
  • :
  • -
  • :
  • -
  • :
  • -
+
+
+ +

+
+
+
+ + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
- -
-

- - -

- -
- -
- + +
+
+ +

+
+ +
+ +
+ +
+
+ Date: Fri, 25 Jul 2025 10:32:24 +0200 Subject: [PATCH 18/21] adding glk_version for logs --- src/shared/class-global-license-key-registry.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 592c456..bc5c280 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -41,7 +41,7 @@ public static function init( $version ) { add_action( 'admin_menu', array( self::class, 'add_admin_menu' ) ); add_action( 'admin_init', array( self::class, 'register_settings' ) ); } - + /** * Registers the settings for the GravityWP plugin. * @@ -94,6 +94,7 @@ public static function render_settings_page() { 'license_key' => $global_key, 'license_url' => home_url(), 'action' => 'activate', + 'glk_version' => esc_html( self::$version ), ), 'https://my.gravitywp.com/wp-json/paddlepress-api/v1/license' ); From ac7bca6353eefe953d9a01436b29f7b20aa0628e Mon Sep 17 00:00:00 2001 From: Karim Date: Fri, 25 Jul 2025 12:58:46 +0200 Subject: [PATCH 19/21] Enqueues admin styles for the GravityWP settings page. --- .../class-global-license-key-registry.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index bc5c280..2c8a3f7 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -40,6 +40,25 @@ public static function init( $version ) { self::$version = $version; add_action( 'admin_menu', array( self::class, 'add_admin_menu' ) ); add_action( 'admin_init', array( self::class, 'register_settings' ) ); + add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_admin_styles' ) ); + } + + /** + * Enqueues admin styles for the GravityWP settings page. + * + * @param string $hook The current admin page hook. + * @return void + */ + public static function enqueue_admin_styles( $hook ) { + // Check if we are on the GravityWP settings page. + if ( 'gravityforms_page_gravitywp-settings' === $hook ) { + wp_enqueue_style( + 'gravitywp-admin-styles', + plugins_url( 'css/admin-styles.css', __FILE__ ), + array(), + self::$version + ); + } } /** From cdb6232ae5d3fcb7e1af5d04c71afbb9d8c10f2b Mon Sep 17 00:00:00 2001 From: Karim Date: Fri, 25 Jul 2025 13:32:50 +0200 Subject: [PATCH 20/21] fix enqueue_admin_styles --- src/shared/class-global-license-key-registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 2c8a3f7..8b01fb2 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -51,7 +51,7 @@ public static function init( $version ) { */ public static function enqueue_admin_styles( $hook ) { // Check if we are on the GravityWP settings page. - if ( 'gravityforms_page_gravitywp-settings' === $hook ) { + if ( 'forms_page_gravitywp-settings' === $hook ) { wp_enqueue_style( 'gravitywp-admin-styles', plugins_url( 'css/admin-styles.css', __FILE__ ), From da54c901438fba9a0babf72e76c5537c4f859210 Mon Sep 17 00:00:00 2001 From: Karim Date: Fri, 25 Jul 2025 13:57:07 +0200 Subject: [PATCH 21/21] fix gwp-styles --- src/shared/class-global-license-key-registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/class-global-license-key-registry.php b/src/shared/class-global-license-key-registry.php index 8b01fb2..34c3e99 100644 --- a/src/shared/class-global-license-key-registry.php +++ b/src/shared/class-global-license-key-registry.php @@ -54,7 +54,7 @@ public static function enqueue_admin_styles( $hook ) { if ( 'forms_page_gravitywp-settings' === $hook ) { wp_enqueue_style( 'gravitywp-admin-styles', - plugins_url( 'css/admin-styles.css', __FILE__ ), + plugins_url( 'css/gwp-styles.min.css', __FILE__ ), array(), self::$version );