Check if user is admin by user ID

You worded it as you want to check if user has administrator role. It is considered more proper to check for capability, relevant to specific action.

In practice this is usually expressed as current_user_can( 'manage_options' ) for current user. For arbitrary user it would be user_can( $user_id, 'manage_options' ).

Of course this is capability that stands for general configuration of the site. Depending on your purpose you might want to use a different one, see list in roles and capabilities documentation.

Leave a Comment