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 Why does 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?
user_canfunction and log / print_r what it outputs.read. My custom capability is added during plugin activation. Both return false when passed touser_can. Because these capabilities are stored in the database, they exist 100% of the time. I don't think it's possible that they are added late. Unlikecurrent_user_can, there is no need to check for the user being logged in. As I understand, it is just a database query.