Tag: roles

Checking WordPress User Capabilities

Recently I spent some time trying to determine user capabilities while developing some plugins. I figured I’d put what I learned here for future reference.

In order to check a current user’s capabilities (i.e. are they an admin?) use the function;
current_user_can( capability )

An example would be:

if (current_user_can(‘manage_options’)) {
// User is an administrator.
/* Do something */
}

If you want to check a particular user, use the function;
user_can(id, capability).

This works exactly like the previous example, however, it takes an ID as a paramter.

An example would be:

if (user_can($id, ‘manage_options’)){
// User is an administrator
/* Do something
}

For a complete list of roles and capabilities, please reference this site.