Skip to content

Commit 6141c37

Browse files
committed
make clearing only home / front page cache possible
1 parent e4670be commit 6141c37

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

classes/class-base.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,15 +462,18 @@ public function add_toolbar_button( $wp_admin_bar ) {
462462
],
463463
]
464464
);
465-
if ( \is_singular() ) {
465+
466+
if ( $this->is_singular_or_front_page() ) {
467+
$permalink = \is_front_page() || \is_home() ? \get_home_url() : \get_permalink();
468+
466469
$wp_admin_bar->add_node(
467470
[
468471
'id' => 'clear_cloudflare_cache_url',
469472
'title' => \esc_html__( 'Clear CF cache for this URL', 'pp-cf-utils' ),
470473
'parent' => 'cloudflare',
471474
'href' => '#',
472475
'meta' => [
473-
'onclick' => 'clearCloudflareCache("' . \get_permalink() . '"); return false;',
476+
'onclick' => 'clearCloudflareCache("' . esc_attr( $permalink ) . '"); return false;',
474477
],
475478
]
476479
);
@@ -479,6 +482,16 @@ public function add_toolbar_button( $wp_admin_bar ) {
479482
$this->add_toolbar_button_script();
480483
}
481484

485+
/**
486+
* Checks if the current page is a singular page, front page, or home page and not on a paged page.
487+
*
488+
* @return bool True if the current page is a singular page, front page, or home page and not on a paged page, false otherwise.
489+
*/
490+
public function is_singular_or_front_page() {
491+
// 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.
492+
return \is_singular() || ( ( \is_front_page() || \is_home() ) && ! \get_query_var( 'paged' ) );
493+
}
494+
482495
/**
483496
* Adds the toolbar icon styles.
484497
*

0 commit comments

Comments
 (0)