| @@ -44,8 +44,12 @@ | ||
| 44 | 44 | } else { |
| 45 | 45 | $this->settings = array_merge( $this->get_defaults(), $settings ); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | + // Update Access Token when refreshed by the API class. | |
| 49 | + add_action( 'convertkit_api_get_access_token', array( $this, 'update_credentials' ), 10, 2 ); | |
| 50 | + add_action( 'convertkit_api_refresh_token', array( $this, 'update_credentials' ), 10, 2 ); | |
| 51 | + | |
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | /** |
| 51 | 55 | * Returns Plugin settings. |
| @@ -174,11 +178,8 @@ | ||
| 174 | 178 | * @return string |
| 175 | 179 | */ |
| 176 | 180 | public function get_access_token() { |
| 177 | 181 | |
| 178 | - // Reload settings from options table, to ensure we have the latest tokens. | |
| 179 | - $this->refresh_settings(); | |
| 180 | - | |
| 181 | 182 | // Return Access Token from settings. |
| 182 | 183 | return $this->settings['access_token']; |
| 183 | 184 | |
| 184 | 185 | } |
| @@ -204,11 +205,8 @@ | ||
| 204 | 205 | * @return string |
| 205 | 206 | */ |
| 206 | 207 | public function get_refresh_token() { |
| 207 | 208 | |
| 208 | - // Reload settings from options table, to ensure we have the latest tokens. | |
| 209 | - $this->refresh_settings(); | |
| 210 | - | |
| 211 | 209 | // Return Refresh Token from settings. |
| 212 | 210 | return $this->settings['refresh_token']; |
| 213 | 211 | |
| 214 | 212 | } |
| @@ -411,100 +409,8 @@ | ||
| 411 | 409 | |
| 412 | 410 | } |
| 413 | 411 | |
| 414 | 412 | /** |
| 415 | - * Returns whether the Non-inline Form Limit per Session setting has been set in the Plugin settings. | |
| 416 | - * | |
| 417 | - * @since 3.0.0 | |
| 418 | - * | |
| 419 | - * @return bool | |
| 420 | - */ | |
| 421 | - public function non_inline_form_limit_per_session() { | |
| 422 | - | |
| 423 | - return ( $this->settings['non_inline_form_limit_per_session'] === 'on' ? true : false ); | |
| 424 | - | |
| 425 | - } | |
| 426 | - | |
| 427 | - /** | |
| 428 | - * Returns the reCAPTCHA Site Key Plugin setting. | |
| 429 | - * | |
| 430 | - * @since 3.0.0 | |
| 431 | - * | |
| 432 | - * @return string | |
| 433 | - */ | |
| 434 | - public function recaptcha_site_key() { | |
| 435 | - | |
| 436 | - return $this->settings['recaptcha_site_key']; | |
| 437 | - | |
| 438 | - } | |
| 439 | - | |
| 440 | - /** | |
| 441 | - * Returns whether the reCAPTCHA Site Key has been set in the Plugin settings. | |
| 442 | - * | |
| 443 | - * @since 3.0.0 | |
| 444 | - * | |
| 445 | - * @return bool | |
| 446 | - */ | |
| 447 | - public function has_recaptcha_site_key() { | |
| 448 | - | |
| 449 | - return ! empty( $this->recaptcha_site_key() ); | |
| 450 | - | |
| 451 | - } | |
| 452 | - | |
| 453 | - /** | |
| 454 | - * Returns the reCAPTCHA Secret Key Plugin setting. | |
| 455 | - * | |
| 456 | - * @since 3.0.0 | |
| 457 | - * | |
| 458 | - * @return string | |
| 459 | - */ | |
| 460 | - public function recaptcha_secret_key() { | |
| 461 | - | |
| 462 | - return $this->settings['recaptcha_secret_key']; | |
| 463 | - | |
| 464 | - } | |
| 465 | - | |
| 466 | - /** | |
| 467 | - * Returns whether the reCAPTCHA Secret Key has been set in the Plugin settings. | |
| 468 | - * | |
| 469 | - * @since 3.0.0 | |
| 470 | - * | |
| 471 | - * @return bool | |
| 472 | - */ | |
| 473 | - public function has_recaptcha_secret_key() { | |
| 474 | - | |
| 475 | - return ! empty( $this->recaptcha_secret_key() ); | |
| 476 | - | |
| 477 | - } | |
| 478 | - | |
| 479 | - /** | |
| 480 | - * Returns whether the reCAPTCH Site Key and Secret Key are defined | |
| 481 | - * in the Plugin settings. | |
| 482 | - * | |
| 483 | - * @since 3.0.0 | |
| 484 | - * | |
| 485 | - * @return bool | |
| 486 | - */ | |
| 487 | - public function has_recaptcha_site_and_secret_keys() { | |
| 488 | - | |
| 489 | - return $this->has_recaptcha_site_key() && $this->has_recaptcha_secret_key(); | |
| 490 | - | |
| 491 | - } | |
| 492 | - | |
| 493 | - /** | |
| 494 | - * Returns the reCAPTCHA minimum score Plugin setting. | |
| 495 | - * | |
| 496 | - * @since 3.0.0 | |
| 497 | - * | |
| 498 | - * @return float | |
| 499 | - */ | |
| 500 | - public function recaptcha_minimum_score() { | |
| 501 | - | |
| 502 | - return (float) $this->settings['recaptcha_minimum_score']; | |
| 503 | - | |
| 504 | - } | |
| 505 | - | |
| 506 | - /** | |
| 507 | 413 | * Returns whether debugging is enabled in the Plugin settings. |
| 508 | 414 | * |
| 509 | 415 | * @since 1.9.6 |
| 510 | 416 | * |
| @@ -542,34 +448,8 @@ | ||
| 542 | 448 | |
| 543 | 449 | } |
| 544 | 450 | |
| 545 | 451 | /** |
| 546 | - * Returns whether the Add New Landing Page / Member Content button is disabled in the Plugin settings. | |
| 547 | - * | |
| 548 | - * @since 3.2.0 | |
| 549 | - * | |
| 550 | - * @return bool | |
| 551 | - */ | |
| 552 | - public function add_new_button_disabled() { | |
| 553 | - | |
| 554 | - return ( $this->settings['no_add_new_button'] === 'on' ? true : false ); | |
| 555 | - | |
| 556 | - } | |
| 557 | - | |
| 558 | - /** | |
| 559 | - * Returns whether usage tracking is enabled in the Plugin settings. | |
| 560 | - * | |
| 561 | - * @since 3.0.4 | |
| 562 | - * | |
| 563 | - * @return bool | |
| 564 | - */ | |
| 565 | - public function usage_tracking() { | |
| 566 | - | |
| 567 | - return ( $this->settings['usage_tracking'] === 'on' ? true : false ); | |
| 568 | - | |
| 569 | - } | |
| 570 | - | |
| 571 | - /** | |
| 572 | 452 | * The default settings, used when the ConvertKit Plugin Settings haven't been saved |
| 573 | 453 | * e.g. on a new installation. |
| 574 | 454 | * |
| 575 | 455 | * @since 1.9.6 |
| @@ -590,21 +470,13 @@ | ||
| 590 | 470 | |
| 591 | 471 | // Site Wide. |
| 592 | 472 | 'non_inline_form' => array(), // array. |
| 593 | 473 | 'non_inline_form_honor_none_setting' => '', // blank|on. |
| 594 | - 'non_inline_form_limit_per_session' => '', // blank|on. | |
| 595 | 474 | |
| 596 | - // reCAPTCHA. | |
| 597 | - 'recaptcha_site_key' => '', // string. | |
| 598 | - 'recaptcha_secret_key' => '', // string. | |
| 599 | - 'recaptcha_minimum_score' => 0.5, // float. | |
| 600 | - | |
| 601 | 475 | // Advanced. |
| 602 | 476 | 'debug' => '', // blank|on. |
| 603 | 477 | 'no_scripts' => '', // blank|on. |
| 604 | 478 | 'no_css' => '', // blank|on. |
| 605 | - 'no_add_new_button' => '', // blank|on. | |
| 606 | - 'usage_tracking' => '', // blank|on. | |
| 607 | 479 | ); |
| 608 | 480 | |
| 609 | 481 | // Add Post Type Default Forms. |
| 610 | 482 | foreach ( convertkit_get_supported_post_types() as $post_type ) { |
| @@ -633,14 +505,18 @@ | ||
| 633 | 505 | * a WordPress Cron event to refresh the token on expiry. |
| 634 | 506 | * |
| 635 | 507 | * @since 2.8.3 |
| 636 | 508 | * |
| 637 | - * @param array $result New Access Token, Refresh Token and Expiry. | |
| 509 | + * @param array $result New Access Token, Refresh Token and Expiry. | |
| 510 | + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. | |
| 638 | 511 | */ |
| 639 | - public function update_credentials( $result ) { | |
| 512 | + public function update_credentials( $result, $client_id ) { | |
| 640 | 513 | |
| 641 | - // Remove any existing persistent notice. | |
| 642 | - WP_ConvertKit()->get_class( 'admin_notices' )->delete( 'authorization_failed' ); | |
| 514 | + // Don't save these credentials if they're not for this Client ID. | |
| 515 | + // They're for another Kit Plugin that uses OAuth. | |
| 516 | + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { | |
| 517 | + return; | |
| 518 | + } | |
| 643 | 519 | |
| 644 | 520 | $this->save( |
| 645 | 521 | array( |
| 646 | 522 | 'access_token' => $result['access_token'], |
| @@ -657,10 +533,9 @@ | ||
| 657 | 533 | |
| 658 | 534 | } |
| 659 | 535 | |
| 660 | 536 | /** |
| 661 | - * Deletes any existing access token, refresh token and its expiry from the Plugin settings, | |
| 662 | - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry. | |
| 537 | + * Deletes any existing access token, refresh token and its expiry from the Plugin settings. | |
| 663 | 538 | * |
| 664 | 539 | * @since 2.5.0 |
| 665 | 540 | */ |
| 666 | 541 | public function delete_credentials() { |
| @@ -666,22 +541,14 @@ | ||
| 666 | 541 | public function delete_credentials() { |
| 667 | 542 | |
| 668 | 543 | $this->save( |
| 669 | 544 | array( |
| 670 | - // OAuth. | |
| 671 | 545 | 'access_token' => '', |
| 672 | 546 | 'refresh_token' => '', |
| 673 | 547 | 'token_expires' => '', |
| 674 | - | |
| 675 | - // API Key. | |
| 676 | - 'api_key' => '', | |
| 677 | - 'api_secret' => '', | |
| 678 | 548 | ) |
| 679 | 549 | ); |
| 680 | 550 | |
| 681 | - // Clear any existing scheduled WordPress Cron event. | |
| 682 | - wp_clear_scheduled_hook( 'convertkit_refresh_token' ); | |
| 683 | - | |
| 684 | 551 | } |
| 685 | 552 | |
| 686 | 553 | /** |
| 687 | 554 | * Saves the given array of settings to the WordPress options table. |
| @@ -694,27 +561,9 @@ | ||
| 694 | 561 | |
| 695 | 562 | update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) ); |
| 696 | 563 | |
| 697 | 564 | // Reload settings in class, to reflect changes. |
| 698 | - $this->refresh_settings(); | |
| 699 | - | |
| 700 | - } | |
| 701 | - | |
| 702 | - /** | |
| 703 | - * Reloads settings from the options table so this instance has the latest values. | |
| 704 | - * | |
| 705 | - * @since 3.1.1 | |
| 706 | - */ | |
| 707 | - private function refresh_settings() { | |
| 708 | - | |
| 709 | - $settings = get_option( self::SETTINGS_NAME ); | |
| 710 | - | |
| 711 | - if ( ! $settings ) { | |
| 712 | - $this->settings = $this->get_defaults(); | |
| 713 | - return; | |
| 714 | - } | |
| 715 | - | |
| 716 | - $this->settings = array_merge( $this->get_defaults(), $settings ); | |
| 565 | + $this->settings = get_option( self::SETTINGS_NAME ); | |
| 717 | 566 | |
| 718 | 567 | } |
| 719 | 568 | |
| 720 | 569 | } |