| @@ -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 ( ! WP_ConvertKit()->get_class( 'admin_restrict_content' )->restrict_content_enabled() ) { | |
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $this->litespeed_cache(); |
| @@ -63,8 +63,9 @@ | ||
| 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 | |
| @@ -117,9 +118,9 @@ | ||
| 117 | 118 | public function litespeed_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 118 | 119 | |
| 119 | 120 | return sprintf( |
| 120 | 121 | '%s %s %s %s', |
| 121 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 122 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 122 | 123 | '<code>ck_subscriber_id</code>', |
| 123 | 124 | sprintf( |
| 124 | 125 | '<a href="%s">%s</a>', |
| 125 | 126 | esc_url( |
| @@ -188,9 +189,9 @@ | ||
| 188 | 189 | public function w3_total_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 189 | 190 | |
| 190 | 191 | return sprintf( |
| 191 | 192 | '%s %s %s %s', |
| 192 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 193 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 193 | 194 | '<code>ck_subscriber_id</code>', |
| 194 | 195 | sprintf( |
| 195 | 196 | '<a href="%s">%s</a>', |
| 196 | 197 | esc_url( |
| @@ -271,13 +272,8 @@ | ||
| 271 | 272 | // Fetch settings. |
| 272 | 273 | $config = new WPO_Cache_Config(); |
| 273 | 274 | $settings = $config->get(); |
| 274 | 275 | |
| 275 | - // Check that we received an array of settings. | |
| 276 | - if ( ! is_array( $settings ) ) { | |
| 277 | - return; | |
| 278 | - } | |
| 279 | - | |
| 280 | 276 | // Check the exception cookies array key exists in the settings. |
| 281 | 277 | if ( ! array_key_exists( 'cache_exception_cookies', $settings ) ) { |
| 282 | 278 | $settings['cache_exception_cookies'] = array(); |
| 283 | 279 | } |
| @@ -295,8 +291,42 @@ | ||
| 295 | 291 | |
| 296 | 292 | } |
| 297 | 293 | |
| 298 | 294 | /** |
| 295 | + * Add a rule to WP Rocket to prevent caching when | |
| 296 | + * the ck_subscriber_id cookie is present. | |
| 297 | + * | |
| 298 | + * @since 2.7.0 | |
| 299 | + */ | |
| 300 | + public function wp_rocket() { | |
| 301 | + | |
| 302 | + // Bail if the WP Rocket plugin is not active. | |
| 303 | + if ( ! is_plugin_active( 'wp-rocket/wp-rocket.php' ) ) { | |
| 304 | + return; | |
| 305 | + } | |
| 306 | + | |
| 307 | + // Sanity check that we can access WP-Optimize's configuration class. | |
| 308 | + if ( ! function_exists( 'update_rocket_option' ) ) { | |
| 309 | + return; | |
| 310 | + } | |
| 311 | + | |
| 312 | + // Fetch settings. | |
| 313 | + $settings = get_rocket_option( 'cache_reject_cookies', array() ); | |
| 314 | + | |
| 315 | + // If the cookie exception exists, no need to modify anything. | |
| 316 | + if ( in_array( $this->key, $settings, true ) ) { | |
| 317 | + return; | |
| 318 | + } | |
| 319 | + | |
| 320 | + // Add cookie to exceptions. | |
| 321 | + $settings[] = $this->key; | |
| 322 | + | |
| 323 | + // Update configuration to include excluding caching for the ck_subscriber_id cookie. | |
| 324 | + update_rocket_option( 'cache_reject_cookies', $settings ); | |
| 325 | + | |
| 326 | + } | |
| 327 | + | |
| 328 | + /** | |
| 299 | 329 | * Show a notice in the WordPress Administration interface if |
| 300 | 330 | * WP Super Cache is active, its caching enabled and no rule to disable caching |
| 301 | 331 | * exists when the ck_subscriber_id cookie is present. |
| 302 | 332 | * |
| @@ -345,9 +375,9 @@ | ||
| 345 | 375 | public function wp_super_cache_notice( $notice ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
| 346 | 376 | |
| 347 | 377 | return sprintf( |
| 348 | 378 | '%s %s %s %s', |
| 349 | - esc_html__( 'ConvertKit: Member Content: Please add', 'convertkit' ), | |
| 379 | + esc_html__( 'Kit: Member Content: Please add', 'convertkit' ), | |
| 350 | 380 | '<code>ck_subscriber_id</code>', |
| 351 | 381 | sprintf( |
| 352 | 382 | '<a href="%s">%s</a>', |
| 353 | 383 | esc_url( |