PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 3.7
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v3.7
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / includes / classes / AdvancedCache.php

AdvancedCache.php in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 3.7, at includes/classes/AdvancedCache.php

762 lines 20.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin
4 *
5 * @package PoweredCache
6 */
7
8 namespace PoweredCache;
9
10 use PoweredCache\Async\CachePurger;
11 use const PoweredCache\Constants\POST_META_DISABLE_CACHE_KEY;
12 use function PoweredCache\Utils\clean_page_cache_dir;
13 use function PoweredCache\Utils\clean_site_cache_dir;
14 use function PoweredCache\Utils\delete_page_cache;
15 use function PoweredCache\Utils\get_post_related_urls;
16 use const PoweredCache\Constants\PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 /**
23 * Class Admin
24 *
25 * @package PoweredCache
26 */
27 class AdvancedCache {
28
29 /**
30 * Holds plugin settings
31 *
32 * @var array $settings
33 */
34 private $settings;
35
36
37 /**
38 * Instance of CachePreloader
39 *
40 * @var CachePurger
41 */
42 private $cache_purger;
43
44 /**
45 * Return an instance of the current class
46 *
47 * @return AdvancedCache
48 * @since 1.0
49 */
50 public static function factory() {
51
52 static $instance;
53
54 if ( ! $instance ) {
55 $instance = new self();
56 $instance->setup();
57 }
58
59 return $instance;
60 }
61
62 /**
63 * Setup hooks
64 *
65 * @since 1.0
66 */
67 public function setup() {
68 $this->settings = \PoweredCache\Utils\get_settings();
69
70 if ( ! $this->settings['enable_page_cache'] ) {
71 return;
72 }
73
74 $this->cache_purger = CachePurger::factory();
75
76 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ) );
77 add_action( 'admin_post_powered_cache_purge_page_cache', array( $this, 'purge_page_cache' ) );
78 add_action( 'admin_post_powered_cache_purge_page_cache_network', array( $this, 'purge_page_cache_network_wide' ) );
79 add_action( 'transition_post_status', array( $this, 'purge_on_post_update' ), 9999, 3 );
80 add_action( 'switch_theme', array( $this, 'purge_on_switch_theme' ) );
81 add_action( 'wp_set_comment_status', array( $this, 'purge_post_on_comment_update' ) );
82 add_action( 'edit_comment', array( $this, 'purge_post_on_comment_update' ) );
83 add_action( 'set_comment_cookies', array( $this, 'set_comment_cookie' ), 10, 2 );
84 add_filter( 'powered_cache_post_related_urls', array( $this, 'powered_cache_post_related_urls' ) );
85 add_filter( 'powered_cache_page_cache_enable', array( $this, 'maybe_caching_disabled' ) );
86 add_filter( 'powered_cache_mod_rewrite', array( $this, 'maybe_disable_mod_rewrite' ), 99 );
87 add_action( 'wp_update_site', array( $this, 'purge_on_site_update' ), 10, 2 );
88 add_action( 'create_term', array( $this, 'purge_on_term_change' ), 10, 3 );
89 add_action( 'edit_term', array( $this, 'purge_on_term_change' ), 10, 3 );
90 add_action( 'delete_term', array( $this, 'purge_on_term_change' ), 10, 3 );
91 }
92
93 /**
94 * Add purge button on admin bar
95 *
96 * @param object $wp_admin_bar Admin bar object
97 *
98 * @since 1.0
99 */
100 public function admin_bar_menu( $wp_admin_bar ) {
101 if ( POWERED_CACHE_IS_NETWORK && current_user_can( 'manage_network' ) ) {
102 $wp_admin_bar->add_menu(
103 array(
104 'id' => 'advanced-cache-purge-network',
105 'title' => __( 'Purge Page Cache [Network Wide - All Sites]', 'powered-cache' ),
106 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_purge_page_cache_network' ), 'powered_cache_purge_page_cache_network' ),
107 'parent' => 'powered-cache',
108 )
109 );
110 }
111
112 if ( current_user_can( 'manage_options' ) ) {
113 $wp_admin_bar->add_menu(
114 array(
115 'id' => 'advanced-cache-purge',
116 'title' => __( 'Purge Page Cache', 'powered-cache' ),
117 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_purge_page_cache' ), 'powered_cache_purge_page_cache' ),
118 'parent' => 'powered-cache',
119 )
120 );
121
122 if ( is_singular() && ! is_preview() && is_post_publicly_viewable( get_the_ID() ) ) {
123 $wp_admin_bar->add_menu(
124 array(
125 'id' => 'advanced-cache-current-page-purge',
126 'title' => esc_html__( 'Purge Current Page', 'powered-cache' ),
127 'href' => wp_nonce_url( admin_url( sprintf( 'admin-post.php?action=powered_cache_purge_page_cache&type=current-page&post=%d', get_the_ID() ) ), 'powered_cache_purge_page_cache' ),
128 'parent' => 'powered-cache',
129 )
130 );
131 }
132 }
133 }
134
135
136 /**
137 * Purge page cache network wide
138 *
139 * @since 2.0
140 */
141 public function purge_page_cache_network_wide() {
142 if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'powered_cache_purge_page_cache_network' ) ) { // phpcs:ignore
143 wp_nonce_ays( '' );
144 }
145
146 if ( current_user_can( 'manage_network' ) ) {
147 if ( $this->settings['async_cache_cleaning'] ) {
148 $this->cache_purger->push_to_queue( [ 'call' => 'clean_page_cache_dir' ] );
149 $this->cache_purger->save()->dispatch();
150 } else {
151 clean_page_cache_dir();
152 }
153 $redirect_url = add_query_arg( 'pc_action', 'flush_page_cache_network', wp_get_referer() );
154 } else {
155 $redirect_url = add_query_arg( 'pc_action', 'flush_page_cache_network_err_permission', wp_get_referer() );
156 }
157
158 delete_site_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
159
160 wp_safe_redirect( esc_url_raw( $redirect_url ) );
161 exit;
162 }
163
164 /**
165 * Purge page cache directory
166 *
167 * @since 1.0
168 * @since 1.1 clean site dir instead of root page caching dir
169 */
170 public function purge_page_cache() {
171 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'powered_cache_purge_page_cache' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
172 wp_nonce_ays( '' );
173 }
174
175 if ( current_user_can( 'manage_options' ) ) {
176 if ( isset( $_GET['type'] ) && 'current-page' === $_GET['type'] && ! empty( $_GET['post'] ) ) {
177 $this->purge_post( absint( $_GET['post'] ) );
178 } elseif ( $this->settings['async_cache_cleaning'] ) {
179 $this->cache_purger->push_to_queue( [ 'call' => 'clean_site_cache_dir' ] );
180 $this->cache_purger->save()->dispatch();
181 } else {
182 clean_site_cache_dir();
183 }
184
185 $redirect_url = add_query_arg( 'pc_action', 'flush_page_cache', wp_get_referer() );
186 } else {
187 $redirect_url = add_query_arg( 'pc_action', 'flush_page_cache_err_permission', wp_get_referer() );
188 }
189
190 delete_transient( PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
191
192 wp_safe_redirect( esc_url_raw( $redirect_url ) );
193 exit;
194 }
195
196
197 /**
198 * Purge cache when post updated
199 *
200 * @param string $new_status New Post status.
201 * @param string $old_status Old Post status.
202 * @param \WP_Post $post Post object.
203 *
204 * @return void
205 * @since 3.4 adjusted for `transition_post_status` hook
206 * @since 1.0
207 */
208 public function purge_on_post_update( $new_status, $old_status, $post ) {
209 if ( 'publish' === $new_status || 'publish' === $old_status ) {
210 $this->purge_post( $post->ID );
211 }
212 }
213
214 /**
215 * Purge post related page cache
216 *
217 * @param int $post_id Post ID
218 *
219 * @since 3.4
220 */
221 public function purge_post( $post_id ) {
222 $current_post = get_post( $post_id );
223
224 if ( ! is_a( $current_post, 'WP_Post' ) ) {
225 return;
226 }
227
228 if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
229 return;
230 }
231
232 if ( ! is_post_type_viewable( $current_post->post_type ) ) {
233 return;
234 }
235
236 if ( ! in_array( $current_post->post_status, array( 'publish', 'private', 'trash', 'pending', 'draft' ), true ) ) {
237 return;
238 }
239
240 $urls = get_post_related_urls( $post_id );
241
242 /**
243 * Page cache purge urls.
244 *
245 * @hook powered_cache_advanced_cache_purge_urls
246 *
247 * @param {array} $urls The list of URLs that will purged
248 * @param {int} $post_id Post ID.
249 *
250 * @return {array} New value
251 * @since 1.0
252 */
253 $urls = apply_filters( 'powered_cache_advanced_cache_purge_urls', $urls, $post_id );
254 $deleted_urls = [];
255
256 if ( $this->settings['async_cache_cleaning'] ) {
257 $this->cache_purger->push_to_queue(
258 [
259 'call' => 'delete_page_cache',
260 'urls' => $urls,
261 ]
262 );
263 $deleted_urls = $urls;
264 $this->cache_purger->save()->dispatch();
265 } else {
266 foreach ( $urls as $url ) {
267 if ( delete_page_cache( $url ) ) {
268 $deleted_urls[] = $url;
269 }
270 }
271 }
272
273 /**
274 * Fires after purging cache on post update.
275 *
276 * @hook powered_cache_advanced_cache_purge_post
277 *
278 * @param {int} $post_id The Post ID.
279 * @param {array} $deleted_urls The list of purged urls with the updated post.
280 * @param {array} $urls The list of urls that will be purged. @since 3.6
281 *
282 * @since 1.0
283 */
284 do_action( 'powered_cache_advanced_cache_purge_post', $post_id, $deleted_urls, $urls );
285 }
286
287 /**
288 * Purge post cache when comment status change
289 *
290 * @param int $comment_id Comment ID
291 * @param string $comment_status Comment status
292 *
293 * @return void
294 * @deprecated since 3.4.4
295 */
296 public function purge_post_on_comment_status_change( $comment_id, $comment_status ) {
297 // deprecate this method in favor of `purge_post_on_comment_update`
298 _deprecated_function( __METHOD__, '3.4.4', 'purge_post_on_comment_update' );
299 $this->purge_post_on_comment_update( $comment_id );
300 $comment = get_comment( $comment_id );
301 $post_id = $comment->comment_post_ID;
302 $post_url = get_permalink( $post_id );
303
304 do_action( 'powered_cache_advanced_cache_purge_on_comment_update', $post_id, $post_url, $comment_id );
305 }
306
307 /**
308 * Delete page cache when a comment update
309 *
310 * @param int $comment_id Comment ID
311 *
312 * @since 3.4.4
313 */
314 public function purge_post_on_comment_update( $comment_id ) {
315 $comment = get_comment( $comment_id );
316 $post_id = $comment->comment_post_ID;
317 $post_url = get_permalink( $post_id );
318 delete_page_cache( $post_url, true );
319
320 /**
321 * Fires after purging cache for a post that associated a comment
322 *
323 * @hook powered_cache_advanced_cache_purge_on_comment_update
324 *
325 * @param {int} $post_id Post ID.
326 * @param {string} $post_url Post permalink.
327 * @param {int} $comment_id Comment ID.
328 *
329 * @since 3.4.4
330 */
331 do_action( 'powered_cache_advanced_cache_purge_on_comment_update', $post_id, $post_url, $comment_id );
332 }
333
334 /**
335 * Purge site when switching to a new theme
336 *
337 * @since 2.0
338 */
339 public function purge_on_switch_theme() {
340 if ( $this->settings['async_cache_cleaning'] ) {
341 $this->cache_purger->push_to_queue( [ 'call' => 'clean_site_cache_dir' ] );
342 $this->cache_purger->save()->dispatch();
343 } else {
344 clean_site_cache_dir();
345 }
346 }
347
348 /**
349 * Purge site cache when site updated (eg: archived, deleted etc...)
350 *
351 * @param \WP_Site $new_site New site object.
352 * @param \WP_Site $old_site Old site object.
353 *
354 * @return void
355 * @since 2.5.3
356 */
357 public function purge_on_site_update( $new_site, $old_site ) {
358 switch_to_blog( $old_site->id );
359 if ( $this->settings['async_cache_cleaning'] ) {
360 $this->cache_purger->push_to_queue( [ 'call' => 'clean_site_cache_dir' ] );
361 $this->cache_purger->save()->dispatch();
362 } else {
363 clean_site_cache_dir();
364 }
365 restore_current_blog();
366 }
367
368 /**
369 * Leave a cookie when commenting on a post as usual and don't show the cached page.
370 * `comment_author_*` cookies are site-wide available.
371 * Don't show cached results just for left a comment 5 months ago is not seems efficient here.
372 *
373 * @param object $comment Comment object
374 * @param object $user User Object
375 *
376 * @since 1.0
377 */
378 public function set_comment_cookie( $comment, $user ) {
379 $post_id = $comment->comment_post_ID;
380 $path = wp_parse_url( get_permalink( $post_id ), PHP_URL_PATH );
381 setcookie( 'powered_cache_commented_posts[' . $post_id . ']', $path, ( time() + DAY_IN_SECONDS * 30 ), $path );
382 }
383
384
385 /**
386 * Adds custom pages to post related urls
387 *
388 * @param array $urls The list of the urls
389 *
390 * @return array urls
391 * @since 1.1
392 */
393 public function powered_cache_post_related_urls( $urls ) {
394 $settings = \PoweredCache\Utils\get_settings();
395
396 $additional_pages = $settings['purge_additional_pages'];
397
398 if ( empty( $additional_pages ) ) {
399 return $urls;
400 }
401
402 // we only need relative path
403 $additional_pages = str_replace( site_url(), '', $additional_pages );
404 $additional_page_paths = explode( PHP_EOL, $additional_pages );
405 $additional_urls = array();
406
407 foreach ( $additional_page_paths as $page ) {
408 $additional_urls[] = site_url( $page );
409 }
410
411 $urls = array_merge( $urls, $additional_urls );
412
413 return $urls;
414 }
415
416
417 /**
418 * Get the list of rejected cookies
419 *
420 * @return mixed|void
421 * @since 2.0
422 */
423 public static function get_rejected_cookies() {
424 $settings = \PoweredCache\Utils\get_settings();
425 $cookies = [];
426
427 if ( ! empty( $settings['rejected_cookies'] ) ) {
428 $cookies = preg_split( '#(\r\n|\r|\n)#', $settings['rejected_cookies'], - 1, PREG_SPLIT_NO_EMPTY );
429 }
430
431 $wp_cookies = [
432 'wp-postpass',
433 'wordpressuser_',
434 'wordpresspass_',
435 'wordpress_sec_',
436 'wordpress_logged_in_',
437 'powered_cache_commented_posts',
438 'comment_author_',
439 'comment_author_email_',
440 'comment_author_url_',
441 ];
442
443 if ( ! empty( $cookies ) ) {
444 $wp_cookies = array_merge( $cookies, $wp_cookies );
445 }
446
447 /**
448 * Filter rejected cookie list.
449 *
450 * @hook powered_cache_rejected_cookies
451 *
452 * @param {array} $wp_cookies The rejected cookie list from the caching.
453 *
454 * @return {array} Rejected cookie list
455 * @since 2.0
456 */
457 return apply_filters( 'powered_cache_rejected_cookies', $wp_cookies );
458 }
459
460 /**
461 * Get the list of rejected cookies
462 *
463 * @return mixed|void
464 * @since 2.0
465 */
466 public static function get_vary_cookies() {
467 $settings = \PoweredCache\Utils\get_settings();
468 $cookies = [];
469
470 if ( ! empty( $settings['vary_cookies'] ) ) {
471 $cookies = preg_split( '#(\r\n|\r|\n)#', $settings['vary_cookies'], - 1, PREG_SPLIT_NO_EMPTY );
472 }
473
474 /**
475 * Filter vary cookie list.
476 *
477 * @hook powered_cache_vary_cookies
478 *
479 * @param {array} $cookies The varied cookie list, which allows to create separate cache based on the match.
480 *
481 * @return {array} Vary cookie list
482 * @since 2.0
483 */
484 return apply_filters( 'powered_cache_vary_cookies', $cookies );
485 }
486
487 /**
488 * Get the list of rejected referrers
489 *
490 * @return mixed|null
491 * @since 3.6
492 */
493 public static function get_rejected_referrers() {
494 $settings = \PoweredCache\Utils\get_settings();
495 $rejected_referrers = [];
496
497 if ( ! empty( $settings['rejected_referrers'] ) ) {
498 $rejected_referrers = preg_split( '#(\r\n|\r|\n)#', $settings['rejected_referrers'], - 1, PREG_SPLIT_NO_EMPTY );
499 }
500
501 /**
502 * Filter rejected referrer list.
503 *
504 * @hook powered_cache_rejected_referrers
505 *
506 * @param {array} $rejected_referrers The referrer that will not see the cached page.
507 *
508 * @return {array} Rejected referrer list.
509 * @since 3.6
510 */
511 return apply_filters( 'powered_cache_rejected_referrers', $rejected_referrers );
512 }
513
514 /**
515 * Get the list of rejected user agents
516 *
517 * @return mixed|void
518 * @since 2.0
519 */
520 public static function get_rejected_user_agents() {
521 $settings = \PoweredCache\Utils\get_settings();
522 $rejected_user_agents = [];
523
524 if ( ! empty( $settings['rejected_user_agents'] ) ) {
525 $rejected_user_agents = preg_split( '#(\r\n|\r|\n)#', $settings['rejected_user_agents'], - 1, PREG_SPLIT_NO_EMPTY );
526 }
527
528 $rejected_user_agents[] = 'facebookexternalhit';
529
530 /**
531 * Filter rejected user agent list.
532 *
533 * @hook powered_cache_rejected_user_agents
534 *
535 * @param {array} $rejected_user_agents The user agents that will not see the cached page.
536 *
537 * @return {array} Rejected user agent list.
538 * @since 2.0
539 */
540 return apply_filters( 'powered_cache_rejected_user_agents', $rejected_user_agents );
541 }
542
543 /**
544 * Get the list of rejected uri that never get cached
545 *
546 * @return mixed|void
547 * @since 2.0
548 */
549 public static function get_rejected_uri() {
550 $settings = \PoweredCache\Utils\get_settings();
551 $rejected_uri_list = [];
552
553 if ( ! empty( $settings['rejected_uri'] ) ) {
554 $rejected_uri_list = preg_split( '#(\r\n|\r|\n)#', $settings['rejected_uri'], - 1, PREG_SPLIT_NO_EMPTY );
555 }
556
557 /**
558 * Filter rejected uri list
559 *
560 * @hook powered_cache_rejected_uri_list
561 *
562 * @param {array} $rejected_uri_list The list of rejected uri that never get cached.
563 *
564 * @return {array} New value
565 * @since 2.0
566 */
567 return apply_filters( 'powered_cache_rejected_uri_list', $rejected_uri_list );
568 }
569
570
571 /**
572 * Get the allowed cache query parameters
573 *
574 * @return mixed|null
575 * @since 3.0
576 */
577 public static function get_cache_query_string() {
578 $settings = \PoweredCache\Utils\get_settings();
579 $cache_query_strings = [];
580
581 if ( ! empty( $settings['cache_query_strings'] ) ) {
582 $cache_query_strings = preg_split( '#(\r\n|\r|\n)#', $settings['cache_query_strings'], - 1, PREG_SPLIT_NO_EMPTY );
583 }
584
585 $query_strings = [
586 'lang',
587 ];
588
589 if ( ! empty( $cache_query_strings ) ) {
590 $cache_query_strings = array_merge( $query_strings, $cache_query_strings );
591 }
592
593 /**
594 * Filter accepted query strings.
595 *
596 * @hook powered_cache_cache_query_strings
597 *
598 * @param {array} $query_strings The list of query strings that will be cached based on their value
599 *
600 * @return {array} New value
601 * @since 3.0
602 */
603 return apply_filters( 'powered_cache_cache_query_strings', $cache_query_strings );
604 }
605
606 /**
607 * These query strings will be ignored during the caching
608 *
609 * @return array
610 * @since 3.0 deprecated
611 * @deprecated Use `self::get_ignored_query_strings` instead
612 */
613 public static function get_accepted_query_strings() {
614 _deprecated_function( '\PoweredCache\AdvancedCache::get_accepted_query_strings', '3.0', '\PoweredCache\AdvancedCache::get_ignored_query_strings' );
615
616 return self::get_ignored_query_strings();
617 }
618
619 /**
620 * These query strings will be ignored during the caching
621 *
622 * @return mixed|void
623 * @since 3.0
624 */
625 public static function get_ignored_query_strings() {
626 $settings = \PoweredCache\Utils\get_settings();
627 $ignored_query_strings = [];
628
629 if ( ! empty( $settings['ignored_query_strings'] ) ) {
630 $ignored_query_strings = preg_split( '#(\r\n|\r|\n)#', $settings['ignored_query_strings'], - 1, PREG_SPLIT_NO_EMPTY );
631 }
632
633 $query_strings = [
634 'fbclid',
635 'fb_action_ids',
636 'fb_action_types',
637 'ref',
638 'gclid',
639 'fb_source',
640 'utm_source',
641 'utm_medium',
642 'utm_campaign',
643 'utm_term',
644 'utm_content',
645 'utm_expid',
646 '_ga',
647 'mc_cid',
648 'mc_eid',
649 'campaignid',
650 'adgroupid',
651 'adid',
652 'age-verified',
653 'usqp',
654 'cn-reloaded',
655 'ao_noptimize',
656 ];
657
658 if ( ! empty( $ignored_query_strings ) ) {
659 $query_strings = array_merge( $query_strings, $ignored_query_strings );
660 }
661
662 /**
663 * Filters ignored query strings.
664 *
665 * @hook powered_cache_accepted_query_strings
666 *
667 * @param {array} $query_strings The list of query strings will be ignored during the caching
668 *
669 * @return {array} New value
670 * @since 2.0
671 * @depreacated since 3.0
672 */
673 $query_strings = apply_filters( 'powered_cache_accepted_query_strings', $query_strings );
674
675 /**
676 * Filters ignored query strings.
677 *
678 * @hook powered_cache_ignored_query_strings
679 *
680 * @param {array} $query_strings The list of query strings will be ignored during the caching
681 *
682 * @return {array} New value
683 * @since 3.0
684 */
685 $query_strings = apply_filters( 'powered_cache_ignored_query_strings', $query_strings );
686
687 return $query_strings;
688 }
689
690
691 /**
692 * Disable caching of the individual page when it marked as dont' cache
693 *
694 * @param bool $status Cache status
695 *
696 * @return bool
697 */
698 public function maybe_caching_disabled( $status ) {
699 if ( is_single() ) {
700 $is_cache_disabled = (bool) get_post_meta( get_the_ID(), POST_META_DISABLE_CACHE_KEY, true );
701 if ( $is_cache_disabled ) {
702 return false;
703 }
704 }
705
706 return $status;
707 }
708
709 /**
710 * Maybe disable rewrite rules based on the settings
711 *
712 * @param bool $rewrite_status mod rewrite status
713 *
714 * @return bool
715 * @since 2.0
716 */
717 public function maybe_disable_mod_rewrite( $rewrite_status ) {
718 $vary_cookies = self::get_vary_cookies();
719 if ( ! empty( $vary_cookies ) ) {
720 $rewrite_status = false;
721 }
722
723 return $rewrite_status;
724 }
725
726
727 /**
728 * Purge cache when term change
729 *
730 * @param int $term_id Term ID
731 * @param int $tt_id Term Taxonomy ID
732 * @param string $taxonomy Taxonomy
733 *
734 * @since 3.4.2
735 */
736 public function purge_on_term_change( $term_id, $tt_id, $taxonomy ) {
737 $term_taxonomy = get_taxonomy( $taxonomy );
738
739 if ( ! $term_taxonomy->public ) {
740 return;
741 }
742
743 $term_url = get_term_link( $term_id, $taxonomy );
744
745 if ( ! is_wp_error( $term_url ) ) {
746 if ( $this->settings['async_cache_cleaning'] ) {
747 $this->cache_purger->push_to_queue(
748 [
749 'call' => 'delete_page_cache',
750 'urls' => $term_url,
751 ]
752 );
753 $this->cache_purger->save()->dispatch();
754 } else {
755 delete_page_cache( $term_url );
756 }
757 }
758 }
759
760 }
761
762