TL;DR
- Roles vs. Capabilities
- Creating Custom Roles
- Frequently Asked Questions
Roles vs. Capabilities
In WordPress, a **Role** is simply a name assigned to a collection of **Capabilities**. For example, the 'Editor' role is bestowed with capabilities like edit_others_posts and manage_categories. As a developer, you should always check for capabilities, not roles.
// DON'T check roles
if ( current_user_can('editor') ) { ... }
// DO check capabilities
if ( current_user_can('edit_others_posts') ) { ... }
Creating Custom Roles
Need a 'Client' role that can only view private posts? You can easily create it using the add_role() function.
Quick Tip: Use the User Role Creator to build the exact code needed for your custom roles and capabilities.
Frequently Asked Questions
What is the difference between a role and a capability?
How do I add a new capability to an existing role?
Can I hide admin menu items based on roles?
Key Takeaways
- Roles vs. Capabilities: Practical action you can apply now.
- Creating Custom Roles: Practical action you can apply now.
- Frequently Asked Questions: Practical action you can apply now.