Skip to content

Commit

Permalink
Merge pull request #651 from ConvertKit/restrict-content-frontend-pag…
Browse files Browse the repository at this point in the history
…e-builders

Member Content: Display Content when using Frontend Page Builder
  • Loading branch information
n7studios authored Apr 9, 2024
2 parents 35dd063 + 91a3766 commit 711f34e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions includes/class-convertkit-output-restrict-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,60 @@ 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');

// Deactivate Beaver Builder Lite.
$I->deactivateThirdPartyPlugin($I, 'beaver-builder-lite-version');
}

/**
* Test that search engines can access Restrict Content.
*
Expand Down

0 comments on commit 711f34e

Please sign in to comment.