From fe74f90f5d7390f8a363e775fb70d28ed4b322b7 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 23 Oct 2024 11:55:16 +0300 Subject: [PATCH] use another approach --- inc/Engine/Cache/TaxonomySubscriber.php | 37 ++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/inc/Engine/Cache/TaxonomySubscriber.php b/inc/Engine/Cache/TaxonomySubscriber.php index e921dd8a3f..9cae069781 100644 --- a/inc/Engine/Cache/TaxonomySubscriber.php +++ b/inc/Engine/Cache/TaxonomySubscriber.php @@ -24,7 +24,7 @@ public static function get_subscribed_events() { * @return bool */ public function disable_cache_on_not_valid_taxonomy_pages( $can_cache ) { - if ( $this->is_not_valid_taxonomies_page() ) { + if ( $this->is_not_valid_taxonomy_page() ) { return false; } @@ -39,7 +39,7 @@ public function disable_cache_on_not_valid_taxonomy_pages( $can_cache ) { * @return string */ public function stop_optimizations_for_not_valid_taxonomy_pages( $html ) { - return $this->is_not_valid_taxonomies_page() ? '' : $html; + return $this->is_not_valid_taxonomy_page() ? '' : $html; } /** @@ -67,34 +67,21 @@ private function get_all_taxonomies_query_var() { } /** - * Check if we are on any taxonomy frontend page, but the url query is not valid. + * Check if we are on the taxonomy frontend page, but it's not valid url query. * - * @return bool (True when not valid page, False if it's a valid taxonomy page) + * @return bool (True when not valid taxonomy page, False if it's a valid one) */ - private function is_not_valid_taxonomies_page() { - if ( ! is_category() && ! is_tag() && ! is_tax() ) { + private function is_not_valid_taxonomy_page() { + $term_id = get_queried_object_id(); + if ( empty( $term_id ) ) { return false; } - $taxonomies_query_vars = wpm_apply_filters_typed( 'string[]', 'rocket_cache_taxonomy_query_vars', $this->get_all_taxonomies_query_var() ); - foreach ( $taxonomies_query_vars as $taxonomy_query_var ) { - if ( $this->is_not_valid_taxonomy_page( $taxonomy_query_var ) ) { - return true; - } - } - return false; - } + global $wp; - /** - * Check if we are on the taxonomy frontend page, but it's not valid url query. - * - * @param string $taxonomy_query_var Current taxonomy query var to check. - * @return bool (True when not valid taxonomy page, False if it's a valid one) - */ - private function is_not_valid_taxonomy_page( $taxonomy_query_var ) { - global $wp_query; - return isset( $wp_query->query_vars[ $taxonomy_query_var ], $wp_query->query[ $taxonomy_query_var ] ) - && - $wp_query->query_vars[ $taxonomy_query_var ] !== $wp_query->query[ $taxonomy_query_var ]; + $term_link = untrailingslashit( get_term_link( $term_id ) ); + $current_link = untrailingslashit( home_url( add_query_arg( [], $wp->request ) ) ); + + return $term_link !== $current_link; } }