Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions classes/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,18 @@ public function add_toolbar_button( $wp_admin_bar ) {
],
]
);
if ( \is_singular() ) {

if ( $this->is_singular_or_front_page() ) {
$permalink = (string) ( \is_front_page() || \is_home() ? \get_home_url() : \get_permalink() );

$wp_admin_bar->add_node(
[
'id' => 'clear_cloudflare_cache_url',
'title' => \esc_html__( 'Clear CF cache for this URL', 'pp-cf-utils' ),
'parent' => 'cloudflare',
'href' => '#',
'meta' => [
'onclick' => 'clearCloudflareCache("' . \get_permalink() . '"); return false;',
'onclick' => 'clearCloudflareCache("' . esc_attr( $permalink ) . '"); return false;',
],
]
);
Expand All @@ -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.
*
Expand Down