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
- 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?
- 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
- Disable posts, only allow to edit existing pages, not create new ones (create_posts)
- How to update user role without logout
- 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
- How to enable the theme editor cap for an editor role?
- How-to Delay The Capability To Publish Posts?
- 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?
- Set default page for user account in admin
- 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?
- Print WordPress username id inside JavaScript
- query users by role
- Check if someone is editing a post (this content is currently locked)
- 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?
- How to filter users list on user_status field with get_users()
- get_posts() not working when accessing with a custom user role
- Display custom fields in frontside user profile
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- Add a role and give admin priviledges
- Display list of uploaded images, filtered by user under a specific user group
- 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)?
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- First and last name fields not filled when using wp_insert_user
- get author of published post
- How to get custom post_author?
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- What’s the correct way to add capabilites to user roles?
- User Capabilities are not available in WP REST permission callback?
- How to use gettext for specific user role
- Does it matter if the very first user, usually Admin, does not have a user ID of 1?
- Best practice for Designing a Plugin with this scenario
- Groups and subgroups for permission
- Redirect admin 403 “Cheatin uh?” admin pages
- Adding another field to user table
- Remove specific administrator’s capability
- Preventing role reading others posts
- How To Create A File Archive in WordPress?
- Allow a user or role to view drafts and previews, but not other admin privileges?
- See which user role / capability is needed to use a plugin
- Allowing duplicating users with same user_login and user_email
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- How to grab data after wp user search is complete
- Add custom parameter for custom user role
- How to prevent users from deleting their accounts?
- Disabling user capability to edit_posts or delete_posts in the front-end
- User Permissions on custom post type
- User Registration Moderate
- How I can give access to my custom plugin for editor roles user?
- How to retrieve custom profile fields associated with different users
- Remove all capabilities in separate method fails versus included in method
- WordPress install checking permissions of user id 0
- Remove from a div by class name from post page if post author role is not administrator
- Adding admin for specific users
- New Users are saved with no role selected
- Force “submit for review” on update?
- WordPress User Management Departmental Managers
- first_name property missing inside register_user action hook
- Want to add post to user dashboard
- user can login from single account detail from multiple locations(computer) at the same time [closed]
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- How might I enable a user to view Draft pages from a different Author, without the ability to edit?