PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.9
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.9
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 +132 -284 3.10.43.4.9 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
@@ -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>&nbsp;&nbsp;&nbsp;<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,87 +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 - * 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 - * Return the last error message.
307 - *
308 - * @return mixed Error message.
309 - */
310 - public function get_error() {
311 - return get_transient( $this->product->get_key() . 'act_err' );
312 - }
313 -
314 - /**
315 227 * Get remote api url.
316 228 *
317 229 * @return string Remote api url.
318 230 */
@@ -330,9 +242,9 @@
330 242 * @return string Remote api url.
331 243 */
332 244 public function get_distributor_name() {
333 245 if ( $this->is_from_partner( $this->product ) ) {
334 - return 'Themeisle';
246 + return 'ThemeIsle';
335 247 }
336 248
337 249 return $this->product->get_store_name();
338 250 }
@@ -337,22 +249,13 @@
337 249 return $this->product->get_store_name();
338 250 }
339 251
340 252 /**
341 - * License price id.
342 - *
343 - * @return int License plan.
344 - */
345 - public function get_plan() {
346 - return self::plan( $this->product->get_basefile() );
347 - }
348 -
349 - /**
350 253 * Show the admin notice regarding the license status.
351 254 *
352 255 * @return bool Should we show the notice ?
353 256 */
354 - public function show_notice() {
257 + function show_notice() {
355 258 if ( ! is_admin() ) {
356 259 return false;
357 260 }
358 261
@@ -362,9 +265,9 @@
362 265
363 266 $status = $this->get_license_status( true );
364 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.' );
365 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>. ' );
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.' );
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.' );
367 270 // No activations left for this license.
368 271 if ( 'valid' != $status && $this->check_activation() ) {
369 272 ?>
370 273 <div class="error">
@@ -370,12 +273,12 @@
370 273 <div class="error">
371 274 <p><strong>
372 275 <?php
373 276 echo sprintf(
374 - wp_kses_data( $no_activations_string ),
375 - esc_attr( $this->product->get_name() ),
376 - esc_attr( $this->product->get_name() ),
377 - '<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>'
378 281 );
379 282 ?>
380 283 </strong>
381 284 </p>
@@ -388,9 +291,9 @@
388 291 if ( 'active_expired' === $status ) {
389 292 ?>
390 293 <div class="error">
391 294 <p>
392 - <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>
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>
393 296 </p>
394 297 </div>
395 298 <?php
396 299
@@ -400,9 +303,9 @@
400 303 if ( 'valid' != $status ) {
401 304 ?>
402 305 <div class="error">
403 306 <p>
404 - <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>
405 308 </p>
406 309 </div>
407 310 <?php
408 311
@@ -431,9 +334,9 @@
431 334 * Check if the license is about to expire in the next month.
432 335 *
433 336 * @return bool
434 337 */
435 - public function check_expiration() {
338 + function check_expiration() {
436 339 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
437 340 if ( '' === $license_data ) {
438 341 return false;
439 342 }
@@ -451,9 +354,9 @@
451 354 * Return the renew url from the store used.
452 355 *
453 356 * @return string The renew url.
454 357 */
455 - public function renew_url() {
358 + function renew_url() {
456 359 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
457 360 if ( '' === $license_data ) {
458 361 return $this->get_api_url();
459 362 }
@@ -460,9 +363,9 @@
460 363 if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
461 364 return $this->get_api_url();
462 365 }
463 366
464 - 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;
465 368 }
466 369
467 370 /**
468 371 * Run the license check call.
@@ -467,9 +370,9 @@
467 370 /**
468 371 * Run the license check call.
469 372 */
470 373 public function product_valid() {
471 - 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' ) ) ) {
472 375 return;
473 376 }
474 377 $license = $this->check_license();
475 378 set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS );
@@ -494,17 +397,22 @@
494 397 $response = $this->do_license_process( $license, 'check' );
495 398
496 399 if ( is_wp_error( $response ) ) {
497 400 $license_data = new \stdClass();
498 - $license_data->license = 'invalid';
401 + $license_data->license = 'valid';
499 402 } else {
500 403 $license_data = $response;
501 404 }
502 405
503 406 $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 ) {
407 +
408 + if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) ) {
505 409 $this->increment_failed_checks();
410 + } else {
411 + $this->reset_failed_checks();
412 + }
506 413
414 + if ( $this->failed_checks <= self::$max_failed ) {
507 415 return $license_old;
508 416 }
509 417
510 418 if ( ! isset( $license_data->key ) ) {
@@ -509,9 +417,8 @@
509 417
510 418 if ( ! isset( $license_data->key ) ) {
511 419 $license_data->key = isset( $license_old->key ) ? $license_old->key : '';
512 420 }
513 - $this->reset_failed_checks();
514 421
515 422 return $license_data;
516 423
517 424 }
@@ -516,8 +423,44 @@
516 423
517 424 }
518 425
519 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 + /**
520 463 * Do license activation/deactivation.
521 464 *
522 465 * @param string $license License key.
523 466 * @param string $action What do to.
@@ -542,9 +485,9 @@
542 485 }
543 486
544 487 // Call the custom API.
545 488 if ( 'check' === $action ) {
546 - $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() ) );
547 490 } else {
548 491 $response = wp_remote_post(
549 492 sprintf( '%slicense/%s/%s/%s', Product::API_URL, $action, rawurlencode( $this->product->get_name() ), $license ),
550 493 array(
@@ -603,51 +546,20 @@
603 546 if ( 'activate' === $action && 'valid' !== $license_data->license ) {
604 547 return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' );
605 548 }
606 549
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 550 return true;
612 551 }
613 552
614 553 /**
615 - * Reset the failed checks
616 - */
617 - private function reset_failed_checks() {
618 - $this->failed_checks = 1;
619 - update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
620 - }
621 -
622 - /**
623 - * Increment the failed checks.
624 - */
625 - private function increment_failed_checks() {
626 - $this->failed_checks ++;
627 - update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
628 - }
629 -
630 - /**
631 554 * Activate the license remotely.
632 555 */
633 - public function process_license() {
556 + function process_license() {
634 557 // listen for our activate button to be clicked.
635 558 if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
636 559 return;
637 560 }
638 - if ( ! isset( $_POST[ $this->product->get_key() . 'nonce_field' ] )
639 - || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
640 - ) {
641 - return;
642 - }
643 - if ( ! current_user_can( 'manage_options' ) ) {
644 - return;
645 - }
646 - $license = isset( $_POST[ $this->product->get_key() . '_license' ] )
647 - ? sanitize_text_field( $_POST[ $this->product->get_key() . '_license' ] )
648 - : '';
649 -
561 + $license = $_POST[ $this->product->get_key() . '_license' ];
650 562 $response = $this->do_license_process( $license, 'toggle' );
651 563 if ( is_wp_error( $response ) ) {
652 564 $this->set_error( $response->get_error_message() );
653 565
@@ -655,24 +567,16 @@
655 567 }
656 568 if ( true === $response ) {
657 569 $this->set_error( '' );
658 570 }
659 - }
660 571
661 - /**
662 - * Set license validation error message.
663 - *
664 - * @param string $message Error message.
665 - */
666 - public function set_error( $message = '' ) {
667 - set_transient( $this->product->get_key() . 'act_err', $message, MINUTE_IN_SECONDS );
668 -
572 + return;
669 573 }
670 574
671 575 /**
672 576 * Load the Themes screen.
673 577 */
674 - public function load_themes_screen() {
578 + function load_themes_screen() {
675 579 add_thickbox();
676 580 add_action( 'admin_notices', array( &$this, 'update_nag' ) );
677 581 }
678 582
@@ -678,9 +582,9 @@
678 582
679 583 /**
680 584 * Alter the nag for themes update.
681 585 */
682 - public function update_nag() {
586 + function update_nag() {
683 587 $theme = wp_get_theme( $this->product->get_slug() );
684 588 $api_response = get_transient( $this->product_key );
685 589 if ( false === $api_response || ! isset( $api_response->new_version ) ) {
686 590 return;
@@ -691,18 +595,18 @@
691 595 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
692 596 echo '<div id="update-nag">';
693 597 printf(
694 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>.',
695 - esc_attr( $theme->get( 'Name' ) ),
696 - esc_attr( $api_response->new_version ),
697 - esc_url( sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ) ),
698 - esc_attr( $theme->get( 'Name' ) ),
699 - esc_url( $update_url ),
700 - $update_onclick // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped.
599 + $theme->get( 'Name' ),
600 + $api_response->new_version,
601 + sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ),
602 + $theme->get( 'Name' ),
603 + $update_url,
604 + $update_onclick
701 605 );
702 606 echo '</div>';
703 - echo '<div id="' . esc_attr( $this->product->get_slug() ) . '_changelog" style="display:none;">';
704 - 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'] );
705 609 echo '</div>';
706 610 }
707 611 }
708 612
@@ -712,23 +616,14 @@
712 616 * @param mixed $value The transient data.
713 617 *
714 618 * @return mixed
715 619 */
716 - public function theme_update_transient( $value ) {
620 + function theme_update_transient( $value ) {
717 621 $update_data = $this->check_for_update();
718 - if ( empty( $value ) ) {
719 - return $value;
622 + if ( $update_data ) {
623 + $value->response[ $this->product->get_slug() ] = $update_data;
720 624 }
721 625
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 626 return $value;
732 627 }
733 628
734 629 /**
@@ -735,9 +630,9 @@
735 630 * Check for updates
736 631 *
737 632 * @return array|bool Either the update data or false in case of failure.
738 633 */
739 - public function check_for_update() {
634 + function check_for_update() {
740 635 $update_data = get_transient( $this->product_key );
741 636
742 637 if ( false === $update_data ) {
743 638 $failed = false;
@@ -773,9 +668,9 @@
773 668 * @return bool|mixed Update api response.
774 669 */
775 670 private function get_version_data() {
776 671
777 - $response = $this->safe_get(
672 + $response = wp_remote_get(
778 673 sprintf(
779 674 '%slicense/version/%s/%s/%s/%s',
780 675 Product::API_URL,
781 676 rawurlencode( $this->product->get_name() ),
@@ -783,9 +678,9 @@
783 678 $this->product->get_version(),
784 679 rawurlencode( home_url() )
785 680 ),
786 681 array(
787 - 'timeout' => 15, //phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout, Inherited by wp_remote_get only, for vip environment we use defaults.
682 + 'timeout' => 15,
788 683 'sslverify' => false,
789 684 )
790 685 );
791 686 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
@@ -810,10 +705,10 @@
810 705
811 706 /**
812 707 * Delete the update transient
813 708 */
814 - public function delete_theme_update_transient() {
815 - return delete_transient( $this->product_key );
709 + function delete_theme_update_transient() {
710 + delete_transient( $this->product_key );
816 711 }
817 712
818 713 /**
819 714 * Check for Updates at the defined API endpoint and modify the update array.
@@ -829,15 +724,10 @@
829 724 return $_transient_data;
830 725 }
831 726 $api_response = $this->api_request();
832 727 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 728 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
837 729 $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
838 - } else {
839 - $_transient_data->no_update[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
840 730 }
841 731 }
842 732
843 733 return $_transient_data;
@@ -891,9 +781,9 @@
891 781 * @param string $url Url to check.
892 782 *
893 783 * @return array $array
894 784 */
895 - public function http_request_args( $args, $url ) {
785 + function http_request_args( $args, $url ) {
896 786 // If it is an https request and we are performing a package download, disable ssl verification.
897 787 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
898 788 $args['sslverify'] = false;
899 789 }
@@ -934,19 +824,12 @@
934 824 if ( $this->product->requires_license() ) {
935 825 $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) );
936 826 $this->register_license_hooks();
937 827 }
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 - }
828 +
945 829 $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false );
946 830
947 831 if ( false !== $namespace ) {
948 - $this->namespace = $namespace;
949 832 add_filter( 'themeisle_sdk_license_process_' . $namespace, [ $this, 'do_license_process' ], 10, 2 );
950 833 add_filter( 'product_' . $namespace . '_license_status', [ $this, 'get_license_status' ], PHP_INT_MAX );
951 834 add_filter( 'product_' . $namespace . '_license_key', [ $this->product, 'get_license' ] );
952 835 add_filter( 'product_' . $namespace . '_license_plan', [ $this, 'get_plan' ], PHP_INT_MAX );
@@ -966,33 +849,19 @@
966 849 'pre_set_site_transient_update_plugins_filter',
967 850 ]
968 851 );
969 852 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
970 - 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>';
853 + add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
980 854
981 - return $new_actions;
982 - }
983 - );
984 - }
985 -
986 855 return $this;
987 856 }
988 857 if ( $this->product->is_theme() ) {
989 858 add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) );
990 - add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
859 + add_filter( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
991 860 add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) );
992 861 add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) );
993 862 add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) );
994 - add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
863 + add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 );
995 864
996 865 return $this;
997 866
998 867 }
@@ -1000,76 +869,44 @@
1000 869 return $this;
1001 870 }
1002 871
1003 872 /**
1004 - * Register license fields for the products.
873 + * Run license activation on plugin activate.
1005 874 */
1006 - public function register_license_hooks() {
1007 - add_action( 'admin_init', array( $this, 'register_settings' ) );
1008 - add_action( 'admin_init', array( $this, 'process_license' ) );
1009 - add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 );
1010 - add_action( 'admin_notices', array( $this, 'show_notice' ) );
1011 - add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) );
1012 - }
875 + public function auto_activate() {
876 + if ( ! current_user_can( 'switch_themes' ) ) {
877 + return;
878 + }
879 + $status = $this->get_license_status();
880 + if ( 'not_active' !== $status ) {
881 + return;
882 + }
1013 883
1014 - /**
1015 - * Check license on filesystem.
1016 - *
1017 - * @return mixed License key.
1018 - */
1019 - public function get_file_license() {
1020 -
1021 884 $license_file = dirname( $this->product->get_basefile() ) . '/license.json';
1022 885
1023 886 global $wp_filesystem;
1024 887 if ( ! is_file( $license_file ) ) {
1025 - return false;
888 + return;
1026 889 }
1027 890
1028 - require_once ABSPATH . '/wp-admin/includes/file.php';
891 + require_once( ABSPATH . '/wp-admin/includes/file.php' );
1029 892 \WP_Filesystem();
1030 893 $content = json_decode( $wp_filesystem->get_contents( $license_file ) );
1031 894 if ( ! is_object( $content ) ) {
1032 - return false;
895 + return;
1033 896 }
1034 897 if ( ! isset( $content->key ) ) {
1035 - return false;
1036 - }
1037 - return $content->key;
1038 - }
1039 - /**
1040 - * Run license activation on plugin activate.
1041 - */
1042 - public function auto_activate() {
1043 - $status = $this->get_license_status();
1044 - if ( 'not_active' !== $status ) {
1045 - return false;
1046 - }
1047 -
1048 - if ( ! empty( $this->namespace ) ) {
1049 - $license_key = apply_filters( 'product_' . $this->namespace . '_license_key_constant', '' );
1050 - }
1051 -
1052 - if ( empty( $license_key ) ) {
1053 - $license_key = $this->get_file_license();
1054 - }
1055 - if ( empty( $license_key ) ) {
1056 898 return;
1057 899 }
1058 -
1059 -
1060 - $this->license_local = $license_key;
900 + $this->license_local = $content;
1061 901 $lock_key = $this->product->get_key() . '_autoactivated';
1062 902
1063 903 if ( 'yes' === get_option( $lock_key, '' ) ) {
1064 904 return;
1065 905 }
1066 - if ( 'yes' === get_transient( $lock_key ) ) {
1067 - return;
1068 - }
1069 - $response = $this->do_license_process( $license_key, 'activate' );
906 + $response = $this->do_license_process( $content->key, 'activate' );
1070 907
1071 - set_transient( $lock_key, 'yes', 6 * HOUR_IN_SECONDS );
908 + update_option( $lock_key, 'yes' );
1072 909
1073 910 if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
1074 911 return;
1075 912 }
@@ -1084,9 +921,9 @@
1084 921 */
1085 922 public function autoactivate_notice() {
1086 923 ?>
1087 924 <div class="notice notice-success is-dismissible">
1088 - <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>
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>
1089 926 </div>
1090 927 <?php
1091 928 }
1092 929
@@ -1150,6 +987,17 @@
1150 987 return;
1151 988 }
1152 989
1153 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' ) );
1154 1002 }
1155 1003 }