WordPress Users and Roles

WordPress has a built in user system. Every person who can log in to your site is a user, and every user has a role. The role decides what the person is allowed to do. This is important for security: give people only the access they really need.

Default user roles

Terminal output

$ wp role list –fields=role,name
role name
administrator Administrator
editor Editor
author Author
contributor Contributor
subscriber Subscriber

RoleWhat the user can do
AdministratorEverything: settings, themes, plugins, users and all content
EditorPublish and manage all posts and pages, including the posts of others, and moderate comments
AuthorWrite, publish and edit his own posts, and upload files
ContributorWrite and edit his own posts, but cannot publish them, and cannot upload files
SubscriberOnly manage his own profile. Can read the content
Note: On a multisite network there is one more role, Super Admin, who manages the whole network.

Capabilities

A role is only a named group of capabilities. A capability is one small permission, like publish_posts or manage_options. We can check what is allowed with a few lines of PHP:

Terminal output

$ wp user create anita anita@example.com –role=author –user_pass=Secret123! –porcelain
2
$ wp user create sam sam@example.com –role=contributor –user_pass=Secret123! –porcelain
3
$ wp user list –fields=ID,user_login,roles
ID user_login roles
1 admin administrator
2 anita author
3 sam contributor
$ wp eval 'foreach (["publish_posts","edit_others_posts","upload_files","manage_options"] as $c) { echo str_pad($c, 20), "anita: ", user_can(2, $c) ? "yes" : "no", " sam: ", user_can(3, $c) ? "yes" : "no", "\n"; }'
publish_posts anita: yes sam: no
edit_others_posts anita: no sam: no
upload_files anita: yes sam: no
manage_options anita: no sam: no

Manage users

  • Users > Add User creates a user. Choose the lowest role which works.
  • Use a strong password, and ask admins to turn on two factor login with a plugin.
  • When a user leaves, delete the user and assign the content to someone else.
  • Users > Profile is where every user edits his own name, password and options.

Create your own role

Plugins like User Role Editor help you to change capabilities. Developers can also do it with code, by using add_role():

add_role('shop_manager_lite', 'Shop Manager Lite', ['read' => true, 'edit_posts' => true]);
$role = get_role('shop_manager_lite');
echo $role->name . ': ' . implode(', ', array_keys($role->capabilities));
Output

shop_manager_lite: read, edit_posts

Note: Never use the username admin on a live site, and do not share one login between many people. Next: WordPress Permalinks.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.