@@ -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