← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php
+145
-51
3.10.15
→
4.0.9
View file →
| @@ -138,9 +138,9 @@ | ||
| 138 | 138 | $status = $this->get_license_status(); |
| 139 | 139 | $value = $this->license_key; |
| 140 | 140 | |
| 141 | 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']['deactivateactivate'] ); | |
| 142 | + $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', Loader::$labels['licenser']['deactivate'] ); | |
| 143 | 143 | $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', Loader::$labels['licenser']['valid'] ); |
| 144 | 144 | $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', Loader::$labels['licenser']['invalid'] ); |
| 145 | 145 | $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', Loader::$labels['licenser']['notice'] ); |
| 146 | 146 | $error_message = $this->get_error(); |
| @@ -379,9 +379,9 @@ | ||
| 379 | 379 | |
| 380 | 380 | $status = $this->get_license_status( true ); |
| 381 | 381 | $no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', Loader::$labels['licenser']['no_activations'] ); |
| 382 | 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_string', sprintf( Loader::$labels['licenser']['expired'], '%s', '<a href="%s" target="_blank">', '</a>' ) ); | |
| 383 | + $expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_heading_string', Loader::$labels['licenser']['expired'] ); | |
| 384 | 384 | // No activations left for this license. |
| 385 | 385 | if ( 'valid' != $status && $this->check_activation() ) { |
| 386 | 386 | ?> |
| 387 | 387 | <div class="error"> |
| @@ -402,14 +402,74 @@ | ||
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | // Invalid license key. |
| 405 | 405 | 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'; | |
| 406 | 438 | ?> |
| 407 | - <div class="error"> | |
| 408 | - <p> | |
| 409 | - <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> | |
| 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 ); ?> | |
| 410 | 443 | </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> | |
| 411 | 455 | </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> | |
| 412 | 472 | <?php |
| 413 | 473 | |
| 414 | 474 | return false; |
| 415 | 475 | } |
| @@ -843,17 +903,21 @@ | ||
| 843 | 903 | $this->do_check = true; |
| 844 | 904 | |
| 845 | 905 | return $_transient_data; |
| 846 | 906 | } |
| 907 | + $this->product->setup_from_fileheaders(); | |
| 847 | 908 | $api_response = $this->api_request(); |
| 848 | 909 | if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) { |
| 910 | + $plugin = $this->product->get_slug() . '/' . $this->product->get_file(); | |
| 849 | 911 | if ( ! isset( $api_response->plugin ) ) { |
| 850 | - $api_response->plugin = $this->product->get_slug() . '/' . $this->product->get_file(); | |
| 912 | + $api_response->plugin = $plugin; | |
| 851 | 913 | } |
| 852 | 914 | if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) { |
| 853 | - $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response; | |
| 915 | + $_transient_data->response[ $plugin ] = $api_response; | |
| 916 | + unset( $_transient_data->no_update[ $plugin ] ); | |
| 854 | 917 | } else { |
| 855 | - $_transient_data->no_update[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response; | |
| 918 | + $_transient_data->no_update[ $plugin ] = $api_response; | |
| 919 | + unset( $_transient_data->response[ $plugin ] ); | |
| 856 | 920 | } |
| 857 | 921 | } |
| 858 | 922 | |
| 859 | 923 | return $_transient_data; |
| @@ -925,9 +989,9 @@ | ||
| 925 | 989 | * @return bool Should we load the module? |
| 926 | 990 | */ |
| 927 | 991 | public function can_load( $product ) { |
| 928 | 992 | |
| 929 | - if ( $product->is_wordpress_available() ) { | |
| 993 | + if ( ! $product->requires_license() ) { | |
| 930 | 994 | return false; |
| 931 | 995 | } |
| 932 | 996 | |
| 933 | 997 | return ( apply_filters( $product->get_key() . '_enable_licenser', true ) === true ); |
| @@ -974,57 +1038,61 @@ | ||
| 974 | 1038 | } |
| 975 | 1039 | |
| 976 | 1040 | add_action( 'admin_head', [ $this, 'auto_activate' ] ); |
| 977 | 1041 | if ( $this->product->is_plugin() ) { |
| 978 | - add_filter( | |
| 979 | - 'pre_set_site_transient_update_plugins', | |
| 980 | - [ | |
| 981 | - $this, | |
| 982 | - 'pre_set_site_transient_update_plugins_filter', | |
| 983 | - ] | |
| 984 | - ); | |
| 985 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); | |
| 986 | - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 987 | - 'http_request_args', | |
| 988 | - array( | |
| 989 | - $this, | |
| 1042 | + if ( ! $product->is_wordpress_available() ) { | |
| 1043 | + add_filter( | |
| 1044 | + 'pre_set_site_transient_update_plugins', | |
| 1045 | + [ | |
| 1046 | + $this, | |
| 1047 | + 'pre_set_site_transient_update_plugins_filter', | |
| 1048 | + ] | |
| 1049 | + ); | |
| 1050 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); | |
| 1051 | + add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 990 | 1052 | 'http_request_args', |
| 991 | - ), | |
| 992 | - 10, | |
| 993 | - 2 | |
| 994 | - ); | |
| 995 | - if ( ! self::is_valid( $product->get_basefile() ) ) { | |
| 996 | - add_filter( | |
| 997 | - 'plugin_action_links_' . plugin_basename( $product->get_basefile() ), | |
| 998 | - function ( $actions ) { | |
| 999 | - if ( $this->get_license_status( true ) !== self::STATUS_ACTIVE_EXPIRED ) { | |
| 1000 | - return $actions; | |
| 1053 | + array( | |
| 1054 | + $this, | |
| 1055 | + 'http_request_args', | |
| 1056 | + ), | |
| 1057 | + 10, | |
| 1058 | + 2 | |
| 1059 | + ); | |
| 1060 | + if ( ! self::is_valid( $product->get_basefile() ) ) { | |
| 1061 | + add_filter( | |
| 1062 | + 'plugin_action_links_' . plugin_basename( $product->get_basefile() ), | |
| 1063 | + function ( $actions ) { | |
| 1064 | + if ( $this->get_license_status( true ) !== self::STATUS_ACTIVE_EXPIRED ) { | |
| 1065 | + return $actions; | |
| 1066 | + } | |
| 1067 | + $new_actions['deactivate'] = $actions['deactivate']; | |
| 1068 | + $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>'; | |
| 1069 | + | |
| 1070 | + return $new_actions; | |
| 1001 | 1071 | } |
| 1002 | - $new_actions['deactivate'] = $actions['deactivate']; | |
| 1003 | - $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>'; | |
| 1004 | - | |
| 1005 | - return $new_actions; | |
| 1006 | - } | |
| 1007 | - ); | |
| 1072 | + ); | |
| 1073 | + } | |
| 1008 | 1074 | } |
| 1009 | 1075 | |
| 1010 | 1076 | return $this; |
| 1011 | 1077 | } |
| 1012 | 1078 | if ( $this->product->is_theme() ) { |
| 1013 | - add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) ); | |
| 1014 | - add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1015 | - add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1016 | - add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1017 | - add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) ); | |
| 1018 | - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1019 | - 'http_request_args', | |
| 1020 | - array( | |
| 1021 | - $this, | |
| 1022 | - 'disable_wporg_update', | |
| 1023 | - ), | |
| 1024 | - 5, | |
| 1025 | - 2 | |
| 1026 | - ); | |
| 1079 | + if ( ! $product->is_wordpress_available() ) { | |
| 1080 | + add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) ); | |
| 1081 | + add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1082 | + add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1083 | + add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) ); | |
| 1084 | + add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) ); | |
| 1085 | + add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args | |
| 1086 | + 'http_request_args', | |
| 1087 | + array( | |
| 1088 | + $this, | |
| 1089 | + 'disable_wporg_update', | |
| 1090 | + ), | |
| 1091 | + 5, | |
| 1092 | + 2 | |
| 1093 | + ); | |
| 1094 | + } | |
| 1027 | 1095 | |
| 1028 | 1096 | return $this; |
| 1029 | 1097 | |
| 1030 | 1098 | } |
| @@ -1040,8 +1108,34 @@ | ||
| 1040 | 1108 | add_action( 'admin_init', array( $this, 'process_license' ) ); |
| 1041 | 1109 | add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 ); |
| 1042 | 1110 | add_action( 'admin_notices', array( $this, 'show_notice' ) ); |
| 1043 | 1111 | add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) ); |
| 1112 | + add_action( 'wp_ajax_themeisle_sdk_dismiss_license_notice', array( $this, 'dismiss_license_notice' ) ); | |
| 1113 | + } | |
| 1114 | + | |
| 1115 | + /** | |
| 1116 | + * Handle AJAX request to dismiss the license notice. | |
| 1117 | + */ | |
| 1118 | + public function dismiss_license_notice() { | |
| 1119 | + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'themeisle_sdk_dismiss_license_notice' ) ) { | |
| 1120 | + wp_send_json_error( 'Invalid nonce' ); | |
| 1121 | + } | |
| 1122 | + | |
| 1123 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1124 | + wp_send_json_error( 'Insufficient permissions' ); | |
| 1125 | + } | |
| 1126 | + | |
| 1127 | + $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( $_POST['notice_id'] ) : ''; | |
| 1128 | + | |
| 1129 | + if ( empty( $notice_id ) ) { | |
| 1130 | + wp_send_json_error( 'Missing notice ID' ); | |
| 1131 | + } | |
| 1132 | + | |
| 1133 | + // Save the dismissal option. | |
| 1134 | + $dismiss_option_key = $notice_id . '_dismissed'; | |
| 1135 | + update_option( $dismiss_option_key, true ); | |
| 1136 | + | |
| 1137 | + wp_send_json_success(); | |
| 1044 | 1138 | } |
| 1045 | 1139 | |
| 1046 | 1140 | /** |
| 1047 | 1141 | * Check license on filesystem. |