Home / admin / Add and remove wordpress user roles
  • How to Add and remove wordpress user roles

    wordpress user roles admin menu screenshot

    With WordPress you can add and remove roles very easily. The first snippet will add a new role called “manager” with some basic capabilities. You can view the WordPress roles and capabilities page for more extensive details on the capabilities available that you can assign to a custom role. The second snippet will remove some of the existing roles “editor, author, contributor, subscriber” however this could also remove a custom role. NOTE: if you remove an existing role it will be gone! So please be careful when removing roles.

    ( click code to copy )

    wordpress snippet : PHP - Remove

    <>
    function wps_add_role() {
        add_role( 'manager', 'Manager',
                 array(
                      'read',
                      'edit_posts',
                      'delete_posts',
                      )
        );
    }
    add_action( 'init', 'wps_add_role' );
    
    ( click code to copy )

    wordpress snippet : PHP - Remove

    <>
    function wps_remove_role() {
        remove_role( 'editor' );
        remove_role( 'author' );
        remove_role( 'contributor' );
        remove_role( 'subscriber' );
    }
    add_action( 'init', 'wps_remove_role' );
    

    ( WordPress codex functions, hooks, in this snippet. )

    delete_post, edit_post, init, add_role, remove_role, add_action, wp,
  • ??????? ????????

    Very interesting. Can we add a Manager role that will be able to see only the appearance section, not the plugin section?

    • Take a look at edit_themes and some of the options to see what you can do.