Discover in this tutorial how to give the ability to view Restrict Content Pro memberships to a custom WordPress user role via code, without plugins.
By default, WordPress has 5 user roles:
- Subscriber >
( 'subscriber' )
- Contributor > (
'contributor' )
- Author > (
'author' )
- Editor >
( 'editor' )
- Administrator >
( 'administrator' )
In addition to these, some plugins can add new roles. For example, WooCommerce creates two more:
- Customer
- Store manager
In fact, in a previous tutorial you learned how to create a new user role with the capabilities you want.
In this case, I’m going to tell you how you can extend the capabilities of the user role of your choice so that it can access Restrict Content Pro memberships. Something very practical, for example, if you want to give it access to a virtual assistant.
Let’s see how to do it:
Snippet to allow a user role to have access to Restrict Content Pro memberships
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this snippet you first get the 'assistant'
role and then add the ability to view memberships with the add_cap()
function.
This is just an example, where you allow the person(s) who have the wizard
role to have access to review Restrict Content Pro memberships. But the idea is that you assign it to the user role that interests you.
You can also play with the different capabilities of the plugin, which are as follows:
rcp_view_members
rcp_manage_members
rcp_view_levels
rcp_manage_levels
rcp_view_discounts
rcp_manage_discounts
rcp_view_payments
rcp_manage_payments
rcp_manage_settings
rcp_export_data
rcp_view_help
Ass you see, you can apply them quite granularly.
By the way, the new capability is saved in the database so once you have refreshed the page, which will cause the code to execute, you can delete the snippet.
Conclusion
Now you know how to allow a WordPress user role to view Restrict Content Pro memberships, with a simple snippet of code.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂