From 4fff29bec9be6923c6aa1bf1dc610b4ee50ea258 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 8 Apr 2024 15:38:45 +0100 Subject: [PATCH 1/2] Display Member Content when a logged in user has the capability to edit a Page through a frontend page builder --- .github/workflows/tests.yml | 2 +- ...ass-convertkit-output-restrict-content.php | 8 +++ .../RestrictContentProductPageCest.php | 51 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a109c0959..85940db43 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: DB_USER: root DB_PASS: root DB_HOST: localhost - INSTALL_PLUGINS: "admin-menu-editor contact-form-7 classic-editor custom-post-type-ui disable-welcome-messages-and-tips elementor forminator jetpack-boost woocommerce wordpress-seo wpforms-lite litespeed-cache wp-crontrol wp-super-cache w3-total-cache wp-fastest-cache wp-optimize sg-cachepress" # Don't include this repository's Plugin here. + INSTALL_PLUGINS: "admin-menu-editor beaver-builder-lite-version contact-form-7 classic-editor custom-post-type-ui disable-welcome-messages-and-tips elementor forminator jetpack-boost woocommerce wordpress-seo wpforms-lite litespeed-cache wp-crontrol wp-super-cache w3-total-cache wp-fastest-cache wp-optimize sg-cachepress" # Don't include this repository's Plugin here. INSTALL_PLUGINS_URLS: "https://downloads.wordpress.org/plugin/convertkit-for-woocommerce.1.6.4.zip http://cktestplugins.wpengine.com/wp-content/uploads/2024/01/convertkit-action-filter-tests.zip" # URLs to specific third party Plugins CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets CONVERTKIT_API_SECRET: ${{ secrets.CONVERTKIT_API_SECRET }} # ConvertKit API Secret, stored in the repository's Settings > Secrets diff --git a/includes/class-convertkit-output-restrict-content.php b/includes/class-convertkit-output-restrict-content.php index 589d8555a..08efff1f9 100644 --- a/includes/class-convertkit-output-restrict-content.php +++ b/includes/class-convertkit-output-restrict-content.php @@ -310,6 +310,14 @@ public function maybe_restrict_content( $content ) { return $content; } + // Bail if the Page is being edited in a frontend Page Builder / Editor by a logged + // in WordPress user who has the capability to edit the Page. + // This ensures the User can view all content to edit it, instead of seeing the Restrict Content + // view. + if ( current_user_can( 'edit_post', get_the_ID() ) && WP_ConvertKit()->is_admin_or_frontend_editor() ) { + return $content; + } + // Get resource type (Product or Tag) that the visitor must be subscribed against to access this content. $this->resource_type = $this->get_resource_type(); diff --git a/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php b/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php index b30d9dc93..9ce347558 100644 --- a/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php +++ b/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php @@ -206,6 +206,57 @@ public function testRestrictContentByInvalidProduct(AcceptanceTester $I) $I->testRestrictContentDisplaysContent($I); } + /** + * Test that content is displayed when the Page is being edited in a frontend + * Page Builder / Editor by a logged in WordPress user who has the capability + * to edit the Page. + * + * @since 2.4.8 + * + * @param AcceptanceTester $I Tester. + */ + public function testRestrictContentWhenEditingWithFrontendPageBuilder(AcceptanceTester $I) + { + // Setup ConvertKit Plugin, disabling JS. + $I->setupConvertKitPluginDisableJS($I); + + // Activate Beaver Builder Lite, a frontend Page Builder. + $I->activateThirdPartyPlugin($I, 'beaver-builder-lite-version'); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage($I, 'page', 'ConvertKit: Page: Restrict Content: Beaver Builder'); + + // Configure metabox's Restrict Content setting = Product name. + $I->configureMetaboxSettings( + $I, + 'wp-convertkit-meta-box', + [ + 'form' => [ 'select2', 'None' ], + 'restrict_content' => [ 'select2', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ], + ] + ); + + // Publish Page. + $url = $I->publishGutenbergPage($I); + + // Edit Page in Beaver Builder. + $I->amOnUrl($url . '?fl_builder&fl_builder_ui'); + + // Confirm that the CTA is not displayed. + $I->dontSeeElementInDOM('#convertkit-restrict-content'); + + // Log out. + $I->logOut(); + + // Attempt to edit Page in Beaver Builder. + // Beaver Builder won't load as we're not logged in. + $I->amOnUrl($url . '?fl_builder&fl_builder_ui'); + + // Check content is not displayed, and CTA displays with expected text, + // as we are not logged in. + $I->seeElementInDOM('#convertkit-restrict-content'); + } + /** * Test that search engines can access Restrict Content. * From 91a376683a4e19524b36c7b77672c9f4d70120bb Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 8 Apr 2024 16:47:05 +0100 Subject: [PATCH 2/2] Tests: Deactivate Beaver Builder --- .../post-types/RestrictContentProductPageCest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php b/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php index 9ce347558..b185feb70 100644 --- a/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php +++ b/tests/acceptance/restrict-content/post-types/RestrictContentProductPageCest.php @@ -255,6 +255,9 @@ public function testRestrictContentWhenEditingWithFrontendPageBuilder(Acceptance // Check content is not displayed, and CTA displays with expected text, // as we are not logged in. $I->seeElementInDOM('#convertkit-restrict-content'); + + // Deactivate Beaver Builder Lite. + $I->deactivateThirdPartyPlugin($I, 'beaver-builder-lite-version'); } /**