current_user_can('custom_capability')
always returns true for super admins even if the capability is explicitly denied as stated here. It does work with a normal admin account.
I have added a custom capability for users with a specific email address, which is set when new users are registered and on plugin activation.
if (!empty(get_super_admins())) {
foreach (get_users(['login__in' => get_super_admins()]) as $user) {
$user->add_cap('custom_capability', false);
}
}
foreach (get_users(['search' => '*@specific-domain.com']) as $user) {
$user->add_cap('custom_capability');
}
Checking a super admin profile without that specific email address correctly states Denied: custom_capability
under the additional capabilities section of the profile.
The output of wp_get_current_user()
if logged in with the same super admin account as above:
...
["caps"]=>
array(2) {
["custom_capability"]=>
bool(false)
["administrator"]=>
bool(true)
}
...
Nonetheless current_user_can('custom_capability')
returns true
.
Did anybody else ever have this issue? Am I overlooking something and this is intended behavior?