Allowing Editors to Clear the Cache using Quick Cache

I started using Quick Cache on a site recently and some of the publishers (setup as editors) wanted to be able to clear the cache manually to ensure their posts went live right away. So I wrote a quick script to handle that. I’ll probably release a plugin for this eventually, but for now…here’s the code:

function check_publish(){
    global $current_user, $post;
        
    $capability = 'publish_';
    // Check current post type...if we have one available
    if($post->post_type != ''){
        // Set the capability we are looking for to publish_s
        $capability .= $post->post_type . 's';
    } else {
        // Set the default capability to publish_posts
        $capability .= 'posts';
    }
    
    // Check if the user has rights to publish a post
    return current_user_can($capability);
}
add_filter('ws_plugin__qcache_ms_user_can_see_admin_header_controls', 'check_publish');

This will include the Clear Cache button in the admin section of WordPress.

Update: I’ve released this plugin on wordpress.org.