| @@ -53,11 +53,11 @@ | ||
| 53 | 53 | * @since 2.2.2 |
| 54 | 54 | */ |
| 55 | 55 | public function maybe_configure_cache_plugins() { |
| 56 | 56 | |
| 57 | - // Bail if Restrict Content is disabled. | |
| 58 | - $restrict_content_settings = new ConvertKit_Settings_Restrict_Content(); | |
| 59 | - if ( ! $restrict_content_settings->enabled() ) { | |
| 57 | + // If no Pages, Posts or CPTs are configured to use Restrict Content, don't | |
| 58 | + // configure any caching plugins. | |
| 59 | + if ( ! $this->restrict_content_enabled() ) { | |
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $this->litespeed_cache(); |
| @@ -63,13 +63,49 @@ | ||
| 63 | 63 | $this->litespeed_cache(); |
| 64 | 64 | $this->w3_total_cache(); |
| 65 | 65 | $this->wp_fastest_cache(); |
| 66 | 66 | $this->wp_optimize(); |
| 67 | + $this->wp_rocket(); | |
| 67 | 68 | $this->wp_super_cache(); |
| 68 | 69 | |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | /** |
| 73 | + * Check if any Pages, Posts or CPTs are configured to use Restrict Content. | |
| 74 | + * | |
| 75 | + * @since 2.7.6 | |
| 76 | + * | |
| 77 | + * @return bool | |
| 78 | + */ | |
| 79 | + private function restrict_content_enabled() { | |
| 80 | + | |
| 81 | + // Check if any Pages, Posts or CPTs are configured to use Restrict Content. | |
| 82 | + $query = new WP_Query( | |
| 83 | + array( | |
| 84 | + 'post_type' => convertkit_get_supported_post_types(), | |
| 85 | + 'post_status' => 'publish', | |
| 86 | + 'meta_query' => array( | |
| 87 | + array( | |
| 88 | + 'key' => '_wp_convertkit_post_meta', | |
| 89 | + 'value' => '"restrict_content";', | |
| 90 | + 'compare' => 'LIKE', | |
| 91 | + ), | |
| 92 | + array( | |
| 93 | + 'key' => '_wp_convertkit_post_meta', | |
| 94 | + 'value' => '"restrict_content";s:1:"0"', | |
| 95 | + 'compare' => 'NOT LIKE', | |
| 96 | + ), | |
| 97 | + ), | |
| 98 | + 'posts_per_page' => 1, | |
| 99 | + 'fields' => 'ids', | |
| 100 | + ) | |
| 101 | + ); | |
| 102 | + | |
| 103 | + return $query->have_posts(); | |
| 104 | + | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 72 | 108 | * Show a notice in the WordPress Administration interface if |
| 73 | 109 | * Litespeed Cache is active, its caching enabled and no rule to disable caching |
| 74 | 110 | * exists when the ck_subscriber_id cookie is present. |
| 75 | 111 | * |
| @@ -117,9 +153,9 @@ | ||
| 117 | 153 | public function litespeed_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 118 | 154 | |
| 119 | 155 | return sprintf( |
| 120 | 156 | '%s %s %s %s', |
| 121 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 157 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 122 | 158 | '<code>ck_subscriber_id</code>', |
| 123 | 159 | sprintf( |
| 124 | 160 | '<a href="%s">%s</a>', |
| 125 | 161 | esc_url( |
| @@ -188,9 +224,9 @@ | ||
| 188 | 224 | public function w3_total_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 189 | 225 | |
| 190 | 226 | return sprintf( |
| 191 | 227 | '%s %s %s %s', |
| 192 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 228 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 193 | 229 | '<code>ck_subscriber_id</code>', |
| 194 | 230 | sprintf( |
| 195 | 231 | '<a href="%s">%s</a>', |
| 196 | 232 | esc_url( |
| @@ -271,13 +307,8 @@ | ||
| 271 | 307 | // Fetch settings. |
| 272 | 308 | $config = new WPO_Cache_Config(); |
| 273 | 309 | $settings = $config->get(); |
| 274 | 310 | |
| 275 | - // Check that we received an array of settings. | |
| 276 | - if ( ! is_array( $settings ) ) { | |
| 277 | - return; | |
| 278 | - } | |
| 279 | - | |
| 280 | 311 | // Check the exception cookies array key exists in the settings. |
| 281 | 312 | if ( ! array_key_exists( 'cache_exception_cookies', $settings ) ) { |
| 282 | 313 | $settings['cache_exception_cookies'] = array(); |
| 283 | 314 | } |
| @@ -295,8 +326,42 @@ | ||
| 295 | 326 | |
| 296 | 327 | } |
| 297 | 328 | |
| 298 | 329 | /** |
| 330 | + * Add a rule to WP Rocket to prevent caching when | |
| 331 | + * the ck_subscriber_id cookie is present. | |
| 332 | + * | |
| 333 | + * @since 2.7.0 | |
| 334 | + */ | |
| 335 | + public function wp_rocket() { | |
| 336 | + | |
| 337 | + // Bail if the WP Rocket plugin is not active. | |
| 338 | + if ( ! is_plugin_active( 'wp-rocket/wp-rocket.php' ) ) { | |
| 339 | + return; | |
| 340 | + } | |
| 341 | + | |
| 342 | + // Sanity check that we can access WP-Optimize's configuration class. | |
| 343 | + if ( ! function_exists( 'update_rocket_option' ) ) { | |
| 344 | + return; | |
| 345 | + } | |
| 346 | + | |
| 347 | + // Fetch settings. | |
| 348 | + $settings = get_rocket_option( 'cache_reject_cookies', array() ); | |
| 349 | + | |
| 350 | + // If the cookie exception exists, no need to modify anything. | |
| 351 | + if ( in_array( $this->key, $settings, true ) ) { | |
| 352 | + return; | |
| 353 | + } | |
| 354 | + | |
| 355 | + // Add cookie to exceptions. | |
| 356 | + $settings[] = $this->key; | |
| 357 | + | |
| 358 | + // Update configuration to include excluding caching for the ck_subscriber_id cookie. | |
| 359 | + update_rocket_option( 'cache_reject_cookies', $settings ); | |
| 360 | + | |
| 361 | + } | |
| 362 | + | |
| 363 | + /** | |
| 299 | 364 | * Show a notice in the WordPress Administration interface if |
| 300 | 365 | * WP Super Cache is active, its caching enabled and no rule to disable caching |
| 301 | 366 | * exists when the ck_subscriber_id cookie is present. |
| 302 | 367 | * |
| @@ -345,9 +410,9 @@ | ||
| 345 | 410 | public function wp_super_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 346 | 411 | |
| 347 | 412 | return sprintf( |
| 348 | 413 | '%s %s %s %s', |
| 349 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 414 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 350 | 415 | '<code>ck_subscriber_id</code>', |
| 351 | 416 | sprintf( |
| 352 | 417 | '<a href="%s">%s</a>', |
| 353 | 418 | esc_url( |