PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php +38 -187 3.10.133.7.2 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']['deactivateactivate'] );
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_string', sprintf( Loader::$labels['licenser']['expired'], '%s', '<a href="%s" target="_blank">', '</a>' ) );
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">
@@ -477,9 +378,9 @@
477 378 if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
478 379 return $this->get_api_url();
479 380 }
480 381
481 - 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;
482 383 }
483 384
484 385 /**
485 386 * Run the license check call.
@@ -542,17 +443,17 @@
542 443 * @return bool|\WP_Error
543 444 */
544 445 public function do_license_process( $license, $action = 'toggle' ) {
545 446 if ( strlen( $license ) < 10 ) {
546 - return new \WP_Error( 'themeisle-license-invalid-format', Loader::$labels['licenser']['invalid_msg'] );
447 + return new \WP_Error( 'themeisle-license-invalid-format', 'Invalid license.' );
547 448 }
548 449 $status = $this->get_license_status();
549 450
550 451 if ( 'valid' === $status && 'activate' === $action ) {
551 - 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.' );
552 453 }
553 454 if ( 'valid' !== $status && 'deactivate' === $action ) {
554 - 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.' );
555 456 }
556 457
557 458 if ( 'toggle' === $action ) {
558 459 $action = ( 'valid' !== $status ? ( 'activate' ) : ( 'deactivate' ) );
@@ -578,15 +479,15 @@
578 479 }
579 480
580 481 // make sure the response came back okay.
581 482 if ( is_wp_error( $response ) ) {
582 - 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() ) );
583 484 }
584 485
585 486 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
586 487
587 488 if ( ! is_object( $license_data ) ) {
588 - 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.' );
589 490 }
590 491 if ( 'check' === $action ) {
591 492 return $license_data;
592 493 }
@@ -617,15 +518,11 @@
617 518 }
618 519 update_option( $this->product->get_key() . '_license_data', $license_data );
619 520 set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
620 521 if ( 'activate' === $action && 'valid' !== $license_data->license ) {
621 - return new \WP_Error( 'themeisle-license-invalid', Loader::$labels['licenser']['error_invalid'] );
522 + return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' );
622 523 }
623 524
624 - // Remove the versions transient upon activation so that newer version for rollback can be acquired.
625 - $versions_cache = $this->product->get_cache_key();
626 - delete_transient( $versions_cache );
627 -
628 525 return true;
629 526 }
630 527
631 528 /**
@@ -652,9 +549,9 @@
652 549 if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
653 550 return;
654 551 }
655 552 if ( ! isset( $_POST[ $this->product->get_key() . 'nonce_field' ] )
656 - || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
553 + || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
657 554 ) {
658 555 return;
659 556 }
660 557 if ( ! current_user_can( 'manage_options' ) ) {
@@ -702,18 +599,20 @@
702 599 if ( false === $api_response || ! isset( $api_response->new_version ) ) {
703 600 return;
704 601 }
705 602 $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() );
706 - $update_message = apply_filters( 'themeisle_sdk_license_update_message', Loader::$labels['licenser']['update_license'] );
603 + $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.' );
707 604 $update_onclick = ' onclick="if ( confirm(\'' . esc_js( $update_message ) . '\') ) {return true;}return false;"';
708 605 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
709 606 echo '<div id="update-nag">';
710 607 printf(
711 - esc_html( Loader::$labels['licenser']['notice_update'] ),
712 - '<strong>' . esc_attr( $theme->get( 'Name' ) ) . ' ' . esc_attr( $api_response->new_version ) . '</strong>',
713 - '<a href="' . esc_url( sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ) ) . '" class="thickbox" title="' . esc_attr( $theme->get( 'Name' ) ) . '">',
714 - '</a>',
715 - '<a href="' . esc_url( $update_url ) . '" ' . $update_onclick . '>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped.
608 + '<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>.',
609 + esc_attr( $theme->get( 'Name' ) ),
610 + esc_attr( $api_response->new_version ),
611 + esc_url( sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ) ),
612 + esc_attr( $theme->get( 'Name' ) ),
613 + esc_url( $update_url ),
614 + $update_onclick // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped.
716 615 );
717 616 echo '</div>';
718 617 echo '<div id="' . esc_attr( $this->product->get_slug() ) . '_changelog" style="display:none;">';
719 618 echo wp_kses_data( wpautop( $api_response->sections['changelog'] ) );
@@ -729,22 +628,12 @@
729 628 * @return mixed
730 629 */
731 630 public function theme_update_transient( $value ) {
732 631 $update_data = $this->check_for_update();
733 - if ( empty( $value ) ) {
734 - return $value;
632 + if ( $update_data ) {
633 + $value->response[ $this->product->get_slug() ] = $update_data;
735 634 }
736 635
737 - if ( ! isset( $value->response ) ) {
738 - return $value;
739 - }
740 -
741 - if ( ! $update_data ) {
742 - return $value;
743 - }
744 -
745 - $value->response[ $this->product->get_slug() ] = $update_data;
746 -
747 636 return $value;
748 637 }
749 638
750 639 /**
@@ -950,15 +839,9 @@
950 839 if ( $this->product->requires_license() ) {
951 840 $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) );
952 841 $this->register_license_hooks();
953 842 }
954 - if ( ! self::$globals_loaded ) {
955 - add_filter( 'themeisle_sdk_license/status', [ __CLASS__, 'status' ], 999, 1 );
956 - add_filter( 'themeisle_sdk_license/is-valid', [ __CLASS__, 'is_valid' ], 999, 1 );
957 - add_filter( 'themeisle_sdk_license/plan', [ __CLASS__, 'plan' ], 999, 1 );
958 - add_filter( 'themeisle_sdk_license/key', [ __CLASS__, 'key' ], 999, 1 );
959 - $globals_loaded = true;
960 - }
843 +
961 844 $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false );
962 845
963 846 if ( false !== $namespace ) {
964 847 $this->namespace = $namespace;
@@ -982,32 +865,10 @@
982 865 'pre_set_site_transient_update_plugins_filter',
983 866 ]
984 867 );
985 868 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,
990 - '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;
1001 - }
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>';
869 + add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
1004 870
1005 - return $new_actions;
1006 - }
1007 - );
1008 - }
1009 -
1010 871 return $this;
1011 872 }
1012 873 if ( $this->product->is_theme() ) {
1013 874 add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) );
@@ -1014,17 +875,9 @@
1014 875 add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
1015 876 add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) );
1016 877 add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) );
1017 878 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 - );
879 + add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
1027 880
1028 881 return $this;
1029 882
1030 883 }
@@ -1065,12 +918,10 @@
1065 918 }
1066 919 if ( ! isset( $content->key ) ) {
1067 920 return false;
1068 921 }
1069 -
1070 922 return $content->key;
1071 923 }
1072 -
1073 924 /**
1074 925 * Run license activation on plugin activate.
1075 926 */
1076 927 public function auto_activate() {
@@ -1118,9 +969,9 @@
1118 969 */
1119 970 public function autoactivate_notice() {
1120 971 ?>
1121 972 <div class="notice notice-success is-dismissible">
1122 - <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>
973 + <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>
1123 974 </div>
1124 975 <?php
1125 976 }
1126 977