PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.7.5
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.7.5
3.4.6 3.4.5 3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 All 199 releases
← All changes | includes/class-convertkit-settings.php +17 -261 3.3.7 → 2.7.5 View file →
@@ -44,8 +44,11 @@
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_refresh_token', array( $this, 'update_credentials' ), 10, 2 );
50 +
48 51 }
49 52
50 53 /**
51 54 * Returns Plugin settings.
@@ -174,11 +177,8 @@
174 177 * @return string
175 178 */
176 179 public function get_access_token() {
177 180
178 - // Reload settings from options table, to ensure we have the latest tokens.
179 - $this->refresh_settings();
180 -
181 181 // Return Access Token from settings.
182 182 return $this->settings['access_token'];
183 183
184 184 }
@@ -204,11 +204,8 @@
204 204 * @return string
205 205 */
206 206 public function get_refresh_token() {
207 207
208 - // Reload settings from options table, to ensure we have the latest tokens.
209 - $this->refresh_settings();
210 -
211 208 // Return Refresh Token from settings.
212 209 return $this->settings['refresh_token'];
213 210
214 211 }
@@ -411,179 +408,8 @@
411 408
412 409 }
413 410
414 411 /**
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 active spam protection provider Plugin setting.
429 - *
430 - * @since 3.3.7
431 - *
432 - * @return string none|recaptcha|turnstile
433 - */
434 - public function spam_protection_provider() {
435 -
436 - return $this->settings['spam_protection_provider'];
437 -
438 - }
439 -
440 - /**
441 - * Returns the reCAPTCHA Site Key Plugin setting.
442 - *
443 - * @since 3.0.0
444 - *
445 - * @return string
446 - */
447 - public function recaptcha_site_key() {
448 -
449 - return $this->settings['recaptcha_site_key'];
450 -
451 - }
452 -
453 - /**
454 - * Returns whether the reCAPTCHA Site Key has been set in the Plugin settings.
455 - *
456 - * @since 3.0.0
457 - *
458 - * @return bool
459 - */
460 - public function has_recaptcha_site_key() {
461 -
462 - return ! empty( $this->recaptcha_site_key() );
463 -
464 - }
465 -
466 - /**
467 - * Returns the reCAPTCHA Secret Key Plugin setting.
468 - *
469 - * @since 3.0.0
470 - *
471 - * @return string
472 - */
473 - public function recaptcha_secret_key() {
474 -
475 - return $this->settings['recaptcha_secret_key'];
476 -
477 - }
478 -
479 - /**
480 - * Returns whether the reCAPTCHA Secret Key has been set in the Plugin settings.
481 - *
482 - * @since 3.0.0
483 - *
484 - * @return bool
485 - */
486 - public function has_recaptcha_secret_key() {
487 -
488 - return ! empty( $this->recaptcha_secret_key() );
489 -
490 - }
491 -
492 - /**
493 - * Returns whether the reCAPTCH Site Key and Secret Key are defined
494 - * in the Plugin settings.
495 - *
496 - * @since 3.0.0
497 - *
498 - * @return bool
499 - */
500 - public function has_recaptcha_site_and_secret_keys() {
501 -
502 - return $this->has_recaptcha_site_key() && $this->has_recaptcha_secret_key();
503 -
504 - }
505 -
506 - /**
507 - * Returns the reCAPTCHA minimum score Plugin setting.
508 - *
509 - * @since 3.0.0
510 - *
511 - * @return float
512 - */
513 - public function recaptcha_minimum_score() {
514 -
515 - return (float) $this->settings['recaptcha_minimum_score'];
516 -
517 - }
518 -
519 - /**
520 - * Returns the Cloudflare Turnstile Site Key Plugin setting.
521 - *
522 - * @since 3.3.7
523 - *
524 - * @return string
525 - */
526 - public function cloudflare_turnstile_site_key() {
527 -
528 - return $this->settings['cloudflare_turnstile_site_key'];
529 -
530 - }
531 -
532 - /**
533 - * Returns whether the Cloudflare Turnstile Site Key has been set in the Plugin settings.
534 - *
535 - * @since 3.3.7
536 - *
537 - * @return bool
538 - */
539 - public function has_cloudflare_turnstile_site_key() {
540 -
541 - return ! empty( $this->cloudflare_turnstile_site_key() );
542 -
543 - }
544 -
545 - /**
546 - * Returns the Cloudflare Turnstile Secret Key Plugin setting.
547 - *
548 - * @since 3.3.7
549 - *
550 - * @return string
551 - */
552 - public function cloudflare_turnstile_secret_key() {
553 -
554 - return $this->settings['cloudflare_turnstile_secret_key'];
555 -
556 - }
557 -
558 - /**
559 - * Returns whether the Cloudflare Turnstile Secret Key has been set in the Plugin settings.
560 - *
561 - * @since 3.3.7
562 - *
563 - * @return bool
564 - */
565 - public function has_cloudflare_turnstile_secret_key() {
566 -
567 - return ! empty( $this->cloudflare_turnstile_secret_key() );
568 -
569 - }
570 -
571 - /**
572 - * Returns whether the Cloudflare Turnstile Site Key and Secret Key are defined
573 - * in the Plugin settings.
574 - *
575 - * @since 3.3.7
576 - *
577 - * @return bool
578 - */
579 - public function has_cloudflare_turnstile_site_and_secret_keys() {
580 -
581 - return $this->has_cloudflare_turnstile_site_key() && $this->has_cloudflare_turnstile_secret_key();
582 -
583 - }
584 -
585 - /**
586 412 * Returns whether debugging is enabled in the Plugin settings.
587 413 *
588 414 * @since 1.9.6
589 415 *
@@ -621,34 +447,8 @@
621 447
622 448 }
623 449
624 450 /**
625 - * Returns whether the Add New Landing Page / Member Content button is disabled in the Plugin settings.
626 - *
627 - * @since 3.2.0
628 - *
629 - * @return bool
630 - */
631 - public function add_new_button_disabled() {
632 -
633 - return ( $this->settings['no_add_new_button'] === 'on' ? true : false );
634 -
635 - }
636 -
637 - /**
638 - * Returns whether usage tracking is enabled in the Plugin settings.
639 - *
640 - * @since 3.0.4
641 - *
642 - * @return bool
643 - */
644 - public function usage_tracking() {
645 -
646 - return ( $this->settings['usage_tracking'] === 'on' ? true : false );
647 -
648 - }
649 -
650 - /**
651 451 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
652 452 * e.g. on a new installation.
653 453 *
654 454 * @since 1.9.6
@@ -669,28 +469,13 @@
669 469
670 470 // Site Wide.
671 471 'non_inline_form' => array(), // array.
672 472 'non_inline_form_honor_none_setting' => '', // blank|on.
673 - 'non_inline_form_limit_per_session' => '', // blank|on.
674 473
675 - // Spam Protection.
676 - 'spam_protection_provider' => 'recaptcha', // recaptcha|turnstile.
677 -
678 - // reCAPTCHA.
679 - 'recaptcha_site_key' => '', // string.
680 - 'recaptcha_secret_key' => '', // string.
681 - 'recaptcha_minimum_score' => 0.5, // float.
682 -
683 - // Cloudflare Turnstile.
684 - 'cloudflare_turnstile_site_key' => '', // string.
685 - 'cloudflare_turnstile_secret_key' => '', // string.
686 -
687 474 // Advanced.
688 475 'debug' => '', // blank|on.
689 476 'no_scripts' => '', // blank|on.
690 477 'no_css' => '', // blank|on.
691 - 'no_add_new_button' => '', // blank|on.
692 - 'usage_tracking' => '', // blank|on.
693 478 );
694 479
695 480 // Add Post Type Default Forms.
696 481 foreach ( convertkit_get_supported_post_types() as $post_type ) {
@@ -714,39 +499,36 @@
714 499
715 500 }
716 501
717 502 /**
718 - * Saves the new access token, refresh token and its expiry, and schedules
719 - * a WordPress Cron event to refresh the token on expiry.
503 + * Saves the new access token, refresh token and its expiry when the API
504 + * class automatically refreshes an outdated access token.
720 505 *
721 - * @since 2.8.3
506 + * @since 2.5.0
722 507 *
723 - * @param array $result New Access Token, Refresh Token and Expiry.
508 + * @param array $result New Access Token, Refresh Token and Expiry.
509 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
724 510 */
725 - public function update_credentials( $result ) {
511 + public function update_credentials( $result, $client_id ) {
726 512
727 - // Remove any existing persistent notice.
728 - WP_ConvertKit()->get_class( 'admin_notices' )->delete( 'authorization_failed' );
513 + // Don't save these credentials if they're not for this Client ID.
514 + // They're for another ConvertKit Plugin that uses OAuth.
515 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
516 + return;
517 + }
729 518
730 519 $this->save(
731 520 array(
732 521 'access_token' => $result['access_token'],
733 522 'refresh_token' => $result['refresh_token'],
734 - 'token_expires' => ( time() + $result['expires_in'] ),
523 + 'token_expires' => ( $result['created_at'] + $result['expires_in'] ),
735 524 )
736 525 );
737 526
738 - // Clear any existing scheduled WordPress Cron event.
739 - wp_clear_scheduled_hook( 'convertkit_refresh_token' );
740 -
741 - // Schedule a WordPress Cron event to refresh the token on expiry.
742 - wp_schedule_single_event( ( time() + $result['expires_in'] ), 'convertkit_refresh_token' );
743 -
744 527 }
745 528
746 529 /**
747 - * Deletes any existing access token, refresh token and its expiry from the Plugin settings,
748 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry.
530 + * Deletes any existing access token, refresh token and its expiry from the Plugin settings.
749 531 *
750 532 * @since 2.5.0
751 533 */
752 534 public function delete_credentials() {
@@ -752,22 +534,14 @@
752 534 public function delete_credentials() {
753 535
754 536 $this->save(
755 537 array(
756 - // OAuth.
757 538 'access_token' => '',
758 539 'refresh_token' => '',
759 540 'token_expires' => '',
760 -
761 - // API Key.
762 - 'api_key' => '',
763 - 'api_secret' => '',
764 541 )
765 542 );
766 543
767 - // Clear any existing scheduled WordPress Cron event.
768 - wp_clear_scheduled_hook( 'convertkit_refresh_token' );
769 -
770 544 }
771 545
772 546 /**
773 547 * Saves the given array of settings to the WordPress options table.
@@ -780,27 +554,9 @@
780 554
781 555 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
782 556
783 557 // Reload settings in class, to reflect changes.
784 - $this->refresh_settings();
785 -
786 - }
787 -
788 - /**
789 - * Reloads settings from the options table so this instance has the latest values.
790 - *
791 - * @since 3.1.1
792 - */
793 - private function refresh_settings() {
794 -
795 - $settings = get_option( self::SETTINGS_NAME );
796 -
797 - if ( ! $settings ) {
798 - $this->settings = $this->get_defaults();
799 - return;
800 - }
801 -
802 - $this->settings = array_merge( $this->get_defaults(), $settings );
558 + $this->settings = get_option( self::SETTINGS_NAME );
803 559
804 560 }
805 561
806 562 }