Skip to main content
Share Your Experience: Take the 2024 Developer Survey
30 votes

Reset default roles and capabilities

If you don't want to install a plugin to just to do this one task, you can call the WordPress function directly to rebuild the roles and their capabilities. if ( !function_exists( 'populate_roles' ) )...
Enchiridion's user avatar
13 votes

What's the difference between the capability remove_users and delete_users?

The difference is really no difference in regular (single install) WordPress. It's in a multisite install (network) where there is a difference. In multisite, only a Super Admin (who can manage ...
butlerblog's user avatar
  • 4,996
11 votes

Editor can create any new user except administrator

Despite of being ~7 years old, this thread can be googled easily and still provides a working solution. I mean the code provided by @John P Bloch. That said, under PHP 7 it produces a non-critical ...
bugnumber9's user avatar
10 votes

Why is javascript allowed in my post content?

If you have the unfiltered_html capability then you can use JS. Admins and editors have this capability by default. Personally I use a plugin for fine control of my users' capabilities, but you can ...
Andy Macaulay-Brook's user avatar
9 votes

How to get all capabilities of an existing user role

I suggest not to mess with the existing roles and capabilities in its default, it might help you some trouble when you will have a bunch of custom roles and capabilities in the future. To answer your ...
Mac organo's user avatar
8 votes

Allowing custom role access to custom post type in back end

It's hard to troubleshoot the above code because it's only a part of the actual code, but here's the minimum plugin needed to register a custom post type (called Example) and a custom role (Blog ...
Nathan Johnson's user avatar
7 votes

Is there way to rename user role name without plugin?

If you are using WP version 4.7+ you may accomplish this using the wp_roles_init action like so: add_action( 'wp_roles_init', static function ( \WP_Roles $roles ) { $roles->roles['administrator'...
Mat Lipe's user avatar
  • 319
7 votes

How to update role capabilities

add_role() will not do anything if the role already exists, so it can't be used to modify capabilities. To modify capabilities use the add_cap() and remove_cap() method of the WP_Role object. You can ...
Jacob Peattie's user avatar
6 votes

Getting a List of Currently Available Roles on a WordPress Site?

For those which have multilingual site, function function wp_roles_array() { $editable_roles = get_editable_roles(); foreach ($editable_roles as $role => $details) { $sub['role'] =...
Jasom Dotnet's user avatar
6 votes

Allow user to Edit Posts but not Add New?

The previous answer only hides the menu item with CSS, and as @ezejielDFM points out, it won't stop users from actually being able to add posts. Instead, when registering your custom post type, you ...
indextwo's user avatar
  • 441
6 votes

add_menu_page() for more than one user role

Let's take a look at Codex page for add_menu_page... Third param is: $capability (string) (Required) The capability required for this menu to be displayed to the user. And later on in Notes ...
Krzysiek Dróżdż's user avatar
5 votes

add capability to author role to be able to delete attachments

Here is how to allow edition and deletion of attachments for owned ones only to a custom role. Add the capabilities 'manage_other_users_attachments' and 'manage_own_attachments' to the admin role, ...
Laura Perenon's user avatar
5 votes

Reset default roles and capabilities

I find an easier way to reset roles and their associated capabilities is to use wp-cli. wp-cli has a built-in method for resetting roles. You can specify any that you want to reset. For example: wp ...
thetwopct's user avatar
  • 261
5 votes

How do I create a custom role capability?

Tested with WordPress 6.0, and it works: add_action( 'activated_plugin',function( $plugin,$network_activation ){ add_role( 'your_custom_role_slug', __( 'Your custom role title','your-plugin-domain'...
Jose's user avatar
  • 201
5 votes

Is there way to rename user role name without plugin?

Actually, there are many ways to achieve that: With pure php and mysql you can edit the serialized entry in the db. Indeed, Wordpress stores the serialized array of roles in wp_options table. So: ...
Dharma's user avatar
  • 151
5 votes

How can I modify the Capability needed to access a plugin's options?

The best way to change the capability that users need to view the Yoast SEO settings pages is by using the wpseo_manage_options_capability filter. Here's an example of how this is used (placed in ...
Matt Sims's user avatar
  • 181
5 votes

Does the "promote_users" capability allow someone to create a new admin account?

Yes, if you assign 'promote_users' to another user, that user could promote non-site admins to site admin.
danhgilmore's user avatar
5 votes

create_users capabilities on a role on multisite

I ran into the same problem. It's easily solved by going into the Network Admin > Settings page. Look for the label "Add New Users" and make sure this option is checked: Allow site administrators to ...
Amanda Giles's user avatar
5 votes

\WP_User Object | What's the Difference Between {caps} and {allcaps}?

Examining the comments for the properties in the WP_User class reveals that allcaps is: All capabilities the user has, including individual and role based. And caps is: The individual ...
Jacob Peattie's user avatar
5 votes

Custom post type role permissions won't let me read

Your custom post type looks like it's set up properly. It works on my test install. Try this instead of whatever add_role and add_cap code you're currently using. (For testing purposes only. Don't use ...
Myles's user avatar
  • 331
4 votes

Add Media Upload Capabilities Needed for Custom Role for non-Posts

Found the basic problem! Although a different context than the one you described, the root cause is probably the same. I was trying to allow users to setup a personal page and upload an image to ...
user97667's user avatar
4 votes

Custom taxonomies capabilities

When you are defining capabilities while registering a taxonomy you are defining new capabilities that are equal to the existing capabilities of manage_terms edit_terms delete_terms and assign_terms. ...
Marc's user avatar
  • 721
4 votes

Possible to hide Custom Post Type UI/Menu from specific User Roles?

The accepted answer can be used to hide custom post types (and other assorted items) as described. But if you want to hide the CPT UI plugin menu itself, you can also remove the action that adds it to ...
Grant's user avatar
  • 153
4 votes

How to create a clone role in wordpress

You could always use the User Role Editor plugin; Install the plugin Go to Users > User Role Editor Click "Add Role" to the right Choose the role you wish to duplicate from the "Make copy of" ...
McOwen's user avatar
  • 142
4 votes

What do unfiltered_html and unfiltered_upload actually filter?

I appreciate this is an old thread, but restricted unfiltered_html was causing us huge problems on our news site. The in-house writers (a special class of user) are required to place photos and ...
John Le Fevre's user avatar
4 votes

Create user role restricted to specific CPT

You need to register the CPT with your custom capability, then assign that specific cap to the user. When passing the arguments to register_post_type, set capability_type to your new capability, so ...
Morgan Estes's user avatar
  • 1,525
4 votes

How to enable the theme editor cap for an editor role?

The edit_themes capability is what allows access to Appearance > Theme Editor: function wpse243341_modify_editor_role() { $role = get_role( 'editor' ); $role->add_cap( 'edit_themes' ); } ...
Dave Romsey's user avatar
  • 17.7k
4 votes

How to get all users with Author role capabilities?

Here's a way to collect roles with the publish_posts capability: $roles__in = []; foreach( wp_roles()->roles as $role_slug => $role ) { if( ! empty( $role['capabilities']['publish_posts'] ) ...
birgire's user avatar
  • 67.4k
4 votes

Custom role based users are not able to access wp-admin

The read capability must be set to true, so they can access. Keep in mind, roles are saved to the database, when you run it on every init action, this is considered to be time consuming. The Codex ...
websupporter's user avatar
  • 2,979
4 votes

Prevent user creating new users with specific roles

One step is to use the editable_roles filter to remove roles from the dropdown but this doesn't prevent the user from modifying the select value and create a user with "not allowed" role. Yes it does....
swissspidy's user avatar
  • 3,844

Only top scored, non community-wiki answers of a minimum length are eligible