PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.5.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.5.0
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 +21 -135 3.10.23.5.0 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 */
@@ -232,78 +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 - * Check if license is valid.
269 - *
270 - * @param string $product_file Product basefile.
271 - *
272 - * @return bool Is valid?
273 - */
274 - public static function is_valid( $product_file ) {
275 - return self::status( $product_file ) === self::STATUS_VALID;
276 - }
277 -
278 - /**
279 - * Get product plan.
280 - *
281 - * @param string $product_file Product file.
282 - *
283 - * @return int Plan id.
284 - */
285 - public static function plan( $product_file ) {
286 - $product = Product::get( $product_file );
287 - $data = self::get_license_data( $product->get_key() );
288 -
289 - return isset( $data->price_id ) ? (int) $data->price_id : - 1;
290 - }
291 -
292 - /**
293 - * Get product license key.
294 - *
295 - * @param string $product_file Product file.
296 - *
297 - * @return string
298 - */
299 - public static function key( $product_file ) {
300 - $product = Product::get( $product_file );
301 -
302 - return $product->get_license();
303 - }
304 -
305 - /**
306 219 * Return the last error message.
307 220 *
308 221 * @return mixed Error message.
309 222 */
@@ -330,9 +243,9 @@
330 243 * @return string Remote api url.
331 244 */
332 245 public function get_distributor_name() {
333 246 if ( $this->is_from_partner( $this->product ) ) {
334 - return 'Themeisle';
247 + return 'ThemeIsle';
335 248 }
336 249
337 250 return $this->product->get_store_name();
338 251 }
@@ -342,9 +255,14 @@
342 255 *
343 256 * @return int License plan.
344 257 */
345 258 public function get_plan() {
346 - 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;
347 265 }
348 266
349 267 /**
350 268 * Show the admin notice regarding the license status.
@@ -362,9 +280,9 @@
362 280
363 281 $status = $this->get_license_status( true );
364 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.' );
365 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>. ' );
366 - $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.' );
284 + $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.' );
367 285 // No activations left for this license.
368 286 if ( 'valid' != $status && $this->check_activation() ) {
369 287 ?>
370 288 <div class="error">
@@ -460,9 +378,9 @@
460 378 if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
461 379 return $this->get_api_url();
462 380 }
463 381
464 - 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;
465 383 }
466 384
467 385 /**
468 386 * Run the license check call.
@@ -494,17 +412,22 @@
494 412 $response = $this->do_license_process( $license, 'check' );
495 413
496 414 if ( is_wp_error( $response ) ) {
497 415 $license_data = new \stdClass();
498 - $license_data->license = 'invalid';
416 + $license_data->license = 'valid';
499 417 } else {
500 418 $license_data = $response;
501 419 }
502 420
503 421 $license_old = get_option( $this->product->get_key() . '_license_data', '' );
504 - if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) && $this->failed_checks <= self::$max_failed ) {
422 +
423 + if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) ) {
505 424 $this->increment_failed_checks();
425 + } else {
426 + $this->reset_failed_checks();
427 + }
506 428
429 + if ( $this->failed_checks <= self::$max_failed ) {
507 430 return $license_old;
508 431 }
509 432
510 433 if ( ! isset( $license_data->key ) ) {
@@ -509,9 +432,8 @@
509 432
510 433 if ( ! isset( $license_data->key ) ) {
511 434 $license_data->key = isset( $license_old->key ) ? $license_old->key : '';
512 435 }
513 - $this->reset_failed_checks();
514 436
515 437 return $license_data;
516 438
517 439 }
@@ -603,12 +525,8 @@
603 525 if ( 'activate' === $action && 'valid' !== $license_data->license ) {
604 526 return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' );
605 527 }
606 528
607 - // Remove the versions transient upon activation so that newer version for rollback can be acquired.
608 - $versions_cache = $this->product->get_cache_key();
609 - delete_transient( $versions_cache );
610 -
611 529 return true;
612 530 }
613 531
614 532 /**
@@ -714,21 +632,12 @@
714 632 * @return mixed
715 633 */
716 634 public function theme_update_transient( $value ) {
717 635 $update_data = $this->check_for_update();
718 - if ( empty( $value ) ) {
719 - return $value;
636 + if ( $update_data ) {
637 + $value->response[ $this->product->get_slug() ] = $update_data;
720 638 }
721 639
722 - if ( ! isset( $value->response ) ) {
723 - return $value;
724 - }
725 -
726 - if ( ! $update_data ) {
727 - return $value;
728 - }
729 -
730 - $value->response[ $this->product->get_slug() ] = $update_data;
731 640 return $value;
732 641 }
733 642
734 643 /**
@@ -829,11 +738,8 @@
829 738 return $_transient_data;
830 739 }
831 740 $api_response = $this->api_request();
832 741 if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
833 - if ( ! isset( $api_response->plugin ) ) {
834 - $api_response->plugin = $this->product->get_slug() . '/' . $this->product->get_file();
835 - }
836 742 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
837 743 $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
838 744 } else {
839 745 $_transient_data->no_update[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
@@ -934,15 +840,9 @@
934 840 if ( $this->product->requires_license() ) {
935 841 $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) );
936 842 $this->register_license_hooks();
937 843 }
938 - if ( ! self::$globals_loaded ) {
939 - add_filter( 'themeisle_sdk_license/status', [ __CLASS__, 'status' ], 999, 1 );
940 - add_filter( 'themeisle_sdk_license/is-valid', [ __CLASS__, 'is_valid' ], 999, 1 );
941 - add_filter( 'themeisle_sdk_license/plan', [ __CLASS__, 'plan' ], 999, 1 );
942 - add_filter( 'themeisle_sdk_license/key', [ __CLASS__, 'key' ], 999, 1 );
943 - $globals_loaded = true;
944 - }
844 +
945 845 $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false );
946 846
947 847 if ( false !== $namespace ) {
948 848 $this->namespace = $namespace;
@@ -967,22 +867,8 @@
967 867 ]
968 868 );
969 869 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
970 870 add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
971 - if ( ! self::is_valid( $product->get_basefile() ) ) {
972 - add_filter(
973 - 'plugin_action_links_' . plugin_basename( $product->get_basefile() ),
974 - function ( $actions ) {
975 - if ( $this->get_license_status( true ) !== self::STATUS_ACTIVE_EXPIRED ) {
976 - return $actions;
977 - }
978 - $new_actions['deactivate'] = $actions['deactivate'];
979 - $new_actions['renew_link'] = '<a style="color:#d63638" href="' . esc_url( $this->renew_url() ) . '" target="_blank" rel="external noopener noreferrer">Renew license to update</a>';
980 -
981 - return $new_actions;
982 - }
983 - );
984 - }
985 871
986 872 return $this;
987 873 }
988 874 if ( $this->product->is_theme() ) {