← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php
+53
-279
4.0.4
→
3.7.12
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 = 2; | |
| 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 | */ |
| @@ -137,13 +120,13 @@ | ||
| 137 | 120 | public function license_view() { |
| 138 | 121 | $status = $this->get_license_status(); |
| 139 | 122 | $value = $this->license_key; |
| 140 | 123 | |
| 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'] ); | |
| 124 | + $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' ); | |
| 125 | + $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' ); | |
| 126 | + $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' ); | |
| 127 | + $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' ); | |
| 128 | + $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 | 129 | $error_message = $this->get_error(); |
| 147 | 130 | ?> |
| 148 | 131 | <style type="text/css"> |
| 149 | 132 | input.themeisle-sdk-text-input-valid { |
| @@ -232,95 +215,8 @@ | ||
| 232 | 215 | return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status; |
| 233 | 216 | } |
| 234 | 217 | |
| 235 | 218 | /** |
| 236 | - * Check status. | |
| 237 | - * | |
| 238 | - * @param string $product_file Product basefile. | |
| 239 | - * | |
| 240 | - * @return string Status license. | |
| 241 | - */ | |
| 242 | - public static function status( $product_file ) { | |
| 243 | - $product = Product::get( $product_file ); | |
| 244 | - if ( ! $product->requires_license() ) { | |
| 245 | - return self::STATUS_VALID; | |
| 246 | - } | |
| 247 | - $license_data = self::get_license_data( $product->get_key() ); | |
| 248 | - | |
| 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; | |
| 252 | - } | |
| 253 | - | |
| 254 | - /** | |
| 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 | 219 | * Return the last error message. |
| 324 | 220 | * |
| 325 | 221 | * @return mixed Error message. |
| 326 | 222 | */ |
| @@ -359,9 +255,14 @@ | ||
| 359 | 255 | * |
| 360 | 256 | * @return int License plan. |
| 361 | 257 | */ |
| 362 | 258 | public function get_plan() { |
| 363 | - return self::plan( $this->product->get_basefile() ); | |
| 259 | + $license_data = get_option( $this->product->get_key() . '_license_data', '' ); | |
| 260 | + if ( ! isset( $license_data->price_id ) ) { | |
| 261 | + return - 1; | |
| 262 | + } | |
| 263 | + | |
| 264 | + return (int) $license_data->price_id; | |
| 364 | 265 | } |
| 365 | 266 | |
| 366 | 267 | /** |
| 367 | 268 | * Show the admin notice regarding the license status. |
| @@ -377,11 +278,11 @@ | ||
| 377 | 278 | return false; |
| 378 | 279 | } |
| 379 | 280 | |
| 380 | 281 | $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'] ); | |
| 282 | + $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.' ); | |
| 283 | + $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>. ' ); | |
| 284 | + $expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_string', 'Your %s\'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 | 285 | // No activations left for this license. |
| 385 | 286 | if ( 'valid' != $status && $this->check_activation() ) { |
| 386 | 287 | ?> |
| 387 | 288 | <div class="error"> |
| @@ -402,74 +303,14 @@ | ||
| 402 | 303 | } |
| 403 | 304 | |
| 404 | 305 | // Invalid license key. |
| 405 | 306 | 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 | 307 | ?> |
| 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 ); ?> | |
| 308 | + <div class="error"> | |
| 309 | + <p> | |
| 310 | + <strong><?php echo sprintf( wp_kses_data( $expired_license_string ), esc_attr( $this->product->get_name() . ' ' . $this->product->get_type() ), esc_url( $this->get_api_url() . '?license=' . $this->license_key ) ); ?> </strong> | |
| 443 | 311 | </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 | 312 | </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 | 313 | <?php |
| 473 | 314 | |
| 474 | 315 | return false; |
| 475 | 316 | } |
| @@ -537,9 +378,9 @@ | ||
| 537 | 378 | if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) { |
| 538 | 379 | return $this->get_api_url(); |
| 539 | 380 | } |
| 540 | 381 | |
| 541 | - return trim( $this->get_api_url(), '/' ) . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id; | |
| 382 | + return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id; | |
| 542 | 383 | } |
| 543 | 384 | |
| 544 | 385 | /** |
| 545 | 386 | * Run the license check call. |
| @@ -602,17 +443,17 @@ | ||
| 602 | 443 | * @return bool|\WP_Error |
| 603 | 444 | */ |
| 604 | 445 | public function do_license_process( $license, $action = 'toggle' ) { |
| 605 | 446 | if ( strlen( $license ) < 10 ) { |
| 606 | - return new \WP_Error( 'themeisle-license-invalid-format', Loader::$labels['licenser']['invalid_msg'] ); | |
| 447 | + return new \WP_Error( 'themeisle-license-invalid-format', 'Invalid license.' ); | |
| 607 | 448 | } |
| 608 | 449 | $status = $this->get_license_status(); |
| 609 | 450 | |
| 610 | 451 | if ( 'valid' === $status && 'activate' === $action ) { |
| 611 | - return new \WP_Error( 'themeisle-license-already-active', Loader::$labels['licenser']['already_active'] ); | |
| 452 | + return new \WP_Error( 'themeisle-license-already-active', 'License is already active.' ); | |
| 612 | 453 | } |
| 613 | 454 | if ( 'valid' !== $status && 'deactivate' === $action ) { |
| 614 | - return new \WP_Error( 'themeisle-license-already-deactivate', Loader::$labels['licenser']['not_active'] ); | |
| 455 | + return new \WP_Error( 'themeisle-license-already-deactivate', 'License not active.' ); | |
| 615 | 456 | } |
| 616 | 457 | |
| 617 | 458 | if ( 'toggle' === $action ) { |
| 618 | 459 | $action = ( 'valid' !== $status ? ( 'activate' ) : ( 'deactivate' ) ); |
| @@ -638,15 +479,15 @@ | ||
| 638 | 479 | } |
| 639 | 480 | |
| 640 | 481 | // make sure the response came back okay. |
| 641 | 482 | if ( is_wp_error( $response ) ) { |
| 642 | - return new \WP_Error( 'themeisle-license-500', sprintf( Loader::$labels['licenser']['error_notice'], $response->get_error_message() ) ); | |
| 483 | + 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 | 484 | } |
| 644 | 485 | |
| 645 | 486 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 646 | 487 | |
| 647 | 488 | if ( ! is_object( $license_data ) ) { |
| 648 | - return new \WP_Error( 'themeisle-license-404', Loader::$labels['licenser']['error_notice2'] ); | |
| 489 | + return new \WP_Error( 'themeisle-license-404', 'ERROR: Failed to validate license. Please try again in one minute.' ); | |
| 649 | 490 | } |
| 650 | 491 | if ( 'check' === $action ) { |
| 651 | 492 | return $license_data; |
| 652 | 493 | } |
| @@ -677,9 +518,9 @@ | ||
| 677 | 518 | } |
| 678 | 519 | update_option( $this->product->get_key() . '_license_data', $license_data ); |
| 679 | 520 | set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS ); |
| 680 | 521 | if ( 'activate' === $action && 'valid' !== $license_data->license ) { |
| 681 | - return new \WP_Error( 'themeisle-license-invalid', Loader::$labels['licenser']['error_invalid'] ); | |
| 522 | + return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' ); | |
| 682 | 523 | } |
| 683 | 524 | |
| 684 | 525 | // Remove the versions transient upon activation so that newer version for rollback can be acquired. |
| 685 | 526 | $versions_cache = $this->product->get_cache_key(); |
| @@ -712,9 +553,9 @@ | ||
| 712 | 553 | if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) { |
| 713 | 554 | return; |
| 714 | 555 | } |
| 715 | 556 | 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 | |
| 557 | + || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 717 | 558 | ) { |
| 718 | 559 | return; |
| 719 | 560 | } |
| 720 | 561 | if ( ! current_user_can( 'manage_options' ) ) { |
| @@ -762,18 +603,20 @@ | ||
| 762 | 603 | if ( false === $api_response || ! isset( $api_response->new_version ) ) { |
| 763 | 604 | return; |
| 764 | 605 | } |
| 765 | 606 | $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'] ); | |
| 607 | + $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 | 608 | $update_onclick = ' onclick="if ( confirm(\'' . esc_js( $update_message ) . '\') ) {return true;}return false;"'; |
| 768 | 609 | if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) { |
| 769 | 610 | echo '<div id="update-nag">'; |
| 770 | 611 | 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. | |
| 612 | + '<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>.', | |
| 613 | + esc_attr( $theme->get( 'Name' ) ), | |
| 614 | + esc_attr( $api_response->new_version ), | |
| 615 | + esc_url( sprintf( '%s&TB_iframe=true&width=1024&height=800', $this->product->get_changelog() ) ), | |
| 616 | + esc_attr( $theme->get( 'Name' ) ), | |
| 617 | + esc_url( $update_url ), | |
| 618 | + $update_onclick // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped. | |
| 776 | 619 | ); |
| 777 | 620 | echo '</div>'; |
| 778 | 621 | echo '<div id="' . esc_attr( $this->product->get_slug() ) . '_changelog" style="display:none;">'; |
| 779 | 622 | echo wp_kses_data( wpautop( $api_response->sections['changelog'] ) ); |
| @@ -802,9 +645,8 @@ | ||
| 802 | 645 | return $value; |
| 803 | 646 | } |
| 804 | 647 | |
| 805 | 648 | $value->response[ $this->product->get_slug() ] = $update_data; |
| 806 | - | |
| 807 | 649 | return $value; |
| 808 | 650 | } |
| 809 | 651 | |
| 810 | 652 | /** |
| @@ -985,9 +827,9 @@ | ||
| 985 | 827 | * @return bool Should we load the module? |
| 986 | 828 | */ |
| 987 | 829 | public function can_load( $product ) { |
| 988 | 830 | |
| 989 | - if ( ! $product->requires_license() ) { | |
| 831 | + if ( $product->is_wordpress_available() ) { | |
| 990 | 832 | return false; |
| 991 | 833 | } |
| 992 | 834 | |
| 993 | 835 | return ( apply_filters( $product->get_key() . '_enable_licenser', true ) === true ); |
| @@ -1010,15 +852,9 @@ | ||
| 1010 | 852 | if ( $this->product->requires_license() ) { |
| 1011 | 853 | $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) ); |
| 1012 | 854 | $this->register_license_hooks(); |
| 1013 | 855 | } |
| 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 | - } | |
| 856 | + | |
| 1021 | 857 | $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false ); |
| 1022 | 858 | |
| 1023 | 859 | if ( false !== $namespace ) { |
| 1024 | 860 | $this->namespace = $namespace; |
| @@ -1034,61 +870,27 @@ | ||
| 1034 | 870 | } |
| 1035 | 871 | |
| 1036 | 872 | add_action( 'admin_head', [ $this, 'auto_activate' ] ); |
| 1037 | 873 | 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>'; | |
| 874 | + add_filter( | |
| 875 | + 'pre_set_site_transient_update_plugins', | |
| 876 | + [ | |
| 877 | + $this, | |
| 878 | + 'pre_set_site_transient_update_plugins_filter', | |
| 879 | + ] | |
| 880 | + ); | |
| 881 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); | |
| 882 | + add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1065 | 883 | |
| 1066 | - return $new_actions; | |
| 1067 | - } | |
| 1068 | - ); | |
| 1069 | - } | |
| 1070 | - } | |
| 1071 | - | |
| 1072 | 884 | return $this; |
| 1073 | 885 | } |
| 1074 | 886 | 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 | - } | |
| 887 | + add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) ); | |
| 888 | + add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) ); | |
| 889 | + add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 890 | + add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 891 | + add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) ); | |
| 892 | + add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1091 | 893 | |
| 1092 | 894 | return $this; |
| 1093 | 895 | |
| 1094 | 896 | } |
| @@ -1104,37 +906,11 @@ | ||
| 1104 | 906 | add_action( 'admin_init', array( $this, 'process_license' ) ); |
| 1105 | 907 | add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 ); |
| 1106 | 908 | add_action( 'admin_notices', array( $this, 'show_notice' ) ); |
| 1107 | 909 | 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 | 910 | } |
| 1110 | 911 | |
| 1111 | 912 | /** |
| 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' ); | |
| 1117 | - } | |
| 1118 | - | |
| 1119 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1120 | - wp_send_json_error( 'Insufficient permissions' ); | |
| 1121 | - } | |
| 1122 | - | |
| 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 | 913 | * Check license on filesystem. |
| 1138 | 914 | * |
| 1139 | 915 | * @return mixed License key. |
| 1140 | 916 | */ |
| @@ -1155,12 +931,10 @@ | ||
| 1155 | 931 | } |
| 1156 | 932 | if ( ! isset( $content->key ) ) { |
| 1157 | 933 | return false; |
| 1158 | 934 | } |
| 1159 | - | |
| 1160 | 935 | return $content->key; |
| 1161 | 936 | } |
| 1162 | - | |
| 1163 | 937 | /** |
| 1164 | 938 | * Run license activation on plugin activate. |
| 1165 | 939 | */ |
| 1166 | 940 | public function auto_activate() { |
| @@ -1208,9 +982,9 @@ | ||
| 1208 | 982 | */ |
| 1209 | 983 | public function autoactivate_notice() { |
| 1210 | 984 | ?> |
| 1211 | 985 | <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> | |
| 986 | + <p><?php echo sprintf( '<strong>%s</strong> has been successfully activated using <strong>%s</strong> license !', esc_attr( $this->product->get_name() ), esc_attr( str_repeat( '*', 20 ) . substr( $this->license_local, - 10 ) ) ); ?></p> | |
| 1213 | 987 | </div> |
| 1214 | 988 | <?php |
| 1215 | 989 | } |
| 1216 | 990 | |