← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php
+160
-436
4.0.3
→
3.4.7
View file →
| @@ -23,33 +23,16 @@ | ||
| 23 | 23 | /** |
| 24 | 24 | * Licenser module for ThemeIsle SDK. |
| 25 | 25 | */ |
| 26 | 26 | class Licenser extends Abstract_Module { |
| 27 | + | |
| 27 | 28 | /** |
| 28 | - * License VALID status string. | |
| 29 | - */ | |
| 30 | - const STATUS_VALID = 'valid'; | |
| 31 | - /** | |
| 32 | - * License NOT_ACTIVE status string. | |
| 33 | - */ | |
| 34 | - const STATUS_NOT_ACTIVE = 'not_active'; | |
| 35 | - /** | |
| 36 | - * License active expired status string. | |
| 37 | - */ | |
| 38 | - const STATUS_ACTIVE_EXPIRED = 'active_expired'; | |
| 39 | - /** | |
| 40 | 29 | * Number of max failed checks before showing the license message. |
| 41 | 30 | * |
| 42 | 31 | * @var int $max_failed Maximum failed checks allowed before show the notice |
| 43 | 32 | */ |
| 44 | - private static $max_failed = 1; | |
| 33 | + private static $max_failed = 5; | |
| 45 | 34 | /** |
| 46 | - * Flag to check if the global actions were loaded. | |
| 47 | - * | |
| 48 | - * @var bool If the globals actions were loaded. | |
| 49 | - */ | |
| 50 | - private static $globals_loaded = false; | |
| 51 | - /** | |
| 52 | 35 | * License key string. |
| 53 | 36 | * |
| 54 | 37 | * @var string $license_key The license key string |
| 55 | 38 | */ |
| @@ -78,14 +61,8 @@ | ||
| 78 | 61 | * |
| 79 | 62 | * @var null Local license object. |
| 80 | 63 | */ |
| 81 | 64 | private $license_local = null; |
| 82 | - /** | |
| 83 | - * Product namespace, used for fixed name filters/cli commands. | |
| 84 | - * | |
| 85 | - * @var string $namespace Product namespace. | |
| 86 | - */ | |
| 87 | - private $namespace = null; | |
| 88 | 65 | |
| 89 | 66 | /** |
| 90 | 67 | * Disable wporg updates for premium products. |
| 91 | 68 | * |
| @@ -93,9 +70,9 @@ | ||
| 93 | 70 | * @param string $url The api url. |
| 94 | 71 | * |
| 95 | 72 | * @return mixed List of themes to check for update. |
| 96 | 73 | */ |
| 97 | - public function disable_wporg_update( $r, $url ) { | |
| 74 | + function disable_wporg_update( $r, $url ) { | |
| 98 | 75 | |
| 99 | 76 | if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/' ) ) { |
| 100 | 77 | return $r; |
| 101 | 78 | } |
| @@ -105,9 +82,9 @@ | ||
| 105 | 82 | |
| 106 | 83 | unset( $themes->themes->{$this->product->get_slug()} ); |
| 107 | 84 | |
| 108 | 85 | // Encode the updated JSON response. |
| 109 | - $r['body']['themes'] = wp_json_encode( $themes ); | |
| 86 | + $r['body']['themes'] = json_encode( $themes ); | |
| 110 | 87 | |
| 111 | 88 | return $r; |
| 112 | 89 | } |
| 113 | 90 | |
| @@ -137,13 +114,13 @@ | ||
| 137 | 114 | public function license_view() { |
| 138 | 115 | $status = $this->get_license_status(); |
| 139 | 116 | $value = $this->license_key; |
| 140 | 117 | |
| 141 | - $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', Loader::$labels['licenser']['activate'] ); | |
| 142 | - $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', Loader::$labels['licenser']['deactivate'] ); | |
| 143 | - $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', Loader::$labels['licenser']['valid'] ); | |
| 144 | - $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', Loader::$labels['licenser']['invalid'] ); | |
| 145 | - $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', Loader::$labels['licenser']['notice'] ); | |
| 118 | + $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' ); | |
| 119 | + $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' ); | |
| 120 | + $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' ); | |
| 121 | + $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' ); | |
| 122 | + $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', 'Enter your license from %s purchase history in order to get %s updates' ); | |
| 146 | 123 | $error_message = $this->get_error(); |
| 147 | 124 | ?> |
| 148 | 125 | <style type="text/css"> |
| 149 | 126 | input.themeisle-sdk-text-input-valid { |
| @@ -194,20 +171,20 @@ | ||
| 194 | 171 | </style> |
| 195 | 172 | <?php |
| 196 | 173 | echo sprintf( |
| 197 | 174 | '<p>%s<input class="themeisle-sdk-license-input %s" type="text" id="%s_license" name="%s_license" value="%s" /><a class="%s">%s</a> <button name="%s_btn_trigger" class="button button-primary themeisle-sdk-licenser-button-cta" value="yes" type="submit" >%s</button></p><p class="description">%s</p>%s', |
| 198 | - ( ( 'valid' === $status ) ? sprintf( '<input type="hidden" value="%s" name="%s_license" />', esc_attr( $value ), esc_attr( $this->product->get_key() ) ) : '' ), | |
| 175 | + ( ( 'valid' === $status ) ? sprintf( '<input type="hidden" value="%s" name="%s_license" />', $value, $this->product->get_key() ) : '' ), | |
| 199 | 176 | ( ( 'valid' === $status ) ? 'themeisle-sdk-text-input-valid' : '' ), |
| 200 | - esc_attr( $this->product->get_key() ), | |
| 201 | - esc_attr( ( ( 'valid' === $status ) ? $this->product->get_key() . '_mask' : $this->product->get_key() ) ), | |
| 202 | - esc_attr( ( ( 'valid' === $status ) ? ( str_repeat( '*', 30 ) . substr( $value, - 5 ) ) : $value ) ), | |
| 203 | - esc_attr( ( 'valid' === $status ? 'themeisle-sdk-license-deactivate-cta' : 'themeisle-sdk-license-activate-cta' ) ), | |
| 204 | - esc_attr( 'valid' === $status ? $valid_string : $invalid_string ), | |
| 205 | - esc_attr( $this->product->get_key() ), | |
| 206 | - esc_attr( 'valid' === $status ? $deactivate_string : $activate_string ), | |
| 207 | - sprintf( wp_kses_data( $license_message ), '<a href="' . esc_url( $this->get_api_url() ) . '">' . esc_attr( $this->get_distributor_name() ) . '</a> ', esc_attr( $this->product->get_type() ) ), | |
| 208 | - wp_kses_data( empty( $error_message ) ? '' : sprintf( '<p style="color:#dd3d36">%s</p>', ( $error_message ) ) ) | |
| 209 | - ) . wp_nonce_field( $this->product->get_key() . 'nonce', $this->product->get_key() . 'nonce_field', false, false );//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 177 | + $this->product->get_key(), | |
| 178 | + ( ( 'valid' === $status ) ? $this->product->get_key() . '_mask' : $this->product->get_key() ), | |
| 179 | + ( ( 'valid' === $status ) ? ( str_repeat( '*', 30 ) . substr( $value, - 5 ) ) : $value ), | |
| 180 | + ( 'valid' === $status ? 'themeisle-sdk-license-deactivate-cta' : 'themeisle-sdk-license-activate-cta' ), | |
| 181 | + ( 'valid' === $status ? $valid_string : $invalid_string ), | |
| 182 | + $this->product->get_key(), | |
| 183 | + ( 'valid' === $status ? $deactivate_string : $activate_string ), | |
| 184 | + sprintf( $license_message, '<a href="' . $this->get_api_url() . '">' . $this->get_distributor_name() . '</a> ', $this->product->get_type() ), | |
| 185 | + empty( $error_message ) ? '' : sprintf( '<p style="color:#dd3d36">%s</p>', $error_message ) | |
| 186 | + ); | |
| 210 | 187 | |
| 211 | 188 | } |
| 212 | 189 | |
| 213 | 190 | /** |
| @@ -232,104 +209,22 @@ | ||
| 232 | 209 | return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status; |
| 233 | 210 | } |
| 234 | 211 | |
| 235 | 212 | /** |
| 236 | - * Check status. | |
| 213 | + * License price id. | |
| 237 | 214 | * |
| 238 | - * @param string $product_file Product basefile. | |
| 239 | - * | |
| 240 | - * @return string Status license. | |
| 215 | + * @return int License plan. | |
| 241 | 216 | */ |
| 242 | - public static function status( $product_file ) { | |
| 243 | - $product = Product::get( $product_file ); | |
| 244 | - if ( ! $product->requires_license() ) { | |
| 245 | - return self::STATUS_VALID; | |
| 217 | + public function get_plan() { | |
| 218 | + $license_data = get_option( $this->product->get_key() . '_license_data', '' ); | |
| 219 | + if ( ! isset( $license_data->price_id ) ) { | |
| 220 | + return -1; | |
| 246 | 221 | } |
| 247 | - $license_data = self::get_license_data( $product->get_key() ); | |
| 248 | 222 | |
| 249 | - $status = isset( $license_data->license ) ? $license_data->license : self::STATUS_NOT_ACTIVE; | |
| 250 | - | |
| 251 | - return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status; | |
| 223 | + return (int) $license_data->price_id; | |
| 252 | 224 | } |
| 253 | 225 | |
| 254 | 226 | /** |
| 255 | - * Product license data. | |
| 256 | - * | |
| 257 | - * @param string $key Product key. | |
| 258 | - * | |
| 259 | - * @return false|mixed|null | |
| 260 | - */ | |
| 261 | - private static function get_license_data( $key ) { | |
| 262 | - $license_data = get_option( $key . '_license_data', '' ); | |
| 263 | - | |
| 264 | - return isset( $license_data->license ) ? $license_data : false; | |
| 265 | - } | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * Get license hash. | |
| 269 | - * | |
| 270 | - * @param string $key Product key. | |
| 271 | - * | |
| 272 | - * @return bool|string | |
| 273 | - */ | |
| 274 | - public static function create_license_hash( $key ) { | |
| 275 | - $data = self::get_license_data( $key ); | |
| 276 | - | |
| 277 | - if ( ! $data ) { | |
| 278 | - return false; | |
| 279 | - } | |
| 280 | - | |
| 281 | - return isset( $data->key ) ? wp_hash( $data->key ) : false; | |
| 282 | - } | |
| 283 | - | |
| 284 | - /** | |
| 285 | - * Check if license is valid. | |
| 286 | - * | |
| 287 | - * @param string $product_file Product basefile. | |
| 288 | - * | |
| 289 | - * @return bool Is valid? | |
| 290 | - */ | |
| 291 | - public static function is_valid( $product_file ) { | |
| 292 | - return self::status( $product_file ) === self::STATUS_VALID; | |
| 293 | - } | |
| 294 | - | |
| 295 | - /** | |
| 296 | - * Get product plan. | |
| 297 | - * | |
| 298 | - * @param string $product_file Product file. | |
| 299 | - * | |
| 300 | - * @return int Plan id. | |
| 301 | - */ | |
| 302 | - public static function plan( $product_file ) { | |
| 303 | - $product = Product::get( $product_file ); | |
| 304 | - $data = self::get_license_data( $product->get_key() ); | |
| 305 | - | |
| 306 | - return isset( $data->price_id ) ? (int) $data->price_id : - 1; | |
| 307 | - } | |
| 308 | - | |
| 309 | - /** | |
| 310 | - * Get product license key. | |
| 311 | - * | |
| 312 | - * @param string $product_file Product file. | |
| 313 | - * | |
| 314 | - * @return string | |
| 315 | - */ | |
| 316 | - public static function key( $product_file ) { | |
| 317 | - $product = Product::get( $product_file ); | |
| 318 | - | |
| 319 | - return $product->get_license(); | |
| 320 | - } | |
| 321 | - | |
| 322 | - /** | |
| 323 | - * Return the last error message. | |
| 324 | - * | |
| 325 | - * @return mixed Error message. | |
| 326 | - */ | |
| 327 | - public function get_error() { | |
| 328 | - return get_transient( $this->product->get_key() . 'act_err' ); | |
| 329 | - } | |
| 330 | - | |
| 331 | - /** | |
| 332 | 227 | * Get remote api url. |
| 333 | 228 | * |
| 334 | 229 | * @return string Remote api url. |
| 335 | 230 | */ |
| @@ -347,9 +242,9 @@ | ||
| 347 | 242 | * @return string Remote api url. |
| 348 | 243 | */ |
| 349 | 244 | public function get_distributor_name() { |
| 350 | 245 | if ( $this->is_from_partner( $this->product ) ) { |
| 351 | - return 'Themeisle'; | |
| 246 | + return 'ThemeIsle'; | |
| 352 | 247 | } |
| 353 | 248 | |
| 354 | 249 | return $this->product->get_store_name(); |
| 355 | 250 | } |
| @@ -354,22 +249,13 @@ | ||
| 354 | 249 | return $this->product->get_store_name(); |
| 355 | 250 | } |
| 356 | 251 | |
| 357 | 252 | /** |
| 358 | - * License price id. | |
| 359 | - * | |
| 360 | - * @return int License plan. | |
| 361 | - */ | |
| 362 | - public function get_plan() { | |
| 363 | - return self::plan( $this->product->get_basefile() ); | |
| 364 | - } | |
| 365 | - | |
| 366 | - /** | |
| 367 | 253 | * Show the admin notice regarding the license status. |
| 368 | 254 | * |
| 369 | 255 | * @return bool Should we show the notice ? |
| 370 | 256 | */ |
| 371 | - public function show_notice() { | |
| 257 | + function show_notice() { | |
| 372 | 258 | if ( ! is_admin() ) { |
| 373 | 259 | return false; |
| 374 | 260 | } |
| 375 | 261 | |
| @@ -377,11 +263,11 @@ | ||
| 377 | 263 | return false; |
| 378 | 264 | } |
| 379 | 265 | |
| 380 | 266 | $status = $this->get_license_status( true ); |
| 381 | - $no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', Loader::$labels['licenser']['no_activations'] ); | |
| 382 | - $no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', sprintf( Loader::$labels['licenser']['inactive'], '%s', '<a href="%s" target="_blank">', '</a>', '<a href="%s">', '</a>' ) ); | |
| 383 | - $expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_heading_string', Loader::$labels['licenser']['expired'] ); | |
| 267 | + $no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No more activations left for %s. You need to upgrade your plan in order to use %s on more websites. If you need assistance, please get in touch with %s staff.' ); | |
| 268 | + $no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' ); | |
| 269 | + $expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_string', 'Your %s License Key has expired. In order to continue receiving support and software updates you must <a href="%s" target="_blank">renew</a> your license key.' ); | |
| 384 | 270 | // No activations left for this license. |
| 385 | 271 | if ( 'valid' != $status && $this->check_activation() ) { |
| 386 | 272 | ?> |
| 387 | 273 | <div class="error"> |
| @@ -387,12 +273,12 @@ | ||
| 387 | 273 | <div class="error"> |
| 388 | 274 | <p><strong> |
| 389 | 275 | <?php |
| 390 | 276 | echo sprintf( |
| 391 | - wp_kses_data( $no_activations_string ), | |
| 392 | - esc_attr( $this->product->get_name() ), | |
| 393 | - esc_attr( $this->product->get_name() ), | |
| 394 | - '<a href="' . esc_url( $this->get_api_url() ) . '" target="_blank">' . esc_attr( $this->get_distributor_name() ) . '</a>' | |
| 277 | + $no_activations_string, | |
| 278 | + $this->product->get_name(), | |
| 279 | + $this->product->get_name(), | |
| 280 | + '<a href="' . $this->get_api_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>' | |
| 395 | 281 | ); |
| 396 | 282 | ?> |
| 397 | 283 | </strong> |
| 398 | 284 | </p> |
| @@ -402,74 +288,14 @@ | ||
| 402 | 288 | } |
| 403 | 289 | |
| 404 | 290 | // Invalid license key. |
| 405 | 291 | if ( 'active_expired' === $status ) { |
| 406 | - // Check if the notice was dismissed. | |
| 407 | - $dismiss_option_key = $this->product->get_key() . '_expired_notice_dismissed'; | |
| 408 | - if ( get_option( $dismiss_option_key, false ) ) { | |
| 409 | - return false; | |
| 410 | - } | |
| 411 | - | |
| 412 | - $license_data = get_option( $this->product->get_key() . '_license_data', '' ); | |
| 413 | - $expiration_date = ''; | |
| 414 | - if ( is_object( $license_data ) && isset( $license_data->expires ) ) { | |
| 415 | - $timestamp = strtotime( (string) $license_data->expires ); | |
| 416 | - if ( false !== $timestamp ) { | |
| 417 | - $expiration_date = gmdate( 'F j, Y', $timestamp ); | |
| 418 | - } | |
| 419 | - } | |
| 420 | - | |
| 421 | - $discount_config = apply_filters( $this->product->get_key() . '_lc_renew_discount', false ); | |
| 422 | - | |
| 423 | - if ( is_array( $discount_config ) && isset( $discount_config['url'] ) && isset( $discount_config['renew_button'] ) ) { | |
| 424 | - $renew_url = $discount_config['url']; | |
| 425 | - $renew_button = $discount_config['renew_button']; | |
| 426 | - } else { | |
| 427 | - $renew_url = apply_filters( $this->product->get_key() . '_lc_renew_url', $this->renew_url() ); | |
| 428 | - $renew_button = apply_filters( $this->product->get_key() . '_lc_renew_button_string', Loader::$labels['licenser']['renew_license'] ); | |
| 429 | - } | |
| 430 | - | |
| 431 | - $learn_more_url = apply_filters( $this->product->get_key() . '_lc_learn_more_url', $this->get_api_url() ); | |
| 432 | - $learn_more_button = apply_filters( $this->product->get_key() . '_lc_learn_more_button_string', Loader::$labels['licenser']['learn_more'] ); | |
| 433 | - $notice_message = apply_filters( $this->product->get_key() . '_lc_expired_notice_message', Loader::$labels['licenser']['expired_notice'] ); | |
| 434 | - | |
| 435 | - $expired_date_string = apply_filters( $this->product->get_key() . '_lc_expired_date_string', sprintf( Loader::$labels['licenser']['expired_date'], esc_html( $expiration_date ) ) ); | |
| 436 | - $heading = apply_filters( $this->product->get_key() . '_lc_expired_heading_string', sprintf( Loader::$labels['licenser']['expired'], $this->product->get_name() ) ); | |
| 437 | - $notice_id = $this->product->get_key() . '_expired_notice'; | |
| 438 | 292 | ?> |
| 439 | - <div class="notice notice-warning notice-alt is-dismissible themeisle-sdk-license-notice" id="<?php echo esc_attr( $notice_id ); ?>" data-notice-id="<?php echo esc_attr( $notice_id ); ?>" style="position: relative; border-left: 4px solid #d63638; padding: 12px; background-color: #fff;"> | |
| 440 | - <p style="margin: 0.5em 0; font-size: 13px;"> | |
| 441 | - <strong><?php echo wp_kses_post( $heading ); ?></strong> | |
| 442 | - · <?php echo esc_html( $expired_date_string ); ?> | |
| 293 | + <div class="error"> | |
| 294 | + <p> | |
| 295 | + <strong><?php echo sprintf( $expired_license_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url() . '?license=' . $this->license_key ); ?> </strong> | |
| 443 | 296 | </p> |
| 444 | - <p style="margin: 0.5em 0 1em 0; font-size: 13px;"> | |
| 445 | - <?php echo esc_html( $notice_message ); ?> | |
| 446 | - </p> | |
| 447 | - <p style="margin: 0.5em 0;"> | |
| 448 | - <a href="<?php echo esc_url( $renew_url ); ?>" class="button button-primary" target="_blank" rel="noopener noreferrer"> | |
| 449 | - <?php echo esc_html( $renew_button ); ?> | |
| 450 | - </a> | |
| 451 | - <a href="<?php echo esc_url( $learn_more_url ); ?>" class="button" target="_blank" rel="noopener noreferrer" style="border: none; background-color: transparent;"> | |
| 452 | - <?php echo esc_html( $learn_more_button ); ?> | |
| 453 | - </a> | |
| 454 | - </p> | |
| 455 | 297 | </div> |
| 456 | - <script type="text/javascript"> | |
| 457 | - jQuery(document).ready(function($) { | |
| 458 | - $('#<?php echo esc_js( $notice_id ); ?>').on('click', '.notice-dismiss', function(e) { | |
| 459 | - const noticeId = '<?php echo esc_js( $notice_id ); ?>'; | |
| 460 | - $.ajax({ | |
| 461 | - url: ajaxurl, | |
| 462 | - type: 'POST', | |
| 463 | - data: { | |
| 464 | - action: 'themeisle_sdk_dismiss_license_notice', | |
| 465 | - notice_id: noticeId, | |
| 466 | - nonce: '<?php echo esc_js( wp_create_nonce( 'themeisle_sdk_dismiss_license_notice' ) ); ?>' | |
| 467 | - } | |
| 468 | - }); | |
| 469 | - }); | |
| 470 | - }); | |
| 471 | - </script> | |
| 472 | 298 | <?php |
| 473 | 299 | |
| 474 | 300 | return false; |
| 475 | 301 | } |
| @@ -477,9 +303,9 @@ | ||
| 477 | 303 | if ( 'valid' != $status ) { |
| 478 | 304 | ?> |
| 479 | 305 | <div class="error"> |
| 480 | 306 | <p> |
| 481 | - <strong><?php echo sprintf( wp_kses_data( $no_valid_string ), esc_attr( $this->product->get_name() . ' ' . $this->product->get_type() ), esc_url( $this->get_api_url() ), esc_url( admin_url( 'options-general.php' ) . '#' . $this->product->get_key() . '_license' ) ); ?> </strong> | |
| 307 | + <strong><?php echo sprintf( $no_valid_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url(), admin_url( 'options-general.php' ) . '#' . $this->product->get_key() . '_license' ); ?> </strong> | |
| 482 | 308 | </p> |
| 483 | 309 | </div> |
| 484 | 310 | <?php |
| 485 | 311 | |
| @@ -508,9 +334,9 @@ | ||
| 508 | 334 | * Check if the license is about to expire in the next month. |
| 509 | 335 | * |
| 510 | 336 | * @return bool |
| 511 | 337 | */ |
| 512 | - public function check_expiration() { | |
| 338 | + function check_expiration() { | |
| 513 | 339 | $license_data = get_option( $this->product->get_key() . '_license_data', '' ); |
| 514 | 340 | if ( '' === $license_data ) { |
| 515 | 341 | return false; |
| 516 | 342 | } |
| @@ -528,9 +354,9 @@ | ||
| 528 | 354 | * Return the renew url from the store used. |
| 529 | 355 | * |
| 530 | 356 | * @return string The renew url. |
| 531 | 357 | */ |
| 532 | - public function renew_url() { | |
| 358 | + function renew_url() { | |
| 533 | 359 | $license_data = get_option( $this->product->get_key() . '_license_data', '' ); |
| 534 | 360 | if ( '' === $license_data ) { |
| 535 | 361 | return $this->get_api_url(); |
| 536 | 362 | } |
| @@ -537,9 +363,9 @@ | ||
| 537 | 363 | if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) { |
| 538 | 364 | return $this->get_api_url(); |
| 539 | 365 | } |
| 540 | 366 | |
| 541 | - return trim( $this->get_api_url(), '/' ) . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id; | |
| 367 | + return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id; | |
| 542 | 368 | } |
| 543 | 369 | |
| 544 | 370 | /** |
| 545 | 371 | * Run the license check call. |
| @@ -544,9 +370,9 @@ | ||
| 544 | 370 | /** |
| 545 | 371 | * Run the license check call. |
| 546 | 372 | */ |
| 547 | 373 | public function product_valid() { |
| 548 | - if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 374 | + if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) { | |
| 549 | 375 | return; |
| 550 | 376 | } |
| 551 | 377 | $license = $this->check_license(); |
| 552 | 378 | set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS ); |
| @@ -571,17 +397,22 @@ | ||
| 571 | 397 | $response = $this->do_license_process( $license, 'check' ); |
| 572 | 398 | |
| 573 | 399 | if ( is_wp_error( $response ) ) { |
| 574 | 400 | $license_data = new \stdClass(); |
| 575 | - $license_data->license = 'invalid'; | |
| 401 | + $license_data->license = 'valid'; | |
| 576 | 402 | } else { |
| 577 | 403 | $license_data = $response; |
| 578 | 404 | } |
| 579 | 405 | |
| 580 | 406 | $license_old = get_option( $this->product->get_key() . '_license_data', '' ); |
| 581 | - if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) && $this->failed_checks <= self::$max_failed ) { | |
| 407 | + | |
| 408 | + if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) ) { | |
| 582 | 409 | $this->increment_failed_checks(); |
| 410 | + } else { | |
| 411 | + $this->reset_failed_checks(); | |
| 412 | + } | |
| 583 | 413 | |
| 414 | + if ( $this->failed_checks <= self::$max_failed ) { | |
| 584 | 415 | return $license_old; |
| 585 | 416 | } |
| 586 | 417 | |
| 587 | 418 | if ( ! isset( $license_data->key ) ) { |
| @@ -586,9 +417,8 @@ | ||
| 586 | 417 | |
| 587 | 418 | if ( ! isset( $license_data->key ) ) { |
| 588 | 419 | $license_data->key = isset( $license_old->key ) ? $license_old->key : ''; |
| 589 | 420 | } |
| 590 | - $this->reset_failed_checks(); | |
| 591 | 421 | |
| 592 | 422 | return $license_data; |
| 593 | 423 | |
| 594 | 424 | } |
| @@ -593,8 +423,44 @@ | ||
| 593 | 423 | |
| 594 | 424 | } |
| 595 | 425 | |
| 596 | 426 | /** |
| 427 | + * Increment the failed checks. | |
| 428 | + */ | |
| 429 | + private function increment_failed_checks() { | |
| 430 | + $this->failed_checks ++; | |
| 431 | + update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks ); | |
| 432 | + } | |
| 433 | + | |
| 434 | + /** | |
| 435 | + * Reset the failed checks | |
| 436 | + */ | |
| 437 | + private function reset_failed_checks() { | |
| 438 | + $this->failed_checks = 1; | |
| 439 | + update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks ); | |
| 440 | + } | |
| 441 | + | |
| 442 | + /** | |
| 443 | + * Set license validation error message. | |
| 444 | + * | |
| 445 | + * @param string $message Error message. | |
| 446 | + */ | |
| 447 | + public function set_error( $message = '' ) { | |
| 448 | + set_transient( $this->product->get_key() . 'act_err', $message, MINUTE_IN_SECONDS ); | |
| 449 | + | |
| 450 | + return; | |
| 451 | + } | |
| 452 | + | |
| 453 | + /** | |
| 454 | + * Return the last error message. | |
| 455 | + * | |
| 456 | + * @return mixed Error message. | |
| 457 | + */ | |
| 458 | + public function get_error() { | |
| 459 | + return get_transient( $this->product->get_key() . 'act_err' ); | |
| 460 | + } | |
| 461 | + | |
| 462 | + /** | |
| 597 | 463 | * Do license activation/deactivation. |
| 598 | 464 | * |
| 599 | 465 | * @param string $license License key. |
| 600 | 466 | * @param string $action What do to. |
| @@ -602,17 +468,17 @@ | ||
| 602 | 468 | * @return bool|\WP_Error |
| 603 | 469 | */ |
| 604 | 470 | public function do_license_process( $license, $action = 'toggle' ) { |
| 605 | 471 | if ( strlen( $license ) < 10 ) { |
| 606 | - return new \WP_Error( 'themeisle-license-invalid-format', Loader::$labels['licenser']['invalid_msg'] ); | |
| 472 | + return new \WP_Error( 'themeisle-license-invalid-format', 'Invalid license.' ); | |
| 607 | 473 | } |
| 608 | 474 | $status = $this->get_license_status(); |
| 609 | 475 | |
| 610 | 476 | if ( 'valid' === $status && 'activate' === $action ) { |
| 611 | - return new \WP_Error( 'themeisle-license-already-active', Loader::$labels['licenser']['already_active'] ); | |
| 477 | + return new \WP_Error( 'themeisle-license-already-active', 'License is already active.' ); | |
| 612 | 478 | } |
| 613 | 479 | if ( 'valid' !== $status && 'deactivate' === $action ) { |
| 614 | - return new \WP_Error( 'themeisle-license-already-deactivate', Loader::$labels['licenser']['not_active'] ); | |
| 480 | + return new \WP_Error( 'themeisle-license-already-deactivate', 'License not active.' ); | |
| 615 | 481 | } |
| 616 | 482 | |
| 617 | 483 | if ( 'toggle' === $action ) { |
| 618 | 484 | $action = ( 'valid' !== $status ? ( 'activate' ) : ( 'deactivate' ) ); |
| @@ -619,9 +485,9 @@ | ||
| 619 | 485 | } |
| 620 | 486 | |
| 621 | 487 | // Call the custom API. |
| 622 | 488 | if ( 'check' === $action ) { |
| 623 | - $response = $this->safe_get( sprintf( '%slicense/check/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, rawurlencode( home_url() ), Loader::get_cache_token() ) ); | |
| 489 | + $response = wp_remote_get( sprintf( '%slicense/check/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, rawurlencode( home_url() ), Loader::get_cache_token() ) ); | |
| 624 | 490 | } else { |
| 625 | 491 | $response = wp_remote_post( |
| 626 | 492 | sprintf( '%slicense/%s/%s/%s', Product::API_URL, $action, rawurlencode( $this->product->get_name() ), $license ), |
| 627 | 493 | array( |
| @@ -638,15 +504,15 @@ | ||
| 638 | 504 | } |
| 639 | 505 | |
| 640 | 506 | // make sure the response came back okay. |
| 641 | 507 | if ( is_wp_error( $response ) ) { |
| 642 | - return new \WP_Error( 'themeisle-license-500', sprintf( Loader::$labels['licenser']['error_notice'], $response->get_error_message() ) ); | |
| 508 | + return new \WP_Error( 'themeisle-license-500', sprintf( 'ERROR: Failed to connect to the license service. Please try again later. Reason: %s', $response->get_error_message() ) ); | |
| 643 | 509 | } |
| 644 | 510 | |
| 645 | 511 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 646 | 512 | |
| 647 | 513 | if ( ! is_object( $license_data ) ) { |
| 648 | - return new \WP_Error( 'themeisle-license-404', Loader::$labels['licenser']['error_notice2'] ); | |
| 514 | + return new \WP_Error( 'themeisle-license-404', 'ERROR: Failed to validate license. Please try again in one minute.' ); | |
| 649 | 515 | } |
| 650 | 516 | if ( 'check' === $action ) { |
| 651 | 517 | return $license_data; |
| 652 | 518 | } |
| @@ -677,54 +543,23 @@ | ||
| 677 | 543 | } |
| 678 | 544 | update_option( $this->product->get_key() . '_license_data', $license_data ); |
| 679 | 545 | set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS ); |
| 680 | 546 | if ( 'activate' === $action && 'valid' !== $license_data->license ) { |
| 681 | - return new \WP_Error( 'themeisle-license-invalid', Loader::$labels['licenser']['error_invalid'] ); | |
| 547 | + return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' ); | |
| 682 | 548 | } |
| 683 | 549 | |
| 684 | - // Remove the versions transient upon activation so that newer version for rollback can be acquired. | |
| 685 | - $versions_cache = $this->product->get_cache_key(); | |
| 686 | - delete_transient( $versions_cache ); | |
| 687 | - | |
| 688 | 550 | return true; |
| 689 | 551 | } |
| 690 | 552 | |
| 691 | 553 | /** |
| 692 | - * Reset the failed checks | |
| 693 | - */ | |
| 694 | - private function reset_failed_checks() { | |
| 695 | - $this->failed_checks = 1; | |
| 696 | - update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks ); | |
| 697 | - } | |
| 698 | - | |
| 699 | - /** | |
| 700 | - * Increment the failed checks. | |
| 701 | - */ | |
| 702 | - private function increment_failed_checks() { | |
| 703 | - $this->failed_checks ++; | |
| 704 | - update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks ); | |
| 705 | - } | |
| 706 | - | |
| 707 | - /** | |
| 708 | 554 | * Activate the license remotely. |
| 709 | 555 | */ |
| 710 | - public function process_license() { | |
| 556 | + function process_license() { | |
| 711 | 557 | // listen for our activate button to be clicked. |
| 712 | 558 | if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) { |
| 713 | 559 | return; |
| 714 | 560 | } |
| 715 | - if ( ! isset( $_POST[ $this->product->get_key() . 'nonce_field' ] ) | |
| 716 | - || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 717 | - ) { | |
| 718 | - return; | |
| 719 | - } | |
| 720 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 721 | - return; | |
| 722 | - } | |
| 723 | - $license = isset( $_POST[ $this->product->get_key() . '_license' ] ) | |
| 724 | - ? sanitize_text_field( $_POST[ $this->product->get_key() . '_license' ] ) | |
| 725 | - : ''; | |
| 726 | - | |
| 561 | + $license = $_POST[ $this->product->get_key() . '_license' ]; | |
| 727 | 562 | $response = $this->do_license_process( $license, 'toggle' ); |
| 728 | 563 | if ( is_wp_error( $response ) ) { |
| 729 | 564 | $this->set_error( $response->get_error_message() ); |
| 730 | 565 | |
| @@ -732,24 +567,16 @@ | ||
| 732 | 567 | } |
| 733 | 568 | if ( true === $response ) { |
| 734 | 569 | $this->set_error( '' ); |
| 735 | 570 | } |
| 736 | - } | |
| 737 | 571 | |
| 738 | - /** | |
| 739 | - * Set license validation error message. | |
| 740 | - * | |
| 741 | - * @param string $message Error message. | |
| 742 | - */ | |
| 743 | - public function set_error( $message = '' ) { | |
| 744 | - set_transient( $this->product->get_key() . 'act_err', $message, MINUTE_IN_SECONDS ); | |
| 745 | - | |
| 572 | + return; | |
| 746 | 573 | } |
| 747 | 574 | |
| 748 | 575 | /** |
| 749 | 576 | * Load the Themes screen. |
| 750 | 577 | */ |
| 751 | - public function load_themes_screen() { | |
| 578 | + function load_themes_screen() { | |
| 752 | 579 | add_thickbox(); |
| 753 | 580 | add_action( 'admin_notices', array( &$this, 'update_nag' ) ); |
| 754 | 581 | } |
| 755 | 582 | |
| @@ -755,9 +582,9 @@ | ||
| 755 | 582 | |
| 756 | 583 | /** |
| 757 | 584 | * Alter the nag for themes update. |
| 758 | 585 | */ |
| 759 | - public function update_nag() { | |
| 586 | + function update_nag() { | |
| 760 | 587 | $theme = wp_get_theme( $this->product->get_slug() ); |
| 761 | 588 | $api_response = get_transient( $this->product_key ); |
| 762 | 589 | if ( false === $api_response || ! isset( $api_response->new_version ) ) { |
| 763 | 590 | return; |
| @@ -762,22 +589,24 @@ | ||
| 762 | 589 | if ( false === $api_response || ! isset( $api_response->new_version ) ) { |
| 763 | 590 | return; |
| 764 | 591 | } |
| 765 | 592 | $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() ); |
| 766 | - $update_message = apply_filters( 'themeisle_sdk_license_update_message', Loader::$labels['licenser']['update_license'] ); | |
| 593 | + $update_message = apply_filters( 'themeisle_sdk_license_update_message', 'Updating this theme will lose any customizations you have made. Cancel to stop, OK to update.' ); | |
| 767 | 594 | $update_onclick = ' onclick="if ( confirm(\'' . esc_js( $update_message ) . '\') ) {return true;}return false;"'; |
| 768 | 595 | if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) { |
| 769 | 596 | echo '<div id="update-nag">'; |
| 770 | 597 | printf( |
| 771 | - esc_html( Loader::$labels['licenser']['notice_update'] ), | |
| 772 | - '<strong>' . esc_attr( $theme->get( 'Name' ) ) . ' ' . esc_attr( $api_response->new_version ) . '</strong>', | |
| 773 | - '<a href="' . esc_url( sprintf( '%s&TB_iframe=true&width=1024&height=800', $this->product->get_changelog() ) ) . '" class="thickbox" title="' . esc_attr( $theme->get( 'Name' ) ) . '">', | |
| 774 | - '</a>', | |
| 775 | - '<a href="' . esc_url( $update_url ) . '" ' . $update_onclick . '>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped. | |
| 598 | + '<strong>%1$s %2$s</strong> is available. <a href="%3$s" class="thickbox" title="%4s">Check out what\'s new</a> or <a href="%5$s"%6$s>update now</a>.', | |
| 599 | + $theme->get( 'Name' ), | |
| 600 | + $api_response->new_version, | |
| 601 | + sprintf( '%s&TB_iframe=true&width=1024&height=800', $this->product->get_changelog() ), | |
| 602 | + $theme->get( 'Name' ), | |
| 603 | + $update_url, | |
| 604 | + $update_onclick | |
| 776 | 605 | ); |
| 777 | 606 | echo '</div>'; |
| 778 | - echo '<div id="' . esc_attr( $this->product->get_slug() ) . '_changelog" style="display:none;">'; | |
| 779 | - echo wp_kses_data( wpautop( $api_response->sections['changelog'] ) ); | |
| 607 | + echo '<div id="' . $this->product->get_slug() . '_' . 'changelog" style="display:none;">'; | |
| 608 | + echo wpautop( $api_response->sections['changelog'] ); | |
| 780 | 609 | echo '</div>'; |
| 781 | 610 | } |
| 782 | 611 | } |
| 783 | 612 | |
| @@ -787,24 +616,14 @@ | ||
| 787 | 616 | * @param mixed $value The transient data. |
| 788 | 617 | * |
| 789 | 618 | * @return mixed |
| 790 | 619 | */ |
| 791 | - public function theme_update_transient( $value ) { | |
| 620 | + function theme_update_transient( $value ) { | |
| 792 | 621 | $update_data = $this->check_for_update(); |
| 793 | - if ( empty( $value ) ) { | |
| 794 | - return $value; | |
| 622 | + if ( $update_data ) { | |
| 623 | + $value->response[ $this->product->get_slug() ] = $update_data; | |
| 795 | 624 | } |
| 796 | 625 | |
| 797 | - if ( ! isset( $value->response ) ) { | |
| 798 | - return $value; | |
| 799 | - } | |
| 800 | - | |
| 801 | - if ( ! $update_data ) { | |
| 802 | - return $value; | |
| 803 | - } | |
| 804 | - | |
| 805 | - $value->response[ $this->product->get_slug() ] = $update_data; | |
| 806 | - | |
| 807 | 626 | return $value; |
| 808 | 627 | } |
| 809 | 628 | |
| 810 | 629 | /** |
| @@ -811,9 +630,9 @@ | ||
| 811 | 630 | * Check for updates |
| 812 | 631 | * |
| 813 | 632 | * @return array|bool Either the update data or false in case of failure. |
| 814 | 633 | */ |
| 815 | - public function check_for_update() { | |
| 634 | + function check_for_update() { | |
| 816 | 635 | $update_data = get_transient( $this->product_key ); |
| 817 | 636 | |
| 818 | 637 | if ( false === $update_data ) { |
| 819 | 638 | $failed = false; |
| @@ -849,9 +668,9 @@ | ||
| 849 | 668 | * @return bool|mixed Update api response. |
| 850 | 669 | */ |
| 851 | 670 | private function get_version_data() { |
| 852 | 671 | |
| 853 | - $response = $this->safe_get( | |
| 672 | + $response = wp_remote_get( | |
| 854 | 673 | sprintf( |
| 855 | 674 | '%slicense/version/%s/%s/%s/%s', |
| 856 | 675 | Product::API_URL, |
| 857 | 676 | rawurlencode( $this->product->get_name() ), |
| @@ -859,9 +678,9 @@ | ||
| 859 | 678 | $this->product->get_version(), |
| 860 | 679 | rawurlencode( home_url() ) |
| 861 | 680 | ), |
| 862 | 681 | array( |
| 863 | - 'timeout' => 15, //phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout, Inherited by wp_remote_get only, for vip environment we use defaults. | |
| 682 | + 'timeout' => 15, | |
| 864 | 683 | 'sslverify' => false, |
| 865 | 684 | ) |
| 866 | 685 | ); |
| 867 | 686 | if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { |
| @@ -886,10 +705,10 @@ | ||
| 886 | 705 | |
| 887 | 706 | /** |
| 888 | 707 | * Delete the update transient |
| 889 | 708 | */ |
| 890 | - public function delete_theme_update_transient() { | |
| 891 | - return delete_transient( $this->product_key ); | |
| 709 | + function delete_theme_update_transient() { | |
| 710 | + delete_transient( $this->product_key ); | |
| 892 | 711 | } |
| 893 | 712 | |
| 894 | 713 | /** |
| 895 | 714 | * Check for Updates at the defined API endpoint and modify the update array. |
| @@ -905,15 +724,10 @@ | ||
| 905 | 724 | return $_transient_data; |
| 906 | 725 | } |
| 907 | 726 | $api_response = $this->api_request(); |
| 908 | 727 | if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) { |
| 909 | - if ( ! isset( $api_response->plugin ) ) { | |
| 910 | - $api_response->plugin = $this->product->get_slug() . '/' . $this->product->get_file(); | |
| 911 | - } | |
| 912 | 728 | if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) { |
| 913 | 729 | $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response; |
| 914 | - } else { | |
| 915 | - $_transient_data->no_update[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response; | |
| 916 | 730 | } |
| 917 | 731 | } |
| 918 | 732 | |
| 919 | 733 | return $_transient_data; |
| @@ -967,9 +781,9 @@ | ||
| 967 | 781 | * @param string $url Url to check. |
| 968 | 782 | * |
| 969 | 783 | * @return array $array |
| 970 | 784 | */ |
| 971 | - public function http_request_args( $args, $url ) { | |
| 785 | + function http_request_args( $args, $url ) { | |
| 972 | 786 | // If it is an https request and we are performing a package download, disable ssl verification. |
| 973 | 787 | if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
| 974 | 788 | $args['sslverify'] = false; |
| 975 | 789 | } |
| @@ -985,9 +799,9 @@ | ||
| 985 | 799 | * @return bool Should we load the module? |
| 986 | 800 | */ |
| 987 | 801 | public function can_load( $product ) { |
| 988 | 802 | |
| 989 | - if ( ! $product->requires_license() ) { | |
| 803 | + if ( $product->is_wordpress_available() ) { | |
| 990 | 804 | return false; |
| 991 | 805 | } |
| 992 | 806 | |
| 993 | 807 | return ( apply_filters( $product->get_key() . '_enable_licenser', true ) === true ); |
| @@ -1010,19 +824,12 @@ | ||
| 1010 | 824 | if ( $this->product->requires_license() ) { |
| 1011 | 825 | $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) ); |
| 1012 | 826 | $this->register_license_hooks(); |
| 1013 | 827 | } |
| 1014 | - if ( ! self::$globals_loaded ) { | |
| 1015 | - add_filter( 'themeisle_sdk_license/status', [ __CLASS__, 'status' ], 999, 1 ); | |
| 1016 | - add_filter( 'themeisle_sdk_license/is-valid', [ __CLASS__, 'is_valid' ], 999, 1 ); | |
| 1017 | - add_filter( 'themeisle_sdk_license/plan', [ __CLASS__, 'plan' ], 999, 1 ); | |
| 1018 | - add_filter( 'themeisle_sdk_license/key', [ __CLASS__, 'key' ], 999, 1 ); | |
| 1019 | - $globals_loaded = true; | |
| 1020 | - } | |
| 828 | + | |
| 1021 | 829 | $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false ); |
| 1022 | 830 | |
| 1023 | 831 | if ( false !== $namespace ) { |
| 1024 | - $this->namespace = $namespace; | |
| 1025 | 832 | add_filter( 'themeisle_sdk_license_process_' . $namespace, [ $this, 'do_license_process' ], 10, 2 ); |
| 1026 | 833 | add_filter( 'product_' . $namespace . '_license_status', [ $this, 'get_license_status' ], PHP_INT_MAX ); |
| 1027 | 834 | add_filter( 'product_' . $namespace . '_license_key', [ $this->product, 'get_license' ] ); |
| 1028 | 835 | add_filter( 'product_' . $namespace . '_license_plan', [ $this, 'get_plan' ], PHP_INT_MAX ); |
| @@ -1034,61 +841,27 @@ | ||
| 1034 | 841 | } |
| 1035 | 842 | |
| 1036 | 843 | add_action( 'admin_head', [ $this, 'auto_activate' ] ); |
| 1037 | 844 | if ( $this->product->is_plugin() ) { |
| 1038 | - if ( ! $product->is_wordpress_available() ) { | |
| 1039 | - add_filter( | |
| 1040 | - 'pre_set_site_transient_update_plugins', | |
| 1041 | - [ | |
| 1042 | - $this, | |
| 1043 | - 'pre_set_site_transient_update_plugins_filter', | |
| 1044 | - ] | |
| 1045 | - ); | |
| 1046 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); | |
| 1047 | - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1048 | - 'http_request_args', | |
| 1049 | - array( | |
| 1050 | - $this, | |
| 1051 | - 'http_request_args', | |
| 1052 | - ), | |
| 1053 | - 10, | |
| 1054 | - 2 | |
| 1055 | - ); | |
| 1056 | - if ( ! self::is_valid( $product->get_basefile() ) ) { | |
| 1057 | - add_filter( | |
| 1058 | - 'plugin_action_links_' . plugin_basename( $product->get_basefile() ), | |
| 1059 | - function ( $actions ) { | |
| 1060 | - if ( $this->get_license_status( true ) !== self::STATUS_ACTIVE_EXPIRED ) { | |
| 1061 | - return $actions; | |
| 1062 | - } | |
| 1063 | - $new_actions['deactivate'] = $actions['deactivate']; | |
| 1064 | - $new_actions['renew_link'] = '<a style="color:#d63638" href="' . esc_url( $this->renew_url() ) . '" target="_blank" rel="external noopener noreferrer">' . esc_html( Loader::$labels['licenser']['renew_cta'] ) . '</a>'; | |
| 845 | + add_filter( | |
| 846 | + 'pre_set_site_transient_update_plugins', | |
| 847 | + [ | |
| 848 | + $this, | |
| 849 | + 'pre_set_site_transient_update_plugins_filter', | |
| 850 | + ] | |
| 851 | + ); | |
| 852 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); | |
| 853 | + add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 ); | |
| 1065 | 854 | |
| 1066 | - return $new_actions; | |
| 1067 | - } | |
| 1068 | - ); | |
| 1069 | - } | |
| 1070 | - } | |
| 1071 | - | |
| 1072 | 855 | return $this; |
| 1073 | 856 | } |
| 1074 | 857 | if ( $this->product->is_theme() ) { |
| 1075 | - if ( ! $product->is_wordpress_available() ) { | |
| 1076 | - add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) ); | |
| 1077 | - add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1078 | - add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1079 | - add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1080 | - add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) ); | |
| 1081 | - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1082 | - 'http_request_args', | |
| 1083 | - array( | |
| 1084 | - $this, | |
| 1085 | - 'disable_wporg_update', | |
| 1086 | - ), | |
| 1087 | - 5, | |
| 1088 | - 2 | |
| 1089 | - ); | |
| 1090 | - } | |
| 858 | + add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) ); | |
| 859 | + add_filter( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) ); | |
| 860 | + add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 861 | + add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 862 | + add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) ); | |
| 863 | + add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 ); | |
| 1091 | 864 | |
| 1092 | 865 | return $this; |
| 1093 | 866 | |
| 1094 | 867 | } |
| @@ -1096,104 +869,44 @@ | ||
| 1096 | 869 | return $this; |
| 1097 | 870 | } |
| 1098 | 871 | |
| 1099 | 872 | /** |
| 1100 | - * Register license fields for the products. | |
| 873 | + * Run license activation on plugin activate. | |
| 1101 | 874 | */ |
| 1102 | - public function register_license_hooks() { | |
| 1103 | - add_action( 'admin_init', array( $this, 'register_settings' ) ); | |
| 1104 | - add_action( 'admin_init', array( $this, 'process_license' ) ); | |
| 1105 | - add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 ); | |
| 1106 | - add_action( 'admin_notices', array( $this, 'show_notice' ) ); | |
| 1107 | - add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) ); | |
| 1108 | - add_action( 'wp_ajax_themeisle_sdk_dismiss_license_notice', array( $this, 'dismiss_license_notice' ) ); | |
| 1109 | - } | |
| 1110 | - | |
| 1111 | - /** | |
| 1112 | - * Handle AJAX request to dismiss the license notice. | |
| 1113 | - */ | |
| 1114 | - public function dismiss_license_notice() { | |
| 1115 | - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'themeisle_sdk_dismiss_license_notice' ) ) { | |
| 1116 | - wp_send_json_error( 'Invalid nonce' ); | |
| 875 | + public function auto_activate() { | |
| 876 | + if ( ! current_user_can( 'switch_themes' ) ) { | |
| 877 | + return; | |
| 1117 | 878 | } |
| 1118 | - | |
| 1119 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1120 | - wp_send_json_error( 'Insufficient permissions' ); | |
| 879 | + $status = $this->get_license_status(); | |
| 880 | + if ( 'not_active' !== $status ) { | |
| 881 | + return; | |
| 1121 | 882 | } |
| 1122 | 883 | |
| 1123 | - $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( $_POST['notice_id'] ) : ''; | |
| 1124 | - | |
| 1125 | - if ( empty( $notice_id ) ) { | |
| 1126 | - wp_send_json_error( 'Missing notice ID' ); | |
| 1127 | - } | |
| 1128 | - | |
| 1129 | - // Save the dismissal option. | |
| 1130 | - $dismiss_option_key = $notice_id . '_dismissed'; | |
| 1131 | - update_option( $dismiss_option_key, true ); | |
| 1132 | - | |
| 1133 | - wp_send_json_success(); | |
| 1134 | - } | |
| 1135 | - | |
| 1136 | - /** | |
| 1137 | - * Check license on filesystem. | |
| 1138 | - * | |
| 1139 | - * @return mixed License key. | |
| 1140 | - */ | |
| 1141 | - public function get_file_license() { | |
| 1142 | - | |
| 1143 | 884 | $license_file = dirname( $this->product->get_basefile() ) . '/license.json'; |
| 1144 | 885 | |
| 1145 | 886 | global $wp_filesystem; |
| 1146 | 887 | if ( ! is_file( $license_file ) ) { |
| 1147 | - return false; | |
| 888 | + return; | |
| 1148 | 889 | } |
| 1149 | 890 | |
| 1150 | - require_once ABSPATH . '/wp-admin/includes/file.php'; | |
| 891 | + require_once( ABSPATH . '/wp-admin/includes/file.php' ); | |
| 1151 | 892 | \WP_Filesystem(); |
| 1152 | 893 | $content = json_decode( $wp_filesystem->get_contents( $license_file ) ); |
| 1153 | 894 | if ( ! is_object( $content ) ) { |
| 1154 | - return false; | |
| 895 | + return; | |
| 1155 | 896 | } |
| 1156 | 897 | if ( ! isset( $content->key ) ) { |
| 1157 | - return false; | |
| 1158 | - } | |
| 1159 | - | |
| 1160 | - return $content->key; | |
| 1161 | - } | |
| 1162 | - | |
| 1163 | - /** | |
| 1164 | - * Run license activation on plugin activate. | |
| 1165 | - */ | |
| 1166 | - public function auto_activate() { | |
| 1167 | - $status = $this->get_license_status(); | |
| 1168 | - if ( 'not_active' !== $status ) { | |
| 1169 | - return false; | |
| 1170 | - } | |
| 1171 | - | |
| 1172 | - if ( ! empty( $this->namespace ) ) { | |
| 1173 | - $license_key = apply_filters( 'product_' . $this->namespace . '_license_key_constant', '' ); | |
| 1174 | - } | |
| 1175 | - | |
| 1176 | - if ( empty( $license_key ) ) { | |
| 1177 | - $license_key = $this->get_file_license(); | |
| 1178 | - } | |
| 1179 | - if ( empty( $license_key ) ) { | |
| 1180 | 898 | return; |
| 1181 | 899 | } |
| 1182 | - | |
| 1183 | - | |
| 1184 | - $this->license_local = $license_key; | |
| 900 | + $this->license_local = $content; | |
| 1185 | 901 | $lock_key = $this->product->get_key() . '_autoactivated'; |
| 1186 | 902 | |
| 1187 | 903 | if ( 'yes' === get_option( $lock_key, '' ) ) { |
| 1188 | 904 | return; |
| 1189 | 905 | } |
| 1190 | - if ( 'yes' === get_transient( $lock_key ) ) { | |
| 1191 | - return; | |
| 1192 | - } | |
| 1193 | - $response = $this->do_license_process( $license_key, 'activate' ); | |
| 906 | + $response = $this->do_license_process( $content->key, 'activate' ); | |
| 1194 | 907 | |
| 1195 | - set_transient( $lock_key, 'yes', 6 * HOUR_IN_SECONDS ); | |
| 908 | + update_option( $lock_key, 'yes' ); | |
| 1196 | 909 | |
| 1197 | 910 | if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) { |
| 1198 | 911 | return; |
| 1199 | 912 | } |
| @@ -1208,9 +921,9 @@ | ||
| 1208 | 921 | */ |
| 1209 | 922 | public function autoactivate_notice() { |
| 1210 | 923 | ?> |
| 1211 | 924 | <div class="notice notice-success is-dismissible"> |
| 1212 | - <p><?php echo sprintf( esc_html( Loader::$labels['licenser']['autoactivate_notice'] ), '<strong>' . esc_attr( $this->product->get_name() ) . '</strong>', '<strong>' . esc_attr( str_repeat( '*', 20 ) . substr( $this->license_local, - 10 ) ) . '</strong>' ); ?></p> | |
| 925 | + <p><?php echo sprintf( '<strong>%s</strong> has been successfully activated using <strong>%s</strong> license !', $this->product->get_name(), str_repeat( '*', 20 ) . substr( $this->license_local->key, - 10 ) ); ?></p> | |
| 1213 | 926 | </div> |
| 1214 | 927 | <?php |
| 1215 | 928 | } |
| 1216 | 929 | |
| @@ -1274,6 +987,17 @@ | ||
| 1274 | 987 | return; |
| 1275 | 988 | } |
| 1276 | 989 | |
| 1277 | 990 | \WP_CLI::halt( 1 ); |
| 991 | + } | |
| 992 | + | |
| 993 | + /** | |
| 994 | + * Register license fields for the products. | |
| 995 | + */ | |
| 996 | + public function register_license_hooks() { | |
| 997 | + add_action( 'admin_init', array( $this, 'register_settings' ) ); | |
| 998 | + add_action( 'admin_init', array( $this, 'process_license' ) ); | |
| 999 | + add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 ); | |
| 1000 | + add_action( 'admin_notices', array( $this, 'show_notice' ) ); | |
| 1001 | + add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) ); | |
| 1278 | 1002 | } |
| 1279 | 1003 | } |