X

How to Add and Remove WordPress User Roles

Snippets by IsItWP

Are you looking for a way to add and remove user roles in WordPress? While there’s probably a plugin for this, we have created a quick code snippet that you can use to add or remove WordPress user roles.

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.

Note: If you remove an existing role, then it will be gone!

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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' );

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 25 best WooCommerce plugins to grow your sales and how to increase maximum file upload size in WordPress.

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!