'; $icon_base64 = base64_encode($icon); $wp_admin_bar->add_menu( array( 'id' => 'berqWP', 'title' => '' . $plugin_name, 'href' => get_admin_url() . 'admin.php?page=berqwp', ) ); // Add the sub-menu item $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', // ID of the parent menu item 'id' => 'flush-cache', 'title' => is_multisite() ? 'Flush all sites' : 'Flush cache', 'href' => wp_nonce_url(admin_url('admin-post.php?action=clear_cache'), 'clear_cache_action'), 'meta' => array( 'class' => 'clear-cache-link', 'title' => 'Clear BerqWP cache', ), ) ); if (berqwp_can_use_cloud()) { $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', 'id' => 'warmup-cache', 'title' => 'Warmup cache', 'href' => wp_nonce_url(admin_url('admin-post.php?action=warmup_cache'), 'warmup_cache_action'), 'meta' => array( 'class' => 'warmup-cache-link', 'title' => 'Warmup BerqWP cache', ), ) ); } if (is_multisite()) { $wp_admin_bar->add_menu(array( 'id' => 'berqwp-network-sites', 'parent' => 'berqWP', 'title' => 'Flush site', 'href' => '#', )); $sites = get_sites(); foreach ($sites as $site) { $wp_admin_bar->add_menu(array( 'id' => 'berqwp-site-flush-' . $site->blog_id, 'parent' => 'berqwp-network-sites', 'title' => 'Flush site ' . get_blog_option($site->blog_id, 'blogname'), 'href' => wp_nonce_url(admin_url('admin-post.php?action=berq_flush_site&site_id=' . $site->blog_id), 'berq_flush_site_action'), )); } } if (berqwp_can_use_cloud()) { $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', // ID of the parent menu item 'id' => 'flush-cdn', 'title' => 'Flush CDN & page cache', 'href' => wp_nonce_url(admin_url('admin-post.php?action=berq_flush_cdn'), 'berq_flush_cdn_action'), 'meta' => array( 'class' => 'flush-cdn-cache', 'title' => 'Flush CDN & page cache', ), ) ); $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', // ID of the parent menu item 'id' => 'flush-criticalcss', 'title' => 'Flush critical CSS cache', 'href' => wp_nonce_url(admin_url('admin-post.php?action=berq_flush_criticalcss'), 'berq_flush_criticalcss_action'), 'meta' => array( 'class' => 'flush-criticalcss', 'title' => 'Flush critical CSS cache', ), ) ); } if (!is_admin()) { $page_url = bwp_get_request_url(); // Add the sub-menu item $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', // ID of the parent menu item 'id' => 'purge-page', 'title' => 'Purge this page', 'href' => wp_nonce_url(admin_url('admin-post.php?action=berq_purge_page&uri=' . urlencode($page_url)), 'berq_purge_page_action'), 'meta' => array( 'class' => 'purge-page-link', 'title' => 'Clear this page cache', ), ) ); if (berqwp_can_use_cloud()) { // Add the request cache $wp_admin_bar->add_menu( array( 'parent' => 'berqWP', // ID of the parent menu item 'id' => 'request-page-cache', 'title' => 'Force cache', 'href' => wp_nonce_url(admin_url('admin-post.php?action=berq_request_cache&uri=' . urlencode($page_url)), 'berq_request_cache_action'), 'meta' => array( 'class' => 'request-page-cache-link', 'title' => 'Force cache for this page', ), ) ); } } } function handle_clear_cache_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'clear_cache' && wp_verify_nonce($_GET['_wpnonce'], 'clear_cache_action')) { $cache = berqCache::getInstance(); $cache->delete_cache_files(is_multisite()); // If is multisite flush all sites if (function_exists('wp_cache_flush')) { wp_cache_flush(); // Clear the entire object cache. } set_transient('berq_cache_cleared_notice', 'true', 60); $redirect_url = add_query_arg('berq_clear_cache', '', wp_get_referer()); // Redirect back to the referring page after clearing the cache wp_safe_redirect($redirect_url); exit; } } function handle_warmup_cache_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'warmup_cache' && wp_verify_nonce($_GET['_wpnonce'], 'warmup_cache_action')) { // trigger cache warmup do_action('berqwp_cache_warmup'); set_transient('berq_cache_warmup_notice', 'true', 60); // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } function handle_purge_page_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'berq_purge_page' && wp_verify_nonce($_GET['_wpnonce'], 'berq_purge_page_action')) { $page_url = $_GET['uri']; berqCache::purge_page($page_url, true); if (is_admin()) { set_transient('berq_purge_page_notice', $page_url, 60); } // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } function handle_request_cache_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'berq_request_cache' && wp_verify_nonce($_GET['_wpnonce'], 'berq_request_cache_action')) { $page_url = $_GET['uri']; $slug = bwp_url_into_path($page_url); if (is_admin()) { set_transient('berq_force_cache_notice', $page_url, 60); } // as_enqueue_async_action('warmup_cache_quickly', [$page_url, true]); warmup_cache_by_url($page_url, true); // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } function handle_flush_cdn_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'berq_flush_cdn' && wp_verify_nonce($_GET['_wpnonce'], 'berq_flush_cdn_action')) { $cache = berqCache::getInstance(); $cache->flush_cdn(); set_transient('berq_purge_cdn_notice', 'true', 60); // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } function handle_berq_flush_site_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && isset($_GET['site_id']) && $_GET['action'] === 'berq_flush_site' && wp_verify_nonce($_GET['_wpnonce'], 'berq_flush_site_action')) { $site_id = (int) sanitize_text_field($_GET['site_id']); $cache = berqCache::getInstance(); switch_to_blog($site_id); // Flush cache $cache->delete_cache_files(); restore_current_blog(); do_action('berqwp_purge_site'); set_transient('berq_purge_site_notice', 'true', 60); // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } function handle_flush_criticalcss_action() { // Check if the user has the necessary nonce and the action matches if (isset($_GET['action']) && $_GET['action'] === 'berq_flush_criticalcss' && wp_verify_nonce($_GET['_wpnonce'], 'berq_flush_criticalcss_action')) { $parsed_url = wp_parse_url(home_url()); $domain = $parsed_url['host']; $berqwp = new BerqWP(berqwp_get_license_key(), null, null); $berqwp->purge_critilclcss($domain); do_action('berqwp_purge_criticalcss'); set_transient('berq_purge_criticalcss_notice', 'true', 60); // Redirect back to the referring page after clearing the cache wp_safe_redirect(wp_get_referer()); exit; } } } new berqAdminBar(); }