Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active June 26, 2019 15:08
Show Gist options
  • Save markhowellsmead/28e0d57f7a8aa5da566970e67899150c to your computer and use it in GitHub Desktop.
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
<?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