X

Add and remove wordpress user roles

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.


function wps_add_role() {
    add_role( 'manager', 'Manager', 
             array(
                  'read',
                  'edit_posts',
                  'delete_posts',
                  )
    );
}
add_action( 'init', 'wps_add_role' );
function wps_remove_role() {
    remove_role( 'editor' );
    remove_role( 'author' );
    remove_role( 'contributor' );
    remove_role( 'subscriber' );
}
add_action( 'init', 'wps_remove_role' );

Comments  Leave a Reply

  1. ??????? ???????? October 3, 2014 at 9:27 am

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

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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!