Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ck_subscriber_id Notice #756

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions admin/class-convertkit-admin-cache-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function maybe_configure_cache_plugins() {
$this->w3_total_cache();
$this->wp_fastest_cache();
$this->wp_optimize();
$this->wp_rocket();
$this->wp_super_cache();

}
Expand Down Expand Up @@ -284,6 +285,40 @@ public function wp_optimize() {

}

/**
* Add a rule to WP Rocket to prevent caching when
* the ck_subscriber_id cookie is present.
*
* @since 2.7.0
*/
public function wp_rocket() {

// Bail if the WP Rocket plugin is not active.
if ( ! is_plugin_active( 'wp-rocket/wp-rocket.php' ) ) {
return;
}

// Sanity check that we can access WP-Optimize's configuration class.
if ( ! function_exists( 'update_rocket_option' ) ) {
return;
}

// Fetch settings.
$settings = get_rocket_option( 'cache_reject_cookies', array() );

// If the cookie exception exists, no need to modify anything.
if ( in_array( $this->key, $settings, true ) ) {
return;
}

// Add cookie to exceptions.
$settings[] = $this->key;

// Update configuration to include excluding caching for the ck_subscriber_id cookie.
update_rocket_option( 'cache_reject_cookies', $settings );

}

/**
* Show a notice in the WordPress Administration interface if
* WP Super Cache is active, its caching enabled and no rule to disable caching
Expand Down
12 changes: 0 additions & 12 deletions admin/class-convertkit-admin-settings-restrict-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,6 @@ public function print_section_info() {

?>
<p class="description"><?php esc_html_e( 'Defines the text and button labels to display when a Page, Post or Custom Post has its Member Content setting defined.', 'convertkit' ); ?></p>
<div class="notice notice-warning">
<p>
<?php
printf(
'%s %s %s',
esc_html__( 'If your web host has caching configured (or you are using a caching plugin), you must configure it to disable caching when the', 'convertkit' ),
'<code>ck_subscriber_id</code>',
esc_html__( 'cookie is present. Failing to do so will result in errors.', 'convertkit' )
);
?>
</p>
</div>
<?php

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,46 @@ public function testRestrictContentWPSuperCache(AcceptanceTester $I)
$I->deactivateThirdPartyPlugin($I, 'wp-super-cache');
}

/**
* Tests that the WP RocketPlugin does not interfere with Restrict Content
* output when a ck_subscriber_id cookie is present.
*
* @since 2.7.0
*
* @param AcceptanceTester $I Tester.
*/
public function testRestrictContentWPRocketCache(AcceptanceTester $I)
{
// Activate WP Rocket Plugin.
$I->activateThirdPartyPlugin($I, 'wp-rocket');

// Create Restricted Content Page.
$pageID = $I->createRestrictedContentPage(
$I,
[
'post_title' => 'Kit: Restrict Content: Product: WP Rocket',
'restrict_content_setting' => 'product_' . $_ENV['CONVERTKIT_API_PRODUCT_ID'],
]
);

// Log out, so that caching is honored.
$I->logOut();

// Navigate to the page.
$I->amOnPage('?p=' . $pageID);

// Test that the restricted content CTA displays when no valid signed subscriber ID is used,
// to confirm caching does not show member-only content.
$I->testRestrictContentByProductHidesContentWithCTA($I);

// Test that the restricted content displays when a valid signed subscriber ID is used,
// to confirm caching does not show the incorrect content.
$I->testRestrictedContentShowsContentWithValidSubscriberID($I, $pageID);

// Deactivate WP Super Cache Plugin.
$I->deactivateThirdPartyPlugin($I, 'wp-rocket');
}

/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
Expand Down