Skip to content

Commit

Permalink
Add support for WP Super Cache and Boost Cache (#35598)
Browse files Browse the repository at this point in the history
* Add support for WP Super Cache and Boost Cache

* Fix string

* Prevent redefining a constant

---------

Co-authored-by: Fabien MILLERAND <[email protected]>
  • Loading branch information
2 people authored and spsiddarthan committed Feb 15, 2024
1 parent 46b7cd2 commit 17ca74e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

Add support for WP Super Cache and Boost Cache
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ function ( $allowed_meta ) {
add_action( 'manage_post_posts_custom_column', __NAMESPACE__ . '\render_newsletter_access_rows', 10, 2 );
add_action( 'admin_head', __NAMESPACE__ . '\newsletter_access_column_styles' );
}

add_action( 'init', __NAMESPACE__ . '\maybe_prevent_super_cache_caching' );
}
add_action( 'init', __NAMESPACE__ . '\register_block', 9 );

Expand Down Expand Up @@ -895,6 +897,32 @@ function maybe_gate_existing_comments( $comment ) {
return '';
}

/**
* Is the Jetpack_Token_Subscription_Service class loaded
*
* @return bool
*/
function is_jetpack_token_subscription_service_loaded(): bool {
return class_exists( 'Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service' );
}

/**
* Adds support for WP Super cache and Boost cache
*/
function maybe_prevent_super_cache_caching() {
// Prevents cached page to be served if the Membership cookie is present
if ( is_jetpack_token_subscription_service_loaded() ) {
do_action( 'wpsc_add_cookie', Jetpack_Token_Subscription_Service::JWT_AUTH_TOKEN_COOKIE_NAME );
}

if ( is_user_auth() ) {
// Do not cache the page if user is auth with Membership token
if ( ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', true );
}
}
}

/**
* Returns paywall content blocks
*
Expand Down Expand Up @@ -1111,16 +1139,17 @@ function get_paywall_access_question( $post_access_level ) {
/**
* Returns true if user is auth for subscriptions check, otherwise returns false.
*
* @return boolean
* @return bool
*/
function is_user_auth() {
function is_user_auth(): bool {
if ( ( new Host() )->is_wpcom_simple() && is_user_logged_in() ) {
return true;
}
if ( current_user_can( 'manage_options' ) ) {
return true;
}
if ( class_exists( 'Automattic\Jetpack\Extensions\Premium_Content\Subscription_Service\Jetpack_Token_Subscription_Service' ) ) {

if ( is_jetpack_token_subscription_service_loaded() ) {
if ( Jetpack_Token_Subscription_Service::has_token_from_cookie() ) {
return true;
}
Expand Down

0 comments on commit 17ca74e

Please sign in to comment.