Simple user role management for Acorn.
Roots is an independent open source org, supported only by developers like you. Your sponsorship funds WP Packages and the entire Roots ecosystem, and keeps them independent. Support us by purchasing Radicle or sponsoring us on GitHub — sponsors get access to our private Discord.
Install via Composer:
composer require roots/acorn-user-rolesStart by optionally publishing the user-roles config:
$ wp acorn vendor:publish --provider="Roots\AcornUserRoles\AcornUserRolesServiceProvider"User roles can be configured in the published config/user-roles.php file.
'librarian' => [
'display_name' => 'Librarian',
'capabilities' => ['read', 'edit_books', 'publish_books'],
],Capabilities can also be defined as an associative array:
'editor_lite' => [
'display_name' => 'Editor Lite',
'capabilities' => [
'read' => true,
'edit_posts' => true,
'delete_posts' => false,
],
],Since roles are stored in the database, removing a role from the config will not delete it. To remove a role, set it to false:
'librarian' => false,
'subscriber' => false,Note: Setting a role to
falsepermanently removes it from the database. Removing the line from config afterward will not restore it. To restore a removed role, use WP-CLI:wp role reset subscriber(orwp role reset --allto restore all default roles).
Capabilities defined in config are synced on every request. If you change the capabilities or display name for an existing role, the configured values will be applied.
Capabilities not included in the config are left untouched, so capabilities added by other plugins are preserved. To explicitly deny a capability, set it to false:
'editor' => [
'capabilities' => [
'read' => true,
'edit_posts' => true,
'delete_posts' => false, // explicitly denied
],
],If you want the config to be the single source of truth for a role, set strict to true. Any capabilities not listed in the config will be removed. In other words: false denies a listed capability, while strict removes unlisted capabilities.
'editor' => [
'strict' => true,
'capabilities' => [
'read' => true,
'edit_posts' => true,
],
],Keep track of development and community news.
- Join us on Discord by sponsoring us on GitHub
- Join us on Roots Discourse
- Follow @rootswp on Twitter
- Follow the Roots Blog
- Subscribe to the Roots Newsletter