| @@ -19,8 +19,18 @@ | ||
| 19 | 19 | private $is_expired_addon = false; |
| 20 | 20 | public $license; |
| 21 | 21 | protected $get_beta = false; |
| 22 | 22 | |
| 23 | + /** | |
| 24 | + * This is used to flag other add ons not to send a request. | |
| 25 | + * We only want to send a single API request per HTTP request. | |
| 26 | + * | |
| 27 | + * @since 6.7.1 | |
| 28 | + * | |
| 29 | + * @var bool | |
| 30 | + */ | |
| 31 | + private static $sent_mothership_request = false; | |
| 32 | + | |
| 23 | 33 | public function __construct() { |
| 24 | 34 | |
| 25 | 35 | if ( empty( $this->plugin_slug ) ) { |
| 26 | 36 | $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) ); |
| @@ -78,9 +88,9 @@ | ||
| 78 | 88 | * Updates information on the "View version x.x details" page with custom data. |
| 79 | 89 | * |
| 80 | 90 | * @uses api_request() |
| 81 | 91 | * |
| 82 | - * @param mixed $_data | |
| 92 | + * @param mixed $_data | |
| 83 | 93 | * @param string $_action |
| 84 | 94 | * @param object $_args |
| 85 | 95 | * |
| 86 | 96 | * @return object $_data |
| @@ -219,9 +229,9 @@ | ||
| 219 | 229 | |
| 220 | 230 | /** |
| 221 | 231 | * @since 3.04.03 |
| 222 | 232 | * |
| 223 | - * @param array error | |
| 233 | + * @param array $error | |
| 224 | 234 | */ |
| 225 | 235 | public function maybe_clear_license( $error ) { |
| 226 | 236 | if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) { |
| 227 | 237 | $this->clear_license(); |
| @@ -338,9 +348,9 @@ | ||
| 338 | 348 | return $transient; |
| 339 | 349 | } |
| 340 | 350 | |
| 341 | 351 | if ( $this->is_current_version( $transient ) ) { |
| 342 | - //make sure it doesn't show there is an update if plugin is up-to-date | |
| 352 | + // Make sure it doesn't show there is an update if plugin is up-to-date. | |
| 343 | 353 | if ( isset( $transient->response[ $this->plugin_folder ] ) ) { |
| 344 | 354 | unset( $transient->response[ $this->plugin_folder ] ); |
| 345 | 355 | } |
| 346 | 356 | } elseif ( isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) ) { |
| @@ -363,9 +373,9 @@ | ||
| 363 | 373 | * Check if the plugin information is correct to allow an update |
| 364 | 374 | * |
| 365 | 375 | * @since 3.04.03 |
| 366 | 376 | * |
| 367 | - * @param object $transient - the current plugin info saved for update | |
| 377 | + * @param object $transient The current plugin info saved for update. | |
| 368 | 378 | */ |
| 369 | 379 | private function prepare_update_details( &$transient ) { |
| 370 | 380 | $version_info = $transient; |
| 371 | 381 | $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta ); |
| @@ -374,9 +384,10 @@ | ||
| 374 | 384 | } |
| 375 | 385 | |
| 376 | 386 | if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) { |
| 377 | 387 | $this->clear_old_plugin_version( $version_info ); |
| 378 | - if ( $version_info === false ) { // was cleared with timeout | |
| 388 | + if ( $version_info === false ) { | |
| 389 | + // Was cleared with timeout. | |
| 379 | 390 | $transient = false; |
| 380 | 391 | } else { |
| 381 | 392 | $this->maybe_use_beta_url( $version_info ); |
| 382 | 393 | |
| @@ -416,9 +427,10 @@ | ||
| 416 | 427 | */ |
| 417 | 428 | private function clear_old_plugin_version( &$version_info ) { |
| 418 | 429 | $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0; |
| 419 | 430 | if ( ! empty( $timeout ) && time() > $timeout ) { |
| 420 | - $version_info = false; // Cache is expired | |
| 431 | + // Cache is expired. | |
| 432 | + $version_info = false; | |
| 421 | 433 | $api = new FrmFormApi( $this->license ); |
| 422 | 434 | $api->reset_cached(); |
| 423 | 435 | } |
| 424 | 436 | } |
| @@ -462,8 +474,12 @@ | ||
| 462 | 474 | update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) ); |
| 463 | 475 | } |
| 464 | 476 | |
| 465 | 477 | private function is_license_revoked() { |
| 478 | + if ( self::$sent_mothership_request ) { | |
| 479 | + return; | |
| 480 | + } | |
| 481 | + | |
| 466 | 482 | if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 467 | 483 | return; |
| 468 | 484 | } |
| 469 | 485 | |
| @@ -471,8 +487,9 @@ | ||
| 471 | 487 | if ( $this->checked_recently( '7 days' ) ) { |
| 472 | 488 | return; |
| 473 | 489 | } |
| 474 | 490 | |
| 491 | + self::$sent_mothership_request = true; | |
| 475 | 492 | $this->update_last_checked(); |
| 476 | 493 | |
| 477 | 494 | $response = $this->get_license_status(); |
| 478 | 495 | if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) { |
| @@ -482,9 +499,9 @@ | ||
| 482 | 499 | |
| 483 | 500 | /** |
| 484 | 501 | * Has this been checked too recently? |
| 485 | 502 | * |
| 486 | - * @param string $time ie. '1 day' | |
| 503 | + * @param string $time ie. '1 day'. | |
| 487 | 504 | * @return bool |
| 488 | 505 | */ |
| 489 | 506 | private function checked_recently( $time ) { |
| 490 | 507 | $last_checked = $this->last_checked(); |
| @@ -618,9 +635,9 @@ | ||
| 618 | 635 | $license_data = $this->send_mothership_request( 'activate_license' ); |
| 619 | 636 | |
| 620 | 637 | // $license_data->license will be either "valid" or "invalid" |
| 621 | 638 | if ( is_array( $license_data ) ) { |
| 622 | - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 639 | + if ( ! empty( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 623 | 640 | $response['status'] = $license_data['license']; |
| 624 | 641 | } |
| 625 | 642 | } else { |
| 626 | 643 | $response['status'] = $license_data; |
| @@ -743,9 +760,9 @@ | ||
| 743 | 760 | $message = $json_res['error']; |
| 744 | 761 | } else { |
| 745 | 762 | $message = $json_res; |
| 746 | 763 | } |
| 747 | - } elseif ( isset( $resp['response'] ) && isset( $resp['response']['code'] ) ) { | |
| 764 | + } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) { | |
| 748 | 765 | $resp['body'] = wp_strip_all_tags( $resp['body'] ); |
| 749 | 766 | |
| 750 | 767 | $message = sprintf( |
| 751 | 768 | /* translators: %1$s: Error code, %2$s: Error message */ |
| @@ -753,9 +770,9 @@ | ||
| 753 | 770 | esc_html( $resp['response']['code'] ), |
| 754 | 771 | $resp['response']['message'] . ' ' . $resp['body'] |
| 755 | 772 | ); |
| 756 | 773 | } |
| 757 | - } | |
| 774 | + }//end if | |
| 758 | 775 | |
| 759 | 776 | return $message; |
| 760 | 777 | } |
| 761 | 778 | |