From 78af4af6fdc7bf15c408838060b4f26cced93a96 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 20 Nov 2024 18:06:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Add=20=E2=80=98None=E2=80=99=20support=20fo?= =?UTF-8?q?r=20Category=20Form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-convertkit-output.php | 8 +++++++- includes/class-convertkit-term.php | 13 +++++++++++++ views/backend/term/fields-add.php | 4 ++++ views/backend/term/fields-edit.php | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/includes/class-convertkit-output.php b/includes/class-convertkit-output.php index 69cb16bb..e6d4df15 100644 --- a/includes/class-convertkit-output.php +++ b/includes/class-convertkit-output.php @@ -652,9 +652,15 @@ private function get_post_form_id( $post_id ) { if ( $term_settings->has_form() ) { return $term_settings->get_form(); } + + // If the Term specifies that no Form should be used, return false. + if ( $term_settings->uses_no_form() ) { + return false; + } } - // If here, use the Plugin's Default Form. + // If here, all Terms were set to display the Default Form. + // Therefore use the Plugin's Default Form. return $this->settings->get_default_form( get_post_type( $post_id ) ); } diff --git a/includes/class-convertkit-term.php b/includes/class-convertkit-term.php index 7c99bbaa..57278919 100644 --- a/includes/class-convertkit-term.php +++ b/includes/class-convertkit-term.php @@ -113,6 +113,19 @@ public function uses_default_form() { } + /** + * Whether the Post's Form setting is set to 'None' + * + * @since 2.6.6 + * + * @return bool + */ + public function uses_no_form() { + + return ( $this->settings['form'] === 0 ); + + } + /** * Returns the form position setting for the Term * on the Term archive. diff --git a/views/backend/term/fields-add.php b/views/backend/term/fields-add.php index 21d58bb8..fb46ace4 100644 --- a/views/backend/term/fields-add.php +++ b/views/backend/term/fields-add.php @@ -21,6 +21,7 @@ '-1', array( '-1' => esc_html__( 'Default', 'convertkit' ), + '0' => esc_html__( 'None', 'convertkit' ), ) ); ?> @@ -32,6 +33,9 @@
+ + +
get_form() ), array( '-1' => esc_html__( 'Default', 'convertkit' ), + '0' => esc_html__( 'None', 'convertkit' ), ) ); ?> @@ -34,6 +35,9 @@
+ + +
Date: Wed, 20 Nov 2024 18:22:37 +0800 Subject: [PATCH 2/5] Added Tests --- .../forms/general/CategoryFormCest.php | 131 ++++++++++++++++++ views/backend/term/fields-add.php | 2 +- views/backend/term/fields-edit.php | 2 +- 3 files changed, 133 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/forms/general/CategoryFormCest.php b/tests/acceptance/forms/general/CategoryFormCest.php index 134e4711..a07802f0 100644 --- a/tests/acceptance/forms/general/CategoryFormCest.php +++ b/tests/acceptance/forms/general/CategoryFormCest.php @@ -82,6 +82,67 @@ public function testAddCategoryWithValidFormSetting(AcceptanceTester $I) $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID']); } + /** + * Test that no Form is displayed when the user: + * - Creates a Category in WordPress, selecting 'None' as the ConvertKit Form to display, + * - Creates a WordPress Post assigned to the created Category. + * + * @since 2.6.6 + * + * @param AcceptanceTester $I Tester. + */ + public function testAddCategoryWithNoFormSetting(AcceptanceTester $I) + { + // Navigate to Posts > Categories. + $I->amOnAdminPage('edit-tags.php?taxonomy=category'); + + // Confirm that settings have label[for] attributes. + $I->seeInSource('