From 6141c37b7159e41af060a1fac82d9d095ad9db8b Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 28 Aug 2025 10:14:22 +0200 Subject: [PATCH 1/2] make clearing only home / front page cache possible --- classes/class-base.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/classes/class-base.php b/classes/class-base.php index 22399d7..ee36c49 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -462,7 +462,10 @@ public function add_toolbar_button( $wp_admin_bar ) { ], ] ); - if ( \is_singular() ) { + + if ( $this->is_singular_or_front_page() ) { + $permalink = \is_front_page() || \is_home() ? \get_home_url() : \get_permalink(); + $wp_admin_bar->add_node( [ 'id' => 'clear_cloudflare_cache_url', @@ -470,7 +473,7 @@ public function add_toolbar_button( $wp_admin_bar ) { 'parent' => 'cloudflare', 'href' => '#', 'meta' => [ - 'onclick' => 'clearCloudflareCache("' . \get_permalink() . '"); return false;', + 'onclick' => 'clearCloudflareCache("' . esc_attr( $permalink ) . '"); return false;', ], ] ); @@ -479,6 +482,16 @@ public function add_toolbar_button( $wp_admin_bar ) { $this->add_toolbar_button_script(); } + /** + * Checks if the current page is a singular page, front page, or home page and not on a paged page. + * + * @return bool True if the current page is a singular page, front page, or home page and not on a paged page, false otherwise. + */ + public function is_singular_or_front_page() { + // If we're on a singular page, or the front page or home page and not on a paged page, we can clear the cache for this URL. + return \is_singular() || ( ( \is_front_page() || \is_home() ) && ! \get_query_var( 'paged' ) ); + } + /** * Adds the toolbar icon styles. * From 1dd32494eb2b34c5f246addd8612c76249b05cfd Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 28 Aug 2025 10:22:06 +0200 Subject: [PATCH 2/2] phpstan fix --- classes/class-base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/class-base.php b/classes/class-base.php index ee36c49..bfe413b 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -464,7 +464,7 @@ public function add_toolbar_button( $wp_admin_bar ) { ); if ( $this->is_singular_or_front_page() ) { - $permalink = \is_front_page() || \is_home() ? \get_home_url() : \get_permalink(); + $permalink = (string) ( \is_front_page() || \is_home() ? \get_home_url() : \get_permalink() ); $wp_admin_bar->add_node( [