I have a multisite WordPress installation set up, and have a user who is set to an ‘Administrator’ role on both sites. However, the function current_user_can('Administrator') does not return true when logged in as them, which I expected it to.

My user account, however, is an ‘Administrator’ on both sites, and also a ‘Super Admin’ on the network, and the call returns true for me.

Why is this? Shouldn’t the first user only be false if checking for ‘Super Admin’ and not just ‘Administrator’?

If this is an issue, is there any other way that I can check if a user is set to the ‘Administrator’ role without being a ‘Super Admin’?

2 Answers
2

I would agree that current_user_can(‘Administrator’) should return true for the user. However, current_user_can is primarily intended to check for capabilities, which is generally a more robust check to be making.

I’d suggest something like this (untested):

if ( current_user_can( 'activate_plugins' ) && ! current_user_can( 'update_core' ) ) {
//...
}

So this is checking if the current user can activate plugins but cannot update core. This should return true for Administrators whilst returning false for Network Admins – as on multisite update_core is reserved for Network Admins.

Leave a Reply

Your email address will not be published. Required fields are marked *