W3 Total Cache - Allow Editors To Purge Single Post From Cache W3 Total Cache - Allow Editors To Purge Single Post From Cache wordpress wordpress

W3 Total Cache - Allow Editors To Purge Single Post From Cache


I needed a similar thing, but I'm sure you can adapt this to your needs:

First some filters to make it show the "Performance"-Menu on the AdminBar for normal editors:

function allow_users_to_flush($capability) {   return "publish_post";}add_filter("w3tc_capability_row_action_w3tc_flush_post", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_w3tc_flush", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_w3tc_flush_all", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_admin_bar", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_admin_bar_flush_all", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_admin_bar_w3tc", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_admin_bar_flush", "allow_users_to_flush", 10, 10);add_filter("w3tc_capability_w3tc", "allow_users_to_flush", 10, 10);

And, because the user must be allowed to access the dashboard for purging/flushing, a cap-filter:

function w3tc_cap_filter( $allcaps, $cap, $args ) {    if(preg_match("/w3tc_dashboard/", $_SERVER["REQUEST_URI"])) {        $allcaps[$cap[0]] = true;    }    return $allcaps;}add_filter( 'user_has_cap', 'w3tc_cap_filter', 10, 3 );

Voila, the user now sees the menu and can flush the cache (I needed "Purge all caches", not a single post/page, but that should work the same).

My permissions are pretty broad, but it works for my case. You might want to add more safeguards depending on your requirements.For reference:

http://hookr.io/plugins/w3-total-cache/0.9.5/filters/#index=w has a nice overview of filters in w3.

https://codex.wordpress.org/Plugin_API/Filter_Reference/user_has_cap for info on the capability-filter.