WordPress remove_role() not working

Hi I’m trying to deleting some custom created roles with,

$wp_roles = new WP_Roles();
$wp_roles->remove_role("your_role");

Some roles deleted fine. but when I delete few otehr roles first time they seems to deleted successfully. but after next refresh they are recreating.

Read More

I’m pretty sure , this is not a something that is recreating the role if it is not exists. As I created those roles via add_role those roles are totally independent and no inside code creating those.

Thanks

I tried with “User Role Editor” plugin not worked too

Related posts

Leave a Reply

2 comments

  1. If you have the access to phpmyadmin, try editing the database directly.

    wp_user_roles is in wp_options table.

    Each user’s role/capability is in a wp_capabilities record in wp_usermeta

    There you can add/edit/delete any roles with minimum mysql knowledge.

  2. Try with this

    //check if role exist before removing it
    if( get_role('subscriber') ){
          remove_role( 'subscriber' );
    }
    
    //check if role exist before removing it
    if( get_role('contributor') ){
          remove_role( 'contributor' );
    }
    
    //check if role exist before removing it
    if( get_role('editor') ){
          remove_role( 'editor' );
    }
    
    //check if role exist before removing it
    if( get_role('author') ){
          remove_role( 'author' );
    }