Last active
June 26, 2019 15:08
-
-
Save markhowellsmead/28e0d57f7a8aa5da566970e67899150c to your computer and use it in GitHub Desktop.
WordPress: how to use “do_not_allow” with map_meta_cap in Multisite to restrict custom capability to non-super-admins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function customCapabilityRules($caps, $cap, $user_id, $args) | |
{ | |
$deny = array(); | |
switch ($cap) { | |
case 'my_custom_capability': | |
if( is_super_admin() ){ | |
$deny[] = 'my_custom_capability'; | |
} | |
break; | |
} | |
if (in_array($cap, $deny)) { | |
$caps[] = 'do_not_allow'; | |
} | |
return $caps; | |
} | |
add_filter('map_meta_cap', 'customCapabilityRules', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment