purge_domain_now( 'admin-bar-edge-purge' );
if ( $result ) {
update_option( 'edge-cache-purge-time-stamp', gmdate('j M Y, g:ia') . ' UTC' );
echo esc_html__( 'Edge Cache purged successfully.', 'pressable_cache_management' );
} else {
echo esc_html__( 'Edge Cache purge failed. It might be disabled or rate-limited.', 'pressable_cache_management' );
}
wp_die();
}
function pcm_abar_flush_combined_callback() {
if ( ! current_user_can('administrator') && ! current_user_can('editor') && ! current_user_can('manage_woocommerce') ) {
echo 'You do not have permission to flush the combined cache.';
wp_die();
}
$messages = array();
// Object cache
wp_cache_flush();
if ( function_exists('batcache_clear_cache') ) batcache_clear_cache();
update_option( 'flush-obj-cache-time-stamp', gmdate('j M Y, g:ia') . ' UTC' );
$messages[] = esc_html__( 'Object Cache Flushed successfully.', 'pressable_cache_management' );
// Edge cache
if ( class_exists('Edge_Cache_Plugin') ) {
$edge_cache = Edge_Cache_Plugin::get_instance();
if ( method_exists( $edge_cache, 'purge_domain_now' ) ) {
$result = $edge_cache->purge_domain_now( 'admin-bar-combined-purge' );
if ( $result ) {
update_option( 'edge-cache-purge-time-stamp', gmdate('j M Y, g:ia') . ' UTC' );
$messages[] = esc_html__( 'Edge Cache Purged successfully.', 'pressable_cache_management' );
} else {
$messages[] = esc_html__( 'Edge Cache purge failed (possibly disabled or rate-limited).', 'pressable_cache_management' );
}
} else {
$messages[] = esc_html__( 'Edge Cache Plugin active, but purge method unavailable.', 'pressable_cache_management' );
}
} else {
$messages[] = esc_html__( 'Edge Cache Plugin not found; skipping Edge Cache purge.', 'pressable_cache_management' );
}
echo '- ' . implode( "\n- ", $messages );
wp_die();
}
// ─── Permission check ─────────────────────────────────────────────────────
if ( ! function_exists('pcm_abar_can_view') ) {
function pcm_abar_can_view() {
return current_user_can('administrator') || current_user_can('editor') || current_user_can('manage_woocommerce');
}
}
// ─── Admin Bar Menu ───────────────────────────────────────────────────────
add_action( 'admin_bar_menu', 'pcm_abar_add_menu', 100 );
function pcm_abar_add_menu( $wp_admin_bar ) {
if ( is_network_admin() || ! pcm_abar_can_view() ) return;
$branding_opts = get_option('remove_pressable_branding_tab_options');
$branding_disabled = $branding_opts && 'disable' == $branding_opts['branding_on_off_radio_button'];
$parent_id = $branding_disabled ? 'pcm-wp-admin-toolbar-parent-remove-branding' : 'pcm-wp-admin-toolbar-parent';
$parent_title = $branding_disabled ? 'Cache Control' : 'Cache Management';
// Detect Edge Cache state
$edge_cache_is_enabled = false;
if ( class_exists('Edge_Cache_Plugin') ) {
$ec = Edge_Cache_Plugin::get_instance();
$server_status = method_exists($ec,'get_ec_status') ? $ec->get_ec_status() : null;
if ( defined('Edge_Cache_Plugin::EC_ENABLED') && $server_status === Edge_Cache_Plugin::EC_ENABLED ) {
$edge_cache_is_enabled = true;
} elseif ( get_option('edge-cache-enabled') === 'enabled' ) {
$edge_cache_is_enabled = true;
}
}
// Parent
$wp_admin_bar->add_node( array( 'id' => $parent_id, 'title' => $parent_title ) );
// Flush Object Cache
$wp_admin_bar->add_menu( array(
'id' => 'cache-purge',
'title' => __( 'Flush Object Cache', 'pressable_cache_management' ),
'parent' => $parent_id,
'meta' => array( 'class' => 'pcm-wp-admin-toolbar-child' ),
));
// Edge Cache options (only if enabled)
if ( $edge_cache_is_enabled ) {
$wp_admin_bar->add_menu( array(
'id' => 'edge-purge',
'title' => __( 'Purge Edge Cache', 'pressable_cache_management' ),
'parent' => $parent_id,
'meta' => array( 'class' => 'pcm-wp-admin-toolbar-child' ),
));
$wp_admin_bar->add_menu( array(
'id' => 'combined-cache-purge',
'title' => __( 'Flush Object & Edge Cache', 'pressable_cache_management' ),
'parent' => $parent_id,
'meta' => array( 'class' => 'pcm-wp-admin-toolbar-child' ),
));
}
// Cache Settings (admin only)
if ( current_user_can('administrator') ) {
$wp_admin_bar->add_menu( array(
'id' => 'settings',
'title' => __( 'Cache Settings', 'pressable_cache_management' ),
'parent' => $parent_id,
'href' => admin_url('admin.php?page=pressable_cache_management'),
'meta' => array( 'class' => 'pcm-wp-admin-toolbar-child' ),
));
}
}