From 7f63c03a8a4e85bee6875f15f7ac709484256e73 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 29 Jul 2026 11:12:21 +0800 Subject: [PATCH] Form Builder: Check for Access Token --- .../class-convertkit-block-form-builder.php | 12 ++++++- .../PageBlockFormBuilderCest.php | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/includes/blocks/class-convertkit-block-form-builder.php b/includes/blocks/class-convertkit-block-form-builder.php index 16833a0fd..04552ad09 100644 --- a/includes/blocks/class-convertkit-block-form-builder.php +++ b/includes/blocks/class-convertkit-block-form-builder.php @@ -401,8 +401,18 @@ public function get_overview() { ), ), + // Help descriptions, displayed when no Access Token / resources exist and this block/shortcode is added. + 'no_access_token' => array( + 'notice' => __( 'Not connected to Kit.', 'convertkit' ), + 'link' => convertkit_get_setup_wizard_plugin_link(), + 'link_text' => __( 'Click here to connect your Kit account.', 'convertkit' ), + 'instruction_text' => __( 'Connect your Kit account at Settings > Kit, and then refresh this page to configure this block.', 'convertkit' ), + ), + 'has_access_token' => $settings->has_access_and_refresh_token(), - 'has_resources' => $convertkit_forms->exist(), + + // This block works without resources, so we don't need to check if resources exist. + 'has_resources' => true, ); } diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php index cd0c88202..02bbb5ce9 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php @@ -23,6 +23,40 @@ public function _before(EndToEndTester $I) $I->activateKitPlugin($I); } + /** + * Test the Form Builder block displays a message with a link that opens + * a popup window with the Plugin's Setup Wizard, when the Plugin has + * Not connected to Kit. + * + * @since 3.4.0 + * + * @param EndToEndTester $I Tester. + */ + public function testFormBuilderBlockWhenNoCredentials(EndToEndTester $I) + { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form Builder: Block: No Credentials' + ); + + // Add block to Page. + $I->addGutenbergBlock( + $I, + blockName: 'Kit Form Builder', + blockProgrammaticName: 'convertkit-form-builder' + ); + + // Test that the popup window works. + $I->testBlockNoCredentialsPopupWindow( + $I, + blockName: 'convertkit-form-builder' + ); + + // Save page to avoid a browser alert when _passed() runs to deactivate the Plugin. + $I->publishGutenbergPage($I); + } + /** * Test the Form Builder block's conditional fields work. *