Skip to main content
Changed role name in final snipped to align the entire example, also fixed links
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

    $admin_role_set = get_role( 'administrator' )->capabilities;
    
  2. You can create a new user role by using add_role, see the Codexhandbook for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

    $role = 'content_admin';
    $display_name = 'Content Admin';
    add_role( $role, $display_name, $admin_role_set );
    
  3. By checking the Roles and CapabilitiesRoles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilitieshandbook, we will be needing to remove edit_pluginsedit_plugins & edit_themesedit_themes capabilities, we can achieve that by using remove_cap()remove_cap():

    remove_cap( 'content_admin', 'edit_plugins' ); remove_cap( 'content_admin', 'edit_themes' );

    remove_cap( 'content_admin', 'edit_plugins' );
    remove_cap( 'content_admin', 'edit_themes' );
    

Hope this helps!

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

  2. You can create a new user role by using add_role, see Codex for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

  3. By checking the Roles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilities we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'content_admin', 'edit_plugins' ); remove_cap( 'content_admin', 'edit_themes' );

Hope this helps!

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;
    
  2. You can create a new user role by using add_role, see the handbook for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin';
    $display_name = 'Content Admin';
    add_role( $role, $display_name, $admin_role_set );
    
  3. By checking the Roles and Capabilities list from the handbook, we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'content_admin', 'edit_plugins' );
    remove_cap( 'content_admin', 'edit_themes' );
    
Changed role name in final snipped to align the entire example
Source Link

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

  2. You can create a new user role by using add_role, see Codex for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

  3. By checking the Roles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilities we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'editor''content_admin', 'edit_plugins' ); remove_cap( 'editor''content_admin', 'edit_themes' );

Hope this helps!

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

  2. You can create a new user role by using add_role, see Codex for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

  3. By checking the Roles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilities we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'editor', 'edit_plugins' ); remove_cap( 'editor', 'edit_themes' );

Hope this helps!

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

  2. You can create a new user role by using add_role, see Codex for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

  3. By checking the Roles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilities we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'content_admin', 'edit_plugins' ); remove_cap( 'content_admin', 'edit_themes' );

Hope this helps!

Source Link
Mac organo
  • 148
  • 1
  • 1
  • 6

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 question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme, to do that:

  1. Let's say you would like to copy the existing capabilities of Administrator, do it by:

    $admin_role_set = get_role( 'administrator' )->capabilities;

  2. You can create a new user role by using add_role, see Codex for more details. We can then use the list of capabilities that we have from #1 by using:

    $role = 'content_admin'; $display_name = 'Content Admin'; add_role( $role, $display_name, $admin_role_set );

  3. By checking the Roles and Capabilities list from the codex: https://codex.wordpress.org/Roles_and_Capabilities we will be needing to remove edit_plugins & edit_themes capabilities, we can achieve that by using remove_cap():

    remove_cap( 'editor', 'edit_plugins' ); remove_cap( 'editor', 'edit_themes' );

Hope this helps!