Custom capability – docs?
-
I am unable to find any easily accessible instruction on how to use custom capability field when editing a role. Ideally some example.
The page I need help with: [log in to see the link]
-
Hi @postcd,
Thanks for reaching out Members Support Team!
The Custom Capability field in the role editor lets you add a capability that isn’t already listed in the UI — including ones you’ve invented yourself.
How to use it:
- Go to Users → Roles and open the role you want to edit.
- Scroll down to the Edit Capabilities section.
- Find the Custom Capability text field on the right side of the Edit Capabilities box.
- Type in the capability name using lowercase letters and underscores — for example:
view_reportsoraccess_premium_content. - Select Grant or Deny using the radio buttons next to it.
- Save the role.
That capability is now assigned to the role and stored directly in your WordPress database.
A few things to keep in mind:
- Capability names are case-sensitive and should use only lowercase letters, numbers, and underscores (e.g.,
my_custom_cap, notMy Custom Cap). - A custom capability you add this way won’t do anything by itself — it just gets stored on the role. For it to have an effect, something needs to check for it, either via
current_user_can( 'my_custom_cap' )in theme/plugin code, or through Members’ own Content Permissions or shortcode features (e.g.,[members_access capability="my_custom_cap"]). - Changes made here are permanent and survive plugin deactivation, since Members writes directly to the database.
Let us know if you have a specific use case in mind and we can point you in the right direction!
Most of the things mentioned was not what I have asked, but this part was on topic:
A custom capability you add this way won’t do anything by itself — it just gets stored on the role. For it to have an effect, something needs to check for it, either via
current_user_can( 'my_custom_cap' )in theme/plugin code, or through Members’ own Content Permissions or shortcode features (e.g.,[members_access capability="my_custom_cap"]).Though this is too general for a layman to understand. Can you link/provide some examples? For example if i want to expose some page or post content only to a certain role with the custom capability, or when i want to expose WP-Admin custom plugin entry in the menu only to a role with this custom capability? Yes, i am asking stupidly, because i am not a developer.
Hi @postcd,
No worries, happy to clarify!
To show a page or post only to a specific role:
- Open the page or post in the WordPress editor.
- On the right side, find the Content Permissions box.
- Tick the role(s) that should be able to view it on your site, then save.
Users without that role will be blocked from seeing the content when they visit the page.
To restrict a WordPress admin menu item to a specific role:
Each admin menu item requires a specific capability to be visible. If a role doesn’t have that capability, the menu item simply won’t appear for users with that role. You can use Members to grant or deny capabilities on a role to control this.
If you’re not sure which capability a particular menu item requires, let us know which plugin it belongs to and we can help you find it!
Regards,
No, I wanted to know how i can do it with custom capability. So if what i have mentioned can not be done with this custom capability, then please provide different examples how i can use it, maybe for similar objectives i have mentioned.
Hi @postcd,
Thank you for pushing back — here’s a more honest answer:
For a non-developer, the most practical way to use a custom capability is with the Members shortcode directly inside your page or post content.
For example, if you created a capability called
view_vip_contentand granted it to a role:[members_access capability="view_vip_content"]This text is only visible to users whose role has this capability.[/members_access]Any content you wrap in that shortcode will only be visible to users with that capability. Everyone else won’t see it.
For restricting entire pages or admin menu items using a custom capability, that would require a small amount of custom code — something a developer could set up quickly, but not something Members handles out of the box without code.
Sorry for the confusion in our earlier replies!
You must be logged in to reply to this topic.