Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 798 forks source link

Delete cache button missing if network activated #25497

Open bpongy opened 5 years ago

bpongy commented 5 years ago

If WPSC is network activated, administrators can’t see the delete cache button. Only the superadmin can see the button. Is there a way to change this behavior?

WordPress 5.0.3 WP Super Cache 1.6.4

bpongy commented 5 years ago

Up.

Here is my patch:

<?php
if ( is_multisite() && function_exists('wp_cache_clear_cache') && current_user_can('manage_options') && isset($_GET['ax_delete_cache']) ) {
    wp_cache_clear_cache(get_current_blog_id());
    wp_redirect( home_url() );
}

add_action( 'admin_bar_menu', function($wp_admin_bar) {
    if ( !is_super_admin() && is_multisite() && function_exists('wp_cache_clear_cache') && current_user_can('manage_options') ) {
        $args = array(
            'id'        => 'ax_vidercache',
            'title'     => 'Vider le cache',
            'href'      => add_query_arg( array('ax_delete_cache' => '1') ),
            'parent'    => 'site-name'
        );
        $wp_admin_bar->add_node($args);
    }
}, 900 );
stiucsib86 commented 5 years ago

Thanks @redpik! Thats handy workaround. I've adapted slightly to

<?php

add_action('init', 'init_delete_cache');

function init_delete_cache()
{
    if (function_exists('wp_cache_clear_cache') && current_user_can('manage_options') && isset($_GET['ax_delete_cache'])) {
        if (is_multisite()) {
            wp_cache_clear_cache(get_current_blog_id());
        } else {
            wp_cache_clear_cache();
        }
    }

    add_action('admin_bar_menu', function ($wp_admin_bar) {
        if (function_exists('wp_cache_clear_cache') && current_user_can('manage_options')) {
            $args = array(
                'id' => 'ax_delete_cache',
                'parent' => '',
                'title' => 'Delete Site Cache',
                'href' => add_query_arg(['ax_delete_cache' => '1']),
            );
            $wp_admin_bar->add_node($args);
        }
    }, 900);

}
bpongy commented 5 years ago

:+1: