There’s a reason why add_role()
has the $capabilities
as 3rd parameter.
First some insights on what happens, when you use the function.
- It calls
WP_Roles->add_role()
– the class method - The method then does a check if the role already exists. If yes, it aborts.
- The next step is, that it adds the role to
WP_Roles->roles[]
array with thedisplay_name
(2nd arg) to the$wpdb->prefix . 'user_roles'
option table entry (an array).
Conclusion
So if you don’t add the capabilities right when creating the role, then you save a role with empty capabilities.
A note about the Codex
NEVER EVER trust the codex. There simply is no function called add_cap()
. There’re only class methods inside WP_Roles
, WP_Role
and WP_User
that are named like this. (Will update the Codex entry if I find some time.)
Related Posts:
- what’s the meaning of the field wp_capabilities in table wp_usermeta
- How to Structure a New Role/Capability Scheme?
- How to allow Unfiltered HTML in a wordpress multisite install
- Is there a simple way to manage capabilities per user?
- Are User Levels Still Currently Used?
- Limit role to one plugin [duplicate]
- Roles for Custom Post Types
- Logout users upon login, based on caps/role?
- You do not have sufficient permissions to access this page on a submenu
- Hide custom post type by user roles
- Menu page with minimum capability as ‘Subscriber’ doesn’t allow ‘Admin’ to access it?
- Unable to access custom plugin backend
- How can I change my assigned user role in WordPress 3.5.1?
- insufficient permissions; coding an action for plugin governed by custom capability
- How to determine which capability to use?
- Allow contributor user role to perform copy operation PHP
- Buddy Press restrict the capability to edit users
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- current_user_can() returning true for capability when the user and role do not have the capability
- Getting a List of Currently Available Roles on a WordPress Site?
- Editor can create any new user except administrator
- How do I create a custom role capability?
- Remove Ability for Other Users to View Administrator in User List?
- Send user activation email when programmatically creating user
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- Export data as CSV in back end with proper HTTP headers
- Change default admin page for specific role(s)
- How to check username/password without signing in the user
- How to let contributors to create a new revision(draft) editing their published posts
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Disable posts, only allow to edit existing pages, not create new ones (create_posts)
- How to Change the Entire WordPress Admin panel Look and Feel?
- How to update user role without logout
- How to check user role without using current_user_can()
- WordPress Capabilities: edit_user vs edit_users
- WordPress REST API call generates nonce twice on every call
- Do not allow users to create new posts and pages
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- Allowing Custom Capability to Manage Plugin Options
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How to programmatically add a user to a role?
- Prevent user creating new users with specific roles
- How-to Delay The Capability To Publish Posts?
- How to restrict specific post types from being read or added by specific user roles (eg. author)?
- How to add more than 1 user role to sub-menu pages
- Custom user profile, registration, login page with theme
- How to use WP default post list tables in a plugin?
- Odd behaviour with submenu link creation
- Reapproval for edits and deletion after post is published
- How to add quick edit and bulk edit fields to users admin section
- Can I create users that have access to *some* other users posts instead of all other users posts?
- How to check if a role has a specific capability
- Set default page for user account in admin
- How to restrict plugin’s sub-menu pages to admin/subscribers?
- How to not let a user with a new role edit users that have administrator role?
- Execute plugin for specific user role(s) only
- How to remove sticky post capability for a specific user role?
- User role permissions based on taxonomies
- Generating User(s) with Settings API
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- WordPress admin deleted user details not removed in database. How to delete WordPress Users from Database
- Print WordPress username id inside JavaScript
- query users by role
- Function Get User Object By Username?
- current_user_can Not Always Working Properly
- Check if someone is editing a post (this content is currently locked)
- Get User Role by ID not working
- Hide plugin dashboard menu item for specific roles
- Remove wordpress author’s capability to moderate comments on their own posts
- Getting users by specific capability, not role
- Can you set a role as author?
- Managing Users and Creating Groups [closed]
- Modify users.php page to create page/post on button clicked
- Subscribe to author?
- How to filter users list on user_status field with get_users()
- Frontend language per user
- get_posts() not working when accessing with a custom user role
- Display custom fields in frontside user profile
- Failed to Open Stream: Permission Denied While Writing to an XML File in a WordPress Plugin
- Applying roles to an admin sub-menu (eg Appearance -> Menus)
- Remove Capabilities from WP admin for specific user role
- Set different custom menu items for different user roles
- Fix permissions for users role
- Prevent third party plugin’s admin page access based on user type
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- Disable user from updating certain posts
- Add a role and give admin priviledges
- Where are $current_user->allcaps set?
- wp_dropdown_roles() to replace option value = code
- Create a custom capability to allow an ‘Editor’ to edit only ‘Subscriber’ users
- global $current_user not current user
- Featured image not working, because of custom user role?
- Display list of uploaded images, filtered by user under a specific user group
- What is the proper way to get logged in user id in a plugin?
- How do I let contributors edit their posts after being approved once?
- How to get a users list by who created them?
- How to build a fool proof AdSense revenue sharing model?
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?