user_can( int|object $user, string $capability )
Whether a particular user has capability or role.
Documentation says that this should work for capabilities, but so far, it's only working for roles. This is being run during plugin deactivation.
Using a capability as an argument returns false:
user_can( $user_id, 'read' )
Using a role as an argument returns true:
user_can( $user_id, 'my_custom_role' )
I have confirmed that the user has the capability by using
var_dump( get_userdata( $user_id ) );
Excerpt of output:
public 'allcaps' => array (size=3) 'my_custom_cap' => boolean true 'read' => boolean true 'my_custom_role' => boolean true
user_can() recognize the role, but not the capability?
If you look at the source for
user_can(), it relies on
get_userdata() as well. Why does it see one, but not the other? Can anybody duplicate this, or is it just me?
Edit: I have confirmed that
user_can( $user_id, 'read' ) returns true during the main plugin, but it appears to return no value when run during deactivation. Can anyone get this to return true during plugin deactivation? Why does it return an empty value instead of true or false?