0

I was accidentally using is_admin() to check if a user was an admin and found out that function is not checking that. So I looked for another one and I found is_super_admin() but that checks if you are a admin of a network of sites or owner of a single WordPress install. I have a network site and I want to know if the user is the owner of the blog. I do not want to use roles. I want to check if the user is the owner of the blog.

1

I have had similar issues with this in the past, WordPress really does need a is_user_admin() function.

In the meantime I think the best way to do this is to test if the user has certain capabilities.

function is_user_admin(){
    if(!is_super_admin() && current_user_can('activate_plugins'){
        // User is an admin
    }
}

Reference:

1

The 'activate_plugins' roll only works if superadmin has enabled that privilege in network settings, which they often don't -- it's disabled by default. The proper way is to use the 'administrator' role.

if(current_user_can('administrator')) {echo "User is admin!";}

See the Summary of Rolls at https://codex.wordpress.org/Roles_and_Capabilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.