PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.0.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.0.6
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 2.2.9 2.3.0 All 197 releases
← All changes | includes/class-convertkit-settings.php +14 -303 3.4.23.0.6 View file →
@@ -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 }
@@ -424,21 +422,8 @@
424 422
425 423 }
426 424
427 425 /**
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 426 * Returns the reCAPTCHA Site Key Plugin setting.
442 427 *
443 428 * @since 3.0.0
444 429 *
@@ -516,74 +501,8 @@
516 501
517 502 }
518 503
519 504 /**
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 505 * Returns whether debugging is enabled in the Plugin settings.
587 506 *
588 507 * @since 1.9.6
589 508 *
@@ -621,21 +540,8 @@
621 540
622 541 }
623 542
624 543 /**
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 544 * Returns whether usage tracking is enabled in the Plugin settings.
639 545 *
640 546 * @since 3.0.4
641 547 *
@@ -647,172 +553,8 @@
647 553
648 554 }
649 555
650 556 /**
651 - * Returns this settings group's programmatic name.
652 - *
653 - * @since 3.4.0
654 - *
655 - * @return string
656 - */
657 - public function get_name() {
658 -
659 - return 'general';
660 -
661 - }
662 -
663 - /**
664 - * Returns the title of this settings group.
665 - *
666 - * @since 3.4.0
667 - *
668 - * @return string
669 - */
670 - public function get_title() {
671 -
672 - return __( 'General Settings', 'convertkit' );
673 -
674 - }
675 -
676 - /**
677 - * Returns the keys in this settings group that hold credentials or other
678 - * sensitive values.
679 - *
680 - * @since 3.4.0
681 - *
682 - * @return string[]
683 - */
684 - public function get_secret_keys() {
685 -
686 - return array(
687 - 'access_token',
688 - 'refresh_token',
689 - 'token_expires',
690 - 'api_key',
691 - 'api_secret',
692 - 'recaptcha_secret_key',
693 - );
694 -
695 - }
696 -
697 - /**
698 - * Returns the JSON Schema describing this settings group, in the shape
699 - * stored by save() / returned by get(), excluding secret keys.
700 - *
701 - * @since 3.4.0
702 - *
703 - * @return array
704 - */
705 - public function get_schema() {
706 -
707 - $properties = array(
708 - 'non_inline_form' => array(
709 - 'type' => 'array',
710 - 'items' => array( 'type' => 'integer' ),
711 - 'description' => __( 'IDs of non-inline Forms to display site-wide.', 'convertkit' ),
712 - ),
713 - 'non_inline_form_honor_none_setting' => array(
714 - 'type' => 'string',
715 - 'enum' => array( '', 'on' ),
716 - 'description' => __( 'Whether the site-wide non-inline Form honors a per-Page / per-Post "None" Form setting.', 'convertkit' ),
717 - ),
718 - 'non_inline_form_limit_per_session' => array(
719 - 'type' => 'string',
720 - 'enum' => array( '', 'on' ),
721 - 'description' => __( 'Whether to limit non-inline Form display to once per session.', 'convertkit' ),
722 - ),
723 - 'recaptcha_site_key' => array(
724 - 'type' => 'string',
725 - 'description' => __( 'Google reCAPTCHA v3 site key.', 'convertkit' ),
726 - ),
727 - 'recaptcha_minimum_score' => array(
728 - 'type' => 'number',
729 - 'minimum' => 0,
730 - 'maximum' => 1,
731 - 'description' => __( 'Minimum Google reCAPTCHA v3 score (0.0 - 1.0) below which a request is treated as spam.', 'convertkit' ),
732 - ),
733 - 'debug' => array(
734 - 'type' => 'string',
735 - 'enum' => array( '', 'on' ),
736 - 'description' => __( 'Whether debug logging is enabled.', 'convertkit' ),
737 - ),
738 - 'no_scripts' => array(
739 - 'type' => 'string',
740 - 'enum' => array( '', 'on' ),
741 - 'description' => __( 'Whether the Plugin\'s frontend JavaScript is disabled.', 'convertkit' ),
742 - ),
743 - 'no_css' => array(
744 - 'type' => 'string',
745 - 'enum' => array( '', 'on' ),
746 - 'description' => __( 'Whether the Plugin\'s frontend CSS is disabled.', 'convertkit' ),
747 - ),
748 - 'no_add_new_button' => array(
749 - 'type' => 'string',
750 - 'enum' => array( '', 'on' ),
751 - 'description' => __( 'Whether the "Add New" button for Landing Pages / Member Content is hidden in the WordPress Admin.', 'convertkit' ),
752 - ),
753 - 'usage_tracking' => array(
754 - 'type' => 'string',
755 - 'enum' => array( '', 'on' ),
756 - 'description' => __( 'Whether anonymous usage tracking is enabled.', 'convertkit' ),
757 - ),
758 - );
759 -
760 - // Per-post-type Default Form settings, mirroring get_defaults().
761 - foreach ( convertkit_get_supported_post_types() as $post_type ) {
762 - $properties[ $post_type . '_form' ] = array(
763 - 'type' => 'integer',
764 - 'minimum' => -1,
765 - 'description' => sprintf(
766 - /* translators: Post type slug. */
767 - __( 'Default Form ID to display on %s. `-1` = Plugin Default; `0` = None; positive integer = specific Kit Form ID.', 'convertkit' ),
768 - $post_type
769 - ),
770 - );
771 -
772 - $properties[ $post_type . '_form_position' ] = array(
773 - 'type' => 'string',
774 - 'enum' => array( 'before_content', 'after_content', 'before_after_content', 'after_element' ),
775 - 'description' => sprintf(
776 - /* translators: Post type slug. */
777 - __( 'Where the Default Form displays relative to the %s content.', 'convertkit' ),
778 - $post_type
779 - ),
780 - );
781 -
782 - $properties[ $post_type . '_form_position_element' ] = array(
783 - 'type' => 'string',
784 - 'enum' => array( 'p', 'h2', 'h3', 'h4', 'h5', 'h6', 'img' ),
785 - 'description' => sprintf(
786 - /* translators: 1: Post type slug, 2: Post type slug. */
787 - __( 'HTML element after which to display the Default Form on %1$s. Only used when `%2$s_form_position` is `after_element`.', 'convertkit' ),
788 - $post_type,
789 - $post_type
790 - ),
791 - );
792 -
793 - $properties[ $post_type . '_form_position_element_index' ] = array(
794 - 'type' => 'integer',
795 - 'minimum' => 1,
796 - 'maximum' => 999,
797 - 'description' => sprintf(
798 - /* translators: 1: Post type slug, 2: Post type slug. */
799 - __( 'Nth occurrence of the element after which to display the Default Form on %1$s. Only used when `%2$s_form_position` is `after_element`.', 'convertkit' ),
800 - $post_type,
801 - $post_type
802 - ),
803 - );
804 - }
805 -
806 - return array(
807 - 'type' => 'object',
808 - 'additionalProperties' => false,
809 - 'properties' => $properties,
810 - );
811 -
812 - }
813 -
814 - /**
815 557 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
816 558 * e.g. on a new installation.
817 559 *
818 560 * @since 1.9.6
@@ -835,25 +577,17 @@
835 577 'non_inline_form' => array(), // array.
836 578 'non_inline_form_honor_none_setting' => '', // blank|on.
837 579 'non_inline_form_limit_per_session' => '', // blank|on.
838 580
839 - // Spam Protection.
840 - 'spam_protection_provider' => 'recaptcha', // recaptcha|turnstile.
841 -
842 581 // reCAPTCHA.
843 582 'recaptcha_site_key' => '', // string.
844 583 'recaptcha_secret_key' => '', // string.
845 584 'recaptcha_minimum_score' => 0.5, // float.
846 585
847 - // Cloudflare Turnstile.
848 - 'cloudflare_turnstile_site_key' => '', // string.
849 - 'cloudflare_turnstile_secret_key' => '', // string.
850 -
851 586 // Advanced.
852 587 'debug' => '', // blank|on.
853 588 'no_scripts' => '', // blank|on.
854 589 'no_css' => '', // blank|on.
855 - 'no_add_new_button' => '', // blank|on.
856 590 'usage_tracking' => '', // blank|on.
857 591 );
858 592
859 593 // Add Post Type Default Forms.
@@ -883,14 +617,18 @@
883 617 * a WordPress Cron event to refresh the token on expiry.
884 618 *
885 619 * @since 2.8.3
886 620 *
887 - * @param array $result New Access Token, Refresh Token and Expiry.
621 + * @param array $result New Access Token, Refresh Token and Expiry.
622 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
888 623 */
889 - public function update_credentials( $result ) {
624 + public function update_credentials( $result, $client_id ) {
890 625
891 - // Remove any existing persistent notice.
892 - WP_ConvertKit()->get_class( 'admin_notices' )->delete( 'authorization_failed' );
626 + // Don't save these credentials if they're not for this Client ID.
627 + // They're for another Kit Plugin that uses OAuth.
628 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
629 + return;
630 + }
893 631
894 632 $this->save(
895 633 array(
896 634 'access_token' => $result['access_token'],
@@ -907,10 +645,9 @@
907 645
908 646 }
909 647
910 648 /**
911 - * Deletes any existing access token, refresh token and its expiry from the Plugin settings,
912 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry.
649 + * Deletes any existing access token, refresh token and its expiry from the Plugin settings.
913 650 *
914 651 * @since 2.5.0
915 652 */
916 653 public function delete_credentials() {
@@ -916,22 +653,14 @@
916 653 public function delete_credentials() {
917 654
918 655 $this->save(
919 656 array(
920 - // OAuth.
921 657 'access_token' => '',
922 658 'refresh_token' => '',
923 659 'token_expires' => '',
924 -
925 - // API Key.
926 - 'api_key' => '',
927 - 'api_secret' => '',
928 660 )
929 661 );
930 662
931 - // Clear any existing scheduled WordPress Cron event.
932 - wp_clear_scheduled_hook( 'convertkit_refresh_token' );
933 -
934 663 }
935 664
936 665 /**
937 666 * Saves the given array of settings to the WordPress options table.
@@ -944,27 +673,9 @@
944 673
945 674 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
946 675
947 676 // Reload settings in class, to reflect changes.
948 - $this->refresh_settings();
949 -
950 - }
951 -
952 - /**
953 - * Reloads settings from the options table so this instance has the latest values.
954 - *
955 - * @since 3.1.1
956 - */
957 - private function refresh_settings() {
958 -
959 - $settings = get_option( self::SETTINGS_NAME );
960 -
961 - if ( ! $settings ) {
962 - $this->settings = $this->get_defaults();
963 - return;
964 - }
965 -
966 - $this->settings = array_merge( $this->get_defaults(), $settings );
677 + $this->settings = get_option( self::SETTINGS_NAME );
967 678
968 679 }
969 680
970 681 }