From db81f3d5f71b01959494dc94dbb3060c213ff877 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 10 Aug 2026 12:04:22 +0800 Subject: [PATCH 1/2] Settings: Legacy Forms: Add Warning Notice --- ...onvertkit-admin-legacy-resource-notice.php | 43 +++++++++++++++++++ ...class-convertkit-admin-section-general.php | 36 ++++++++++++++++ .../general/other/LegacyFormDropdownCest.php | 30 +++++++++++++ .../AdminLegacyResourceNoticeTest.php | 36 ++++++++++++++++ 4 files changed, 145 insertions(+) diff --git a/admin/class-convertkit-admin-legacy-resource-notice.php b/admin/class-convertkit-admin-legacy-resource-notice.php index 547ca151c..d1b7e1821 100644 --- a/admin/class-convertkit-admin-legacy-resource-notice.php +++ b/admin/class-convertkit-admin-legacy-resource-notice.php @@ -216,6 +216,49 @@ public function get_legacy_warnings_for_settings( $settings ) { } + /** + * Returns an array of warning strings for the Plugin's General Settings, + * when one or more Default Form settings reference Legacy Forms. + * + * @since 3.3.9 + * + * @param array $settings Plugin settings array. + * @return array + */ + public function get_legacy_warnings_for_plugin_settings( $settings ) { + + // Get Forms resource. + $forms = new ConvertKit_Resource_Forms(); + + // Initialize warnings array. + $warnings = array(); + + // Check each supported Post Type's Default Form setting. + foreach ( convertkit_get_supported_post_types() as $supported_post_type ) { + // Get Post Type object. + $post_type = get_post_type_object( $supported_post_type ); + if ( ! $post_type ) { + continue; + } + + // Get Default Form setting. + $setting_key = $supported_post_type . '_form'; + if ( empty( $settings[ $setting_key ] ) || ! $forms->is_legacy( $settings[ $setting_key ] ) ) { + continue; + } + + $warnings[] = sprintf( + /* translators: 1: Post Type name, plural; 2: Form name */ + __( 'Default Form (%1$s): %2$s', 'convertkit' ), + $post_type->label, + $this->get_form_display_name( $settings[ $setting_key ], $forms ) + ); + } + + return $warnings; + + } + /** * Resolves the form ID to a human-readable "Form Name" string, falling * back to "a Legacy Form" when the resource isn't cached. diff --git a/admin/section/class-convertkit-admin-section-general.php b/admin/section/class-convertkit-admin-section-general.php index 17a4ec3a6..5ee1063e9 100644 --- a/admin/section/class-convertkit-admin-section-general.php +++ b/admin/section/class-convertkit-admin-section-general.php @@ -78,6 +78,7 @@ public function __construct() { if ( $this->on_settings_screen( $this->name ) ) { add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) ); add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) ); + add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_legacy_form_notice' ) ); } // Enqueue scripts and CSS. @@ -110,6 +111,41 @@ public function register_notices( $notices ) { } + /** + * Outputs a non-dismissible warning when one or more Default Form settings + * reference Legacy Forms. + * + * @since 3.3.9 + */ + public function maybe_output_legacy_form_notice() { + + // Get warnings. + $warnings = WP_ConvertKit()->get_class( 'admin_legacy_resource_notice' )->get_legacy_warnings_for_plugin_settings( $this->settings->get() ); + + // Bail if no warnings are found. + if ( empty( $warnings ) ) { + return; + } + + // Output warnings. + ?> +
+

+ : + +

+ +
+ Kit > General when one or + * more Default Form settings reference a Legacy Form. + * + * @since 3.3.9 + * + * @param EndToEndTester $I Tester. + */ + public function testWarningDisplayedForLegacyDefaultFormsSetting(EndToEndTester $I) + { + // Setup Plugin with a legacy form pre-assigned as the Default Form for + // both Pages and Posts, as would be the case for an upgraded install. + $I->setupKitPlugin( + $I, + [ + 'page_form' => (string) $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'post_form' => (string) $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + ] + ); + $I->setupKitPluginResources($I); + + // Go to the Plugin's Settings Screen. + $I->loadKitSettingsGeneralScreen($I); + + // Confirm the warning identifies each affected Default Form setting. + $I->seeElementInDOM('#convertkit-legacy-settings-warning'); + $I->see('Default Form (Pages): ' . $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], '#convertkit-legacy-settings-warning'); + $I->see('Default Form (Posts): ' . $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], '#convertkit-legacy-settings-warning'); + } + /** * Test that a previously-saved legacy Form ID assigned to a Category * term continues to render as the selected option in the term edit diff --git a/tests/Integration/AdminLegacyResourceNoticeTest.php b/tests/Integration/AdminLegacyResourceNoticeTest.php index 6b1240b04..a2439bc02 100644 --- a/tests/Integration/AdminLegacyResourceNoticeTest.php +++ b/tests/Integration/AdminLegacyResourceNoticeTest.php @@ -97,6 +97,42 @@ public function testWarningForLegacyForm() $this->assertStringContainsString($_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], $warnings[0]); } + /** + * Test that a legacy Default Form setting produces a warning containing + * the Post Type label and Form name. + * + * @since 3.3.9 + */ + public function testWarningForLegacyPluginDefaultForm() + { + $warnings = $this->notice->get_legacy_warnings_for_plugin_settings( + [ + 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + ] + ); + + $this->assertCount(1, $warnings); + $this->assertStringContainsString('Default Form (Pages):', $warnings[0]); + $this->assertStringContainsString($_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], $warnings[0]); + } + + /** + * Test that current and empty Default Form settings do not produce warnings. + * + * @since 3.3.7 + */ + public function testNoWarningForCurrentOrEmptyPluginDefaultForms() + { + $warnings = $this->notice->get_legacy_warnings_for_plugin_settings( + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form' => 0, + ] + ); + + $this->assertSame([], $warnings); + } + /** * Test that a legacy landing page assignment (by numeric ID) produces * a landing-page-scoped warning containing the landing page's name. From 9bce2e495d390e259d6f0d3d45bb99b05356ee27 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 10 Aug 2026 12:25:17 +0800 Subject: [PATCH 2/2] Update tests --- .../general/other/LegacyFormDropdownCest.php | 16 ++++++++++++++++ .../AdminLegacyResourceNoticeTest.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/EndToEnd/general/other/LegacyFormDropdownCest.php b/tests/EndToEnd/general/other/LegacyFormDropdownCest.php index 480777484..ccf7047f5 100644 --- a/tests/EndToEnd/general/other/LegacyFormDropdownCest.php +++ b/tests/EndToEnd/general/other/LegacyFormDropdownCest.php @@ -125,6 +125,22 @@ public function testWarningDisplayedForLegacyDefaultFormsSetting(EndToEndTester $I->seeElementInDOM('#convertkit-legacy-settings-warning'); $I->see('Default Form (Pages): ' . $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], '#convertkit-legacy-settings-warning'); $I->see('Default Form (Posts): ' . $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'], '#convertkit-legacy-settings-warning'); + + // Replace the Legacy Forms with a current Kit Form and save the settings. + $I->fillSelect2Field( + $I, + container: '#select2-_wp_convertkit_settings_page_form-container', + value: $_ENV['CONVERTKIT_API_FORM_NAME'] + ); + $I->fillSelect2Field( + $I, + container: '#select2-_wp_convertkit_settings_post_form-container', + value: $_ENV['CONVERTKIT_API_FORM_NAME'] + ); + $I->click('Save Changes'); + + // Confirm the warning is no longer displayed. + $I->waitForElementNotVisible('#convertkit-legacy-settings-warning'); } /** diff --git a/tests/Integration/AdminLegacyResourceNoticeTest.php b/tests/Integration/AdminLegacyResourceNoticeTest.php index a2439bc02..e4cbba2ac 100644 --- a/tests/Integration/AdminLegacyResourceNoticeTest.php +++ b/tests/Integration/AdminLegacyResourceNoticeTest.php @@ -117,11 +117,11 @@ public function testWarningForLegacyPluginDefaultForm() } /** - * Test that current and empty Default Form settings do not produce warnings. + * Test that Plugin settings with no Legacy Forms do not produce warnings. * * @since 3.3.7 */ - public function testNoWarningForCurrentOrEmptyPluginDefaultForms() + public function testNoWarningForPluginSettingsWithoutLegacyForms() { $warnings = $this->notice->get_legacy_warnings_for_plugin_settings( [