I'm working on a modification to WP Super Cache which adds two new capabilities to give more control of restriction to certain features. My goal is to a) allow Editors to see the Delete Cache button on the admin bar and b) use it to delete the cache of the page they're editing. I got 'a', however when the Editor clicks Delete Cache, they get 'You do not have sufficient permissions to access this page.'
I cannot find what part of the plugin forced this permissions check, but I wonder if it has to do with the URL that the menu item points to.
Here is the function and hook to add the menu item:
function supercache_admin_bar_render() {
global $wp_admin_bar, $wp_cache_not_logged_in;
if ( !is_user_logged_in() && !$wp_cache_not_logged_in )
return false;
// ORIGINALLY if ( wp_supercache_admin() )
if ( !current_user_can('wp_supercache_delete_page_cache') && !current_user_can('wp_supercache_manage_options') )
return false;
$wp_admin_bar->add_menu( array(
'parent' => '',
'id' => 'delete-cache',
'title' => __( 'Delete Cache', 'wp-super-cache' ),
'href' => wp_nonce_url( admin_url( 'admin.php?page=wpsupercache&action=wpsupercachedelete&path=' . urlencode( $_SERVER[ 'REQUEST_URI' ] ) ), 'delete-cache' ) // ORIGINALLY pointed to options.general.php?page=wpsupercache&action=delete...
) );
}
add_action( 'wp_before_admin_bar_render', 'supercache_admin_bar_render');
And I think this part is also relevant to solving this ... this is elsewhere in the plugin file, not within any function (do I need to up the priority?):
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
add_action( 'admin_init', 'wp_cache_manager_updates' );
I have made the modifications to wp_cache_manager_updates so it accounts for the aforementioned capabilities. In fact, this function never runs. I put a die('got to wp_cache_manager_updates'); in there to see if it ever even gets touched. It does not. Something intercepts and sends me to Insufficient Permissions-ville.
manage_optionsbit is the capability that gets checked. If I change that up for the custom capability, I can run delete on the page for anyone with that capability, but it has the undesired consequence of letting the Editor into the super cache settings. I still need to learn how to change the code so I beat the capability check. Also, I don't fully understand why the capability for the options page affects running the action. – James Revillini Apr 13 '12 at 19:47