Skip to content

Commit

Permalink
use another approach
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Oct 23, 2024
1 parent 8cabc3f commit fe74f90
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions inc/Engine/Cache/TaxonomySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit fe74f90

Please sign in to comment.