| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | namespace YayMailScoped\YayCommerce\AdminShell\License; |
| 4 | 4 | |
| 5 | 5 | use YayMailScoped\YayCommerce\AdminShell\License\Contracts\LicenseConfigAdapter; |
| 6 | 6 | use YayMailScoped\YayCommerce\AdminShell\Support\Slug; |
| 7 | -\defined('ABSPATH') || exit; | |
| 7 | +defined('ABSPATH') || exit; | |
| 8 | 8 | /** |
| 9 | 9 | * License activation/deactivation/check state machine. |
| 10 | 10 | * |
| 11 | 11 | * NOTE: This file exceeds 200 LOC because it aggregates all WordPress admin |
| @@ -21,9 +21,8 @@ | ||
| 21 | 21 | * |
| 22 | 22 | * NOTE: The original LicenseHandler used CorePlugin::get() for item_id/slug/etc. |
| 23 | 23 | * Here those values come from the injected LicenseConfigAdapter. Port is faithful; |
| 24 | 24 | * any oddities from source preserved with // TODO: investigate comments. |
| 25 | - * @internal | |
| 26 | 25 | */ |
| 27 | 26 | class LicenseHandler |
| 28 | 27 | { |
| 29 | 28 | protected LicenseConfigAdapter $adapter; |
| @@ -32,9 +31,9 @@ | ||
| 32 | 31 | { |
| 33 | 32 | $this->adapter = $adapter; |
| 34 | 33 | $this->license = new License($adapter); |
| 35 | 34 | new RestAPI($adapter); |
| 36 | - if (\is_admin()) { | |
| 35 | + if (is_admin()) { | |
| 37 | 36 | $this->do_hooks(); |
| 38 | 37 | $this->do_cron_job(); |
| 39 | 38 | $this->do_post_requests(); |
| 40 | 39 | $this->show_plugin_page_notification(); |
| @@ -39,9 +38,9 @@ | ||
| 39 | 38 | $this->do_post_requests(); |
| 40 | 39 | $this->show_plugin_page_notification(); |
| 41 | 40 | } |
| 42 | 41 | } |
| 43 | - public function do_hooks() : void | |
| 42 | + public function do_hooks(): void | |
| 44 | 43 | { |
| 45 | 44 | add_action('admin_notices', [$this, 'not_activate_license_notice']); |
| 46 | 45 | add_action('admin_enqueue_scripts', [$this, 'enqueue_license_scripts']); |
| 47 | 46 | add_action('yaycommerce_licenses_page', [$this, 'render_license_settings'], 100); |
| @@ -62,31 +61,31 @@ | ||
| 62 | 61 | * Handle POST-based license form submissions (legacy AJAX path). |
| 63 | 62 | * REST API (RestAPI.php) is the primary path — this is a no-op |
| 64 | 63 | * placeholder for backward compatibility with any direct form posts. |
| 65 | 64 | */ |
| 66 | - public function do_post_requests() : void | |
| 65 | + public function do_post_requests(): void | |
| 67 | 66 | { |
| 68 | 67 | // REST API handles all license actions. No legacy POST handling needed. |
| 69 | 68 | } |
| 70 | - public function do_cron_job() : void | |
| 69 | + public function do_cron_job(): void | |
| 71 | 70 | { |
| 72 | 71 | add_filter('cron_schedules', [$this, 'custom_schedules']); |
| 73 | 72 | add_action('check_license_cron_' . $this->adapter->get_plugin_slug(), [$this, 'check_license_cron_run']); |
| 74 | 73 | $cron_hook = 'check_license_cron_' . $this->adapter->get_plugin_slug(); |
| 75 | 74 | if (!wp_next_scheduled($cron_hook)) { |
| 76 | - wp_schedule_event(\time(), 'daily', $cron_hook); | |
| 75 | + wp_schedule_event(time(), 'daily', $cron_hook); | |
| 77 | 76 | } |
| 78 | 77 | } |
| 79 | - public function custom_schedules(array $schedules) : array | |
| 78 | + public function custom_schedules(array $schedules): array | |
| 80 | 79 | { |
| 81 | 80 | $schedules['3hours'] = ['interval' => 60 * 60 * 3, 'display' => 'Three Hours']; |
| 82 | 81 | return $schedules; |
| 83 | 82 | } |
| 84 | - public function check_license_cron_run() : void | |
| 83 | + public function check_license_cron_run(): void | |
| 85 | 84 | { |
| 86 | 85 | $this->license->update(); |
| 87 | 86 | } |
| 88 | - public function enqueue_license_scripts() : void | |
| 87 | + public function enqueue_license_scripts(): void | |
| 89 | 88 | { |
| 90 | 89 | if (!isset($_GET['page']) || 'yaycommerce-licenses' !== $_GET['page']) { |
| 91 | 90 | // phpcs:ignore WordPress.Security.NonceVerification |
| 92 | 91 | return; |
| @@ -91,13 +90,13 @@ | ||
| 91 | 90 | // phpcs:ignore WordPress.Security.NonceVerification |
| 92 | 91 | return; |
| 93 | 92 | } |
| 94 | 93 | $slug = $this->adapter->get_plugin_slug(); |
| 95 | - $assets_url = \plugin_dir_url(__FILE__) . '../../assets/'; | |
| 94 | + $assets_url = plugin_dir_url(__FILE__) . '../../assets/'; | |
| 96 | 95 | wp_enqueue_script('yaycommerce-license', $assets_url . 'js/license.js', ['jquery'], $this->adapter->get_plugin_version(), \true); |
| 97 | - wp_localize_script('yaycommerce-license', Slug::to_var_name($slug) . 'LicenseData', ['slug' => $slug, 'apiSettings' => ['restNonce' => wp_create_nonce('wp_rest'), 'restUrl' => \esc_url_raw(rest_url(Slug::to_var_name($slug) . '/v1')), 'adminUrl' => \admin_url()]]); | |
| 96 | + wp_localize_script('yaycommerce-license', Slug::to_var_name($slug) . 'LicenseData', ['slug' => $slug, 'apiSettings' => ['restNonce' => wp_create_nonce('wp_rest'), 'restUrl' => esc_url_raw(rest_url(Slug::to_var_name($slug) . '/v1')), 'adminUrl' => admin_url()]]); | |
| 98 | 97 | } |
| 99 | - public function render_license_settings() : void | |
| 98 | + public function render_license_settings(): void | |
| 100 | 99 | { |
| 101 | 100 | $license = $this->license; |
| 102 | 101 | $_plugin = ['slug' => $this->adapter->get_plugin_slug(), 'name' => $this->adapter->get_plugin_name()]; |
| 103 | 102 | if ($license->is_active()) { |
| @@ -105,14 +104,14 @@ | ||
| 105 | 104 | } else { |
| 106 | 105 | include __DIR__ . '/../../views/license-activate-card.php'; |
| 107 | 106 | } |
| 108 | 107 | } |
| 109 | - public function register_licensing_plugins(array $plugins = []) : array | |
| 108 | + public function register_licensing_plugins(array $plugins = []): array | |
| 110 | 109 | { |
| 111 | 110 | $plugin_data = ['name' => $this->adapter->get_plugin_name(), 'slug' => $this->adapter->get_plugin_slug(), 'basename' => $this->adapter->get_plugin_basename(), 'file' => $this->adapter->get_plugin_file(), 'url' => $this->adapter->get_store_link(), 'item_id' => $this->adapter->get_item_id()]; |
| 112 | - return \array_merge($plugins, [$plugin_data]); | |
| 111 | + return array_merge($plugins, [$plugin_data]); | |
| 113 | 112 | } |
| 114 | - public function not_activate_license_notice() : void | |
| 113 | + public function not_activate_license_notice(): void | |
| 115 | 114 | { |
| 116 | 115 | $current_screen = get_current_screen(); |
| 117 | 116 | if (!$current_screen || $current_screen->id !== 'plugins') { |
| 118 | 117 | return; |
| @@ -126,15 +125,15 @@ | ||
| 126 | 125 | <div class="error"> |
| 127 | 126 | <p> |
| 128 | 127 | <?php |
| 129 | 128 | // translators: %1$s plugin name, %2$s link open, %3$s link close |
| 130 | - \printf(\esc_html__('%1$s license key is required. %2$sPlease enter your license key to start using the plugin%3$s.', 'yaycommerce'), \esc_html($name), '<a href="' . \esc_url(\admin_url('admin.php?page=yaycommerce-licenses')) . '">', '</a>'); | |
| 129 | + printf(esc_html__('%1$s license key is required. %2$sPlease enter your license key to start using the plugin%3$s.', 'yaycommerce'), esc_html($name), '<a href="' . esc_url(admin_url('admin.php?page=yaycommerce-licenses')) . '">', '</a>'); | |
| 131 | 130 | ?> |
| 132 | 131 | </p> |
| 133 | 132 | </div> |
| 134 | 133 | <?php |
| 135 | 134 | } |
| 136 | - public function license_expired_admin_notice() : void | |
| 135 | + public function license_expired_admin_notice(): void | |
| 137 | 136 | { |
| 138 | 137 | if ($this->license->is_active() && $this->license->is_expired()) { |
| 139 | 138 | $name = $this->adapter->get_plugin_name(); |
| 140 | 139 | $renewal_url = $this->license->get_renewal_url(); |
| @@ -141,13 +140,13 @@ | ||
| 141 | 140 | ?> |
| 142 | 141 | <div class="notice notice-warning"> |
| 143 | 142 | <p> |
| 144 | 143 | <?php |
| 145 | - \printf( | |
| 144 | + printf( | |
| 146 | 145 | /* translators: %1$s plugin name, %2$s renewal URL */ |
| 147 | - \esc_html__('%1$s: Your license has expired. %2$sRenew now%3$s to continue receiving updates.', 'yaycommerce'), | |
| 148 | - \esc_html($name), | |
| 149 | - '<a href="' . \esc_url($renewal_url) . '" target="_blank">', | |
| 146 | + esc_html__('%1$s: Your license has expired. %2$sRenew now%3$s to continue receiving updates.', 'yaycommerce'), | |
| 147 | + esc_html($name), | |
| 148 | + '<a href="' . esc_url($renewal_url) . '" target="_blank">', | |
| 150 | 149 | '</a>' |
| 151 | 150 | ); |
| 152 | 151 | ?> |
| 153 | 152 | </p> |
| @@ -154,13 +153,13 @@ | ||
| 154 | 153 | </div> |
| 155 | 154 | <?php |
| 156 | 155 | } |
| 157 | 156 | } |
| 158 | - public function show_plugin_page_notification() : void | |
| 157 | + public function show_plugin_page_notification(): void | |
| 159 | 158 | { |
| 160 | 159 | add_action('after_plugin_row_' . $this->adapter->get_plugin_basename(), [$this, 'plugin_notifications'], 10, 2); |
| 161 | 160 | } |
| 162 | - public function plugin_notifications(string $file) : void | |
| 161 | + public function plugin_notifications(string $file): void | |
| 163 | 162 | { |
| 164 | 163 | if ($this->adapter->get_plugin_basename() !== $file) { |
| 165 | 164 | return; |
| 166 | 165 | } |
| @@ -172,12 +171,12 @@ | ||
| 172 | 171 | ?> |
| 173 | 172 | <div class="update-message notice inline notice-warning notice-alt"> |
| 174 | 173 | <p> |
| 175 | 174 | <a href="<?php |
| 176 | - echo \esc_url(\admin_url('admin.php?page=yaycommerce-licenses')); | |
| 175 | + echo esc_url(admin_url('admin.php?page=yaycommerce-licenses')); | |
| 177 | 176 | ?>"> |
| 178 | 177 | <?php |
| 179 | - \esc_html_e('Please activate your license for access to premium features and automatic updates', 'yaycommerce'); | |
| 178 | + esc_html_e('Please activate your license for access to premium features and automatic updates', 'yaycommerce'); | |
| 180 | 179 | ?> |
| 181 | 180 | </a>. |
| 182 | 181 | </p> |
| 183 | 182 | </div> |
| @@ -189,17 +188,17 @@ | ||
| 189 | 188 | ?> |
| 190 | 189 | <div class="update-message notice inline notice-warning notice-alt"> |
| 191 | 190 | <p class="license_expired_text"> |
| 192 | 191 | <span><?php |
| 193 | - echo \esc_html('Your license has expired, please '); | |
| 192 | + echo esc_html('Your license has expired, please '); | |
| 194 | 193 | ?></span> |
| 195 | 194 | <a target="_blank" href="<?php |
| 196 | - echo \esc_url($this->license->get_renewal_url()); | |
| 195 | + echo esc_url($this->license->get_renewal_url()); | |
| 197 | 196 | ?>"><?php |
| 198 | - echo \esc_html('renew this license'); | |
| 197 | + echo esc_html('renew this license'); | |
| 199 | 198 | ?></a> |
| 200 | 199 | <span><?php |
| 201 | - echo \esc_html(' to download this update. '); | |
| 200 | + echo esc_html(' to download this update. '); | |
| 202 | 201 | ?></span> |
| 203 | 202 | </p> |
| 204 | 203 | </div> |
| 205 | 204 | <?php |
| @@ -211,17 +210,17 @@ | ||
| 211 | 210 | } |
| 212 | 211 | /** |
| 213 | 212 | * Add "Enter license key" action link when license is inactive. |
| 214 | 213 | */ |
| 215 | - public function add_license_action_link(array $action_links) : array | |
| 214 | + public function add_license_action_link(array $action_links): array | |
| 216 | 215 | { |
| 217 | - $link = ['license' => '<a href="' . \admin_url('admin.php?page=yaycommerce-licenses') . '">' . \esc_html__('Enter license key', 'yaycommerce') . '</a>']; | |
| 218 | - return \array_merge($link, $action_links); | |
| 216 | + $link = ['license' => '<a href="' . admin_url('admin.php?page=yaycommerce-licenses') . '">' . esc_html__('Enter license key', 'yaycommerce') . '</a>']; | |
| 217 | + return array_merge($link, $action_links); | |
| 219 | 218 | } |
| 220 | - public function auto_update() : void | |
| 219 | + public function auto_update(): void | |
| 221 | 220 | { |
| 222 | - $doing_cron = \defined('DOING_CRON') && \DOING_CRON; | |
| 223 | - if (!\current_user_can($this->adapter->get_capability()) && !$doing_cron) { | |
| 221 | + $doing_cron = defined('DOING_CRON') && \DOING_CRON; | |
| 222 | + if (!current_user_can($this->adapter->get_capability()) && !$doing_cron) { | |
| 224 | 223 | return; |
| 225 | 224 | } |
| 226 | 225 | $license_key = ''; |
| 227 | 226 | if ($this->license->is_active() && !$this->license->is_expired()) { |
| @@ -229,15 +228,15 @@ | ||
| 229 | 228 | } |
| 230 | 229 | $args = ['version' => $this->adapter->get_plugin_version(), 'license' => $license_key, 'author' => 'YayCommerce', 'item_id' => $this->adapter->get_item_id()]; |
| 231 | 230 | new EDD_SL_Plugin_Updater($this->adapter->get_store_url(), $this->adapter->get_plugin_file(), $args); |
| 232 | 231 | } |
| 233 | - public static function remove_site_plugin_check(LicenseConfigAdapter $adapter) : void | |
| 232 | + public static function remove_site_plugin_check(LicenseConfigAdapter $adapter): void | |
| 234 | 233 | { |
| 235 | 234 | global $pagenow; |
| 236 | 235 | if ('plugin-install.php' === $pagenow) { |
| 237 | 236 | return; |
| 238 | 237 | } |
| 239 | - if (!\function_exists('YayMailScoped\\get_plugin_data')) { | |
| 238 | + if (!function_exists('YayMailScoped\get_plugin_data')) { | |
| 240 | 239 | require_once \ABSPATH . 'wp-admin/includes/plugin.php'; |
| 241 | 240 | } |
| 242 | 241 | $basename = $adapter->get_plugin_basename(); |
| 243 | 242 | $site_transient_update_plugins = get_site_transient('update_plugins'); |
| @@ -245,9 +244,9 @@ | ||
| 245 | 244 | unset($site_transient_update_plugins->checked[$basename]); |
| 246 | 245 | set_site_transient('update_plugins', $site_transient_update_plugins); |
| 247 | 246 | } |
| 248 | 247 | } |
| 249 | - public function support_auto_update(array $plugins) : array | |
| 248 | + public function support_auto_update(array $plugins): array | |
| 250 | 249 | { |
| 251 | 250 | foreach ($plugins['all'] as $ind => $active_plugin) { |
| 252 | 251 | if ('YayCommerce' === $active_plugin['Author']) { |
| 253 | 252 | $plugins['all'][$ind]['update-supported'] = \true; |
| @@ -266,13 +265,13 @@ | ||
| 266 | 265 | } |
| 267 | 266 | } |
| 268 | 267 | return $value; |
| 269 | 268 | } |
| 270 | - public function is_license_inactive() : bool | |
| 269 | + public function is_license_inactive(): bool | |
| 271 | 270 | { |
| 272 | 271 | return !$this->license->is_active(); |
| 273 | 272 | } |
| 274 | - public function get_license() : License | |
| 273 | + public function get_license(): License | |
| 275 | 274 | { |
| 276 | 275 | return $this->license; |
| 277 | 276 | } |
| 278 | 277 | } |