← All changes
|
admin/section/class-convertkit-admin-section-general.php
+182
-36
3.3.4
→
3.4.3
View file →
| @@ -14,17 +14,8 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | class ConvertKit_Admin_Section_General extends ConvertKit_Admin_Section_Base { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Holds the API instance. | |
| 19 | - * | |
| 20 | - * @since 1.9.6 | |
| 21 | - * | |
| 22 | - * @var ConvertKit_API_V4 | |
| 23 | - */ | |
| 24 | - private $api; | |
| 25 | - | |
| 26 | - /** | |
| 27 | 18 | * Holds the ConvertKit Account Name. |
| 28 | 19 | * |
| 29 | 20 | * @since 1.9.6 |
| 30 | 21 | * |
| @@ -52,30 +43,30 @@ | ||
| 52 | 43 | // Define the settings key. |
| 53 | 44 | $this->settings_key = $this->settings::SETTINGS_NAME; |
| 54 | 45 | |
| 55 | 46 | // Define the programmatic name, Title and Tab Text. |
| 56 | - $this->name = 'general'; | |
| 57 | - $this->title = __( 'General Settings', 'convertkit' ); | |
| 47 | + $this->name = $this->settings->get_name(); | |
| 48 | + $this->title = $this->settings->get_title(); | |
| 58 | 49 | $this->tab_text = __( 'General', 'convertkit' ); |
| 59 | 50 | |
| 60 | 51 | // Define settings sections. |
| 61 | 52 | $this->settings_sections = array( |
| 62 | - 'general' => array( | |
| 53 | + 'general' => array( | |
| 63 | 54 | 'title' => $this->title, |
| 64 | 55 | 'callback' => array( $this, 'print_section_info' ), |
| 65 | 56 | 'wrap' => true, |
| 66 | 57 | ), |
| 67 | - 'site-wide' => array( | |
| 58 | + 'site-wide' => array( | |
| 68 | 59 | 'title' => __( 'Non-inline Forms', 'convertkit' ), |
| 69 | 60 | 'callback' => array( $this, 'print_section_info_site_wide' ), |
| 70 | 61 | 'wrap' => true, |
| 71 | 62 | ), |
| 72 | - 'recaptcha' => array( | |
| 73 | - 'title' => __( 'reCAPTCHA', 'convertkit' ), | |
| 74 | - 'callback' => array( $this, 'print_section_info_recaptcha' ), | |
| 63 | + 'spam-protection' => array( | |
| 64 | + 'title' => __( 'Spam Protection', 'convertkit' ), | |
| 65 | + 'callback' => array( $this, 'print_section_info_spam_protection' ), | |
| 75 | 66 | 'wrap' => true, |
| 76 | 67 | ), |
| 77 | - 'advanced' => array( | |
| 68 | + 'advanced' => array( | |
| 78 | 69 | 'title' => __( 'Advanced', 'convertkit' ), |
| 79 | 70 | 'callback' => array( $this, 'print_section_info_advanced' ), |
| 80 | 71 | 'wrap' => true, |
| 81 | 72 | ), |
| @@ -86,8 +77,9 @@ | ||
| 86 | 77 | // Register and maybe output notices for this settings screen, and the Intercom messenger. |
| 87 | 78 | if ( $this->on_settings_screen( $this->name ) ) { |
| 88 | 79 | add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) ); |
| 89 | 80 | add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) ); |
| 81 | + add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_legacy_form_notice' ) ); | |
| 90 | 82 | } |
| 91 | 83 | |
| 92 | 84 | // Enqueue scripts and CSS. |
| 93 | 85 | add_action( 'convertkit_admin_settings_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| @@ -119,8 +111,43 @@ | ||
| 119 | 111 | |
| 120 | 112 | } |
| 121 | 113 | |
| 122 | 114 | /** |
| 115 | + * Outputs a non-dismissible warning when one or more Default Form settings | |
| 116 | + * reference Legacy Forms. | |
| 117 | + * | |
| 118 | + * @since 3.3.9 | |
| 119 | + */ | |
| 120 | + public function maybe_output_legacy_form_notice() { | |
| 121 | + | |
| 122 | + // Get warnings. | |
| 123 | + $warnings = WP_ConvertKit()->get_class( 'admin_legacy_resource_notice' )->get_legacy_warnings_for_plugin_settings( $this->settings->get() ); | |
| 124 | + | |
| 125 | + // Bail if no warnings are found. | |
| 126 | + if ( empty( $warnings ) ) { | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + | |
| 130 | + // Output warnings. | |
| 131 | + ?> | |
| 132 | + <div id="convertkit-legacy-settings-warning" class="notice notice-warning"> | |
| 133 | + <p> | |
| 134 | + <strong><?php esc_html_e( 'Kit', 'convertkit' ); ?>:</strong> | |
| 135 | + <?php esc_html_e( 'Your Default Form settings reference Legacy Forms. They still work, but should be migrated:', 'convertkit' ); ?> | |
| 136 | + </p> | |
| 137 | + <ul> | |
| 138 | + <?php | |
| 139 | + foreach ( $warnings as $warning ) { | |
| 140 | + echo '<li>' . esc_html( $warning ) . '</li>'; | |
| 141 | + } | |
| 142 | + ?> | |
| 143 | + </ul> | |
| 144 | + </div> | |
| 145 | + <?php | |
| 146 | + | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 123 | 150 | * Test the access token, if it exists. |
| 124 | 151 | * If the access token has been revoked or is invalid, remove it from the settings now. |
| 125 | 152 | * |
| 126 | 153 | * @since 2.5.0 |
| @@ -146,21 +173,12 @@ | ||
| 146 | 173 | ); |
| 147 | 174 | exit(); |
| 148 | 175 | } |
| 149 | 176 | |
| 150 | - // Initialize the API. | |
| 151 | - $this->api = new ConvertKit_API_V4( | |
| 152 | - CONVERTKIT_OAUTH_CLIENT_ID, | |
| 153 | - CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI, | |
| 154 | - $this->settings->get_access_token(), | |
| 155 | - $this->settings->get_refresh_token(), | |
| 156 | - $this->settings->debug_enabled(), | |
| 157 | - 'settings' | |
| 158 | - ); | |
| 159 | - | |
| 160 | 177 | // Get Account Details, which we'll use in account_name_callback(), but also lets us test |
| 161 | 178 | // whether the API credentials are valid. |
| 162 | - $this->account = $this->api->get_account(); | |
| 179 | + $account = new ConvertKit_Resource_Account(); | |
| 180 | + $this->account = $account->refresh(); | |
| 163 | 181 | |
| 164 | 182 | // If the request succeeded, no need to perform further actions. |
| 165 | 183 | if ( ! is_wp_error( $this->account ) ) { |
| 166 | 184 | return; |
| @@ -223,8 +241,9 @@ | ||
| 223 | 241 | return; |
| 224 | 242 | } |
| 225 | 243 | |
| 226 | 244 | // Delete cached resources. |
| 245 | + $account = new ConvertKit_Resource_Account(); | |
| 227 | 246 | $creator_network = new ConvertKit_Resource_Creator_Network_Recommendations(); |
| 228 | 247 | $custom_fields = new ConvertKit_Resource_Custom_Fields(); |
| 229 | 248 | $forms = new ConvertKit_Resource_Forms(); |
| 230 | 249 | $landing_pages = new ConvertKit_Resource_Landing_Pages(); |
| @@ -231,8 +250,9 @@ | ||
| 231 | 250 | $posts = new ConvertKit_Resource_Posts(); |
| 232 | 251 | $products = new ConvertKit_Resource_Products(); |
| 233 | 252 | $sequences = new ConvertKit_Resource_Sequences(); |
| 234 | 253 | $tags = new ConvertKit_Resource_Tags(); |
| 254 | + $account->delete(); | |
| 235 | 255 | $creator_network->delete(); |
| 236 | 256 | $custom_fields->delete(); |
| 237 | 257 | $forms->delete(); |
| 238 | 258 | $landing_pages->delete(); |
| @@ -408,8 +428,23 @@ | ||
| 408 | 428 | 'label_for' => 'non_inline_form_limit_per_session', |
| 409 | 429 | ) |
| 410 | 430 | ); |
| 411 | 431 | |
| 432 | + // Spam Protection. | |
| 433 | + add_settings_field( | |
| 434 | + 'spam_protection_provider', | |
| 435 | + __( 'Provider', 'convertkit' ), | |
| 436 | + array( $this, 'spam_protection_provider_callback' ), | |
| 437 | + $this->settings_key, | |
| 438 | + $this->name . '-spam-protection', | |
| 439 | + array( | |
| 440 | + 'label_for' => 'spam_protection_provider', | |
| 441 | + 'description' => array( | |
| 442 | + __( 'Select which spam protection service to use for the Member Content signup form and Form Builder block.', 'convertkit' ), | |
| 443 | + ), | |
| 444 | + ) | |
| 445 | + ); | |
| 446 | + | |
| 412 | 447 | // reCAPTCHA. |
| 413 | 448 | add_settings_field( |
| 414 | 449 | 'recaptcha_site_key', |
| 415 | 450 | __( 'reCAPTCHA: Site Key', 'convertkit' ), |
| @@ -414,11 +449,12 @@ | ||
| 414 | 449 | 'recaptcha_site_key', |
| 415 | 450 | __( 'reCAPTCHA: Site Key', 'convertkit' ), |
| 416 | 451 | array( $this, 'recaptcha_site_key_callback' ), |
| 417 | 452 | $this->settings_key, |
| 418 | - $this->name . '-recaptcha', | |
| 453 | + $this->name . '-spam-protection', | |
| 419 | 454 | array( |
| 420 | 455 | 'label_for' => 'recaptcha_site_key', |
| 456 | + 'class' => 'convertkit-spam-protection-recaptcha', | |
| 421 | 457 | 'description' => array( |
| 422 | 458 | __( 'Enter your Google reCAPTCHA v3 Site Key. When specified, this will be used to reduce spam signups.', 'convertkit' ), |
| 423 | 459 | ), |
| 424 | 460 | ) |
| @@ -427,11 +463,12 @@ | ||
| 427 | 463 | 'recaptcha_secret_key', |
| 428 | 464 | __( 'reCAPTCHA: Secret Key', 'convertkit' ), |
| 429 | 465 | array( $this, 'recaptcha_secret_key_callback' ), |
| 430 | 466 | $this->settings_key, |
| 431 | - $this->name . '-recaptcha', | |
| 467 | + $this->name . '-spam-protection', | |
| 432 | 468 | array( |
| 433 | 469 | 'label_for' => 'recaptcha_secret_key', |
| 470 | + 'class' => 'convertkit-spam-protection-recaptcha', | |
| 434 | 471 | 'description' => array( |
| 435 | 472 | __( 'Enter your Google reCAPTCHA v3 Secret Key. When specified, this will be used to reduce spam signups.', 'convertkit' ), |
| 436 | 473 | ), |
| 437 | 474 | ) |
| @@ -440,11 +477,12 @@ | ||
| 440 | 477 | 'recaptcha_minimum_score', |
| 441 | 478 | __( 'reCAPTCHA: Minimum Score', 'convertkit' ), |
| 442 | 479 | array( $this, 'recaptcha_minimum_score_callback' ), |
| 443 | 480 | $this->settings_key, |
| 444 | - $this->name . '-recaptcha', | |
| 481 | + $this->name . '-spam-protection', | |
| 445 | 482 | array( |
| 446 | 483 | 'label_for' => 'recaptcha_minimum_score', |
| 484 | + 'class' => 'convertkit-spam-protection-recaptcha', | |
| 447 | 485 | 'min' => 0, |
| 448 | 486 | 'max' => 1, |
| 449 | 487 | 'step' => 0.01, |
| 450 | 488 | 'description' => array( |
| @@ -452,8 +490,38 @@ | ||
| 452 | 490 | ), |
| 453 | 491 | ) |
| 454 | 492 | ); |
| 455 | 493 | |
| 494 | + // Cloudflare Turnstile. | |
| 495 | + add_settings_field( | |
| 496 | + 'cloudflare_turnstile_site_key', | |
| 497 | + __( 'Cloudflare Turnstile: Site Key', 'convertkit' ), | |
| 498 | + array( $this, 'cloudflare_turnstile_site_key_callback' ), | |
| 499 | + $this->settings_key, | |
| 500 | + $this->name . '-spam-protection', | |
| 501 | + array( | |
| 502 | + 'label_for' => 'cloudflare_turnstile_site_key', | |
| 503 | + 'class' => 'convertkit-spam-protection-cloudflare_turnstile', | |
| 504 | + 'description' => array( | |
| 505 | + __( 'Enter your Cloudflare Turnstile Site Key. When specified, this will be used to reduce spam signups.', 'convertkit' ), | |
| 506 | + ), | |
| 507 | + ) | |
| 508 | + ); | |
| 509 | + add_settings_field( | |
| 510 | + 'cloudflare_turnstile_secret_key', | |
| 511 | + __( 'Cloudflare Turnstile: Secret Key', 'convertkit' ), | |
| 512 | + array( $this, 'cloudflare_turnstile_secret_key_callback' ), | |
| 513 | + $this->settings_key, | |
| 514 | + $this->name . '-spam-protection', | |
| 515 | + array( | |
| 516 | + 'label_for' => 'cloudflare_turnstile_secret_key', | |
| 517 | + 'class' => 'convertkit-spam-protection-cloudflare_turnstile', | |
| 518 | + 'description' => array( | |
| 519 | + __( 'Enter your Cloudflare Turnstile Secret Key. When specified, this will be used to reduce spam signups.', 'convertkit' ), | |
| 520 | + ), | |
| 521 | + ) | |
| 522 | + ); | |
| 523 | + | |
| 456 | 524 | // Advanced. |
| 457 | 525 | add_settings_field( |
| 458 | 526 | 'debug', |
| 459 | 527 | __( 'Debug', 'convertkit' ), |
| @@ -546,15 +614,15 @@ | ||
| 546 | 614 | |
| 547 | 615 | } |
| 548 | 616 | |
| 549 | 617 | /** |
| 550 | - * Prints help info for the recaptcha section of the settings screen. | |
| 618 | + * Prints help info for the spam protection section of the settings screen. | |
| 551 | 619 | * |
| 552 | - * @since 3.0.0 | |
| 620 | + * @since 3.3.7 | |
| 553 | 621 | */ |
| 554 | - public function print_section_info_recaptcha() { | |
| 622 | + public function print_section_info_spam_protection() { | |
| 555 | 623 | ?> |
| 556 | - <p class="description"><?php esc_html_e( 'Configure reCAPTCHA to protect the Member Content signup form and Form Builder block from spam and abuse.', 'convertkit' ); ?></p> | |
| 624 | + <p class="description"><?php esc_html_e( 'Configure a spam protection service to protect the Member Content signup form and Form Builder block from spam and abuse. Choose a provider below, then enter the corresponding site and secret keys.', 'convertkit' ); ?></p> | |
| 557 | 625 | <?php |
| 558 | 626 | } |
| 559 | 627 | |
| 560 | 628 | /** |
| @@ -646,10 +714,21 @@ | ||
| 646 | 714 | if ( is_wp_error( $result ) ) { |
| 647 | 715 | return; |
| 648 | 716 | } |
| 649 | 717 | |
| 650 | - // Also refresh Landing Pages, Tags and Posts. Whilst not displayed in the Plugin Settings, this ensures up to date | |
| 718 | + // Also refresh other resources. Whilst not displayed in the Plugin Settings, this ensures up to date | |
| 651 | 719 | // lists are stored for when editing e.g. Pages. |
| 720 | + | |
| 721 | + // Refresh Custom Fields. | |
| 722 | + $custom_fields = new ConvertKit_Resource_Custom_Fields( 'settings' ); | |
| 723 | + $result = $custom_fields->refresh(); | |
| 724 | + | |
| 725 | + // Bail if an error occured. | |
| 726 | + if ( is_wp_error( $result ) ) { | |
| 727 | + return; | |
| 728 | + } | |
| 729 | + | |
| 730 | + // Refresh Landing Pages. | |
| 652 | 731 | $landing_pages = new ConvertKit_Resource_Landing_Pages( 'settings' ); |
| 653 | 732 | $result = $landing_pages->refresh(); |
| 654 | 733 | |
| 655 | 734 | // Bail if an error occured. |
| @@ -656,8 +735,9 @@ | ||
| 656 | 735 | if ( is_wp_error( $result ) ) { |
| 657 | 736 | return; |
| 658 | 737 | } |
| 659 | 738 | |
| 739 | + // Refresh Posts. | |
| 660 | 740 | remove_all_actions( 'convertkit_resource_refreshed_posts' ); |
| 661 | 741 | $posts = new ConvertKit_Resource_Posts( 'settings' ); |
| 662 | 742 | $result = $posts->refresh(); |
| 663 | 743 | |
| @@ -665,8 +745,9 @@ | ||
| 665 | 745 | if ( is_wp_error( $result ) ) { |
| 666 | 746 | return; |
| 667 | 747 | } |
| 668 | 748 | |
| 749 | + // Refresh Products. | |
| 669 | 750 | $products = new ConvertKit_Resource_Products( 'settings' ); |
| 670 | 751 | $result = $products->refresh(); |
| 671 | 752 | |
| 672 | 753 | // Bail if an error occured. |
| @@ -673,8 +754,9 @@ | ||
| 673 | 754 | if ( is_wp_error( $result ) ) { |
| 674 | 755 | return; |
| 675 | 756 | } |
| 676 | 757 | |
| 758 | + // Refresh Sequences. | |
| 677 | 759 | $sequences = new ConvertKit_Resource_Sequences( 'settings' ); |
| 678 | 760 | $result = $sequences->refresh(); |
| 679 | 761 | |
| 680 | 762 | // Bail if an error occured. |
| @@ -681,8 +763,9 @@ | ||
| 681 | 763 | if ( is_wp_error( $result ) ) { |
| 682 | 764 | return; |
| 683 | 765 | } |
| 684 | 766 | |
| 767 | + // Refresh Tags. | |
| 685 | 768 | $tags = new ConvertKit_Resource_Tags( 'settings' ); |
| 686 | 769 | $result = $tags->refresh(); |
| 687 | 770 | |
| 688 | 771 | // Bail if an error occured. |
| @@ -919,8 +1002,31 @@ | ||
| 919 | 1002 | |
| 920 | 1003 | } |
| 921 | 1004 | |
| 922 | 1005 | /** |
| 1006 | + * Renders the dropdown for choosing the active spam protection provider. | |
| 1007 | + * | |
| 1008 | + * @since 3.3.7 | |
| 1009 | + * | |
| 1010 | + * @param array $args Setting field arguments (name,description). | |
| 1011 | + */ | |
| 1012 | + public function spam_protection_provider_callback( $args ) { | |
| 1013 | + | |
| 1014 | + $this->output_select_field( | |
| 1015 | + 'spam_protection_provider', | |
| 1016 | + esc_attr( $this->settings->spam_protection_provider() ), | |
| 1017 | + array( | |
| 1018 | + 'recaptcha' => esc_html__( 'Google reCAPTCHA v3', 'convertkit' ), | |
| 1019 | + 'cloudflare_turnstile' => esc_html__( 'Cloudflare Turnstile', 'convertkit' ), | |
| 1020 | + ), | |
| 1021 | + $args['description'], | |
| 1022 | + array( 'convertkit-conditional-display' ), | |
| 1023 | + array( 'data-conditional-class-prefix' => 'convertkit-spam-protection-' ) | |
| 1024 | + ); | |
| 1025 | + | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + /** | |
| 923 | 1029 | * Renders the input for the reCAPTCHA Site Key setting. |
| 924 | 1030 | * |
| 925 | 1031 | * @since 3.0.0 |
| 926 | 1032 | * |
| @@ -976,8 +1082,48 @@ | ||
| 976 | 1082 | esc_attr( (string) $this->settings->recaptcha_minimum_score() ), |
| 977 | 1083 | $args['min'], |
| 978 | 1084 | $args['max'], |
| 979 | 1085 | $args['step'], |
| 1086 | + $args['description'], | |
| 1087 | + array( | |
| 1088 | + 'widefat', | |
| 1089 | + ) | |
| 1090 | + ); | |
| 1091 | + | |
| 1092 | + } | |
| 1093 | + | |
| 1094 | + /** | |
| 1095 | + * Renders the input for the Cloudflare Turnstile Site Key setting. | |
| 1096 | + * | |
| 1097 | + * @since 3.3.7 | |
| 1098 | + * | |
| 1099 | + * @param array $args Setting field arguments (name,description). | |
| 1100 | + */ | |
| 1101 | + public function cloudflare_turnstile_site_key_callback( $args ) { | |
| 1102 | + | |
| 1103 | + $this->output_text_field( | |
| 1104 | + 'cloudflare_turnstile_site_key', | |
| 1105 | + esc_attr( $this->settings->cloudflare_turnstile_site_key() ), | |
| 1106 | + $args['description'], | |
| 1107 | + array( | |
| 1108 | + 'widefat', | |
| 1109 | + ) | |
| 1110 | + ); | |
| 1111 | + | |
| 1112 | + } | |
| 1113 | + | |
| 1114 | + /** | |
| 1115 | + * Renders the input for the Cloudflare Turnstile Secret Key setting. | |
| 1116 | + * | |
| 1117 | + * @since 3.3.7 | |
| 1118 | + * | |
| 1119 | + * @param array $args Setting field arguments (name,description). | |
| 1120 | + */ | |
| 1121 | + public function cloudflare_turnstile_secret_key_callback( $args ) { | |
| 1122 | + | |
| 1123 | + $this->output_text_field( | |
| 1124 | + 'cloudflare_turnstile_secret_key', | |
| 1125 | + esc_attr( $this->settings->cloudflare_turnstile_secret_key() ), | |
| 980 | 1126 | $args['description'], |
| 981 | 1127 | array( |
| 982 | 1128 | 'widefat', |
| 983 | 1129 | ) |