Viewing 5 replies - 1 through 5 (of 5 total)
  • Nothing. If you remove “subscriber”, for example, it won’t automatically be replaced with anything similar unless you use add_role(). Or are you asking about removing a role that a user is currently a part of?

    Thread Starter leepettijohn

    (@leepettijohn)

    Yes, if I add plugin that has a role called “New Admin Role” and then change all administrators to that role. When I remove the plugin, and thus, remove the “New Admin Role”, what role replaces that?

    Does WordPress remember the last role registered and change to that?

    No idea; I’m not sure how new roles are stored. It might remember the new role after you delete the plugin, or it might put them in a pseudo-subscriber role, where they have the same abilities as a subscriber but no actual role assigned. The best way to know would be to test it: Install the plugin, make a test user, assign it a unique role, then remove the plugin.

    Edit: You could always ask the plugin author or post a topic through that plugin’s page.

    Thread Starter leepettijohn

    (@leepettijohn)

    Just tested this and if you remove the role, it sets the user to “-No Role For This Site-”

    Thread Starter leepettijohn

    (@leepettijohn)

    BUT …

    Utilizing this code …

    $roles_to_delete = array('role1','role2','role3');
    
    foreach ( $roles_to_delete as $role ){
    	$users = get_users( array( 'role' => $role ) );
    	if ( count( $users ) <= 0 ){
    		remove_role( $role );
    	}
    	else {
    		foreach ($users as $user){
    			$userid = $user->ID;
    			$user_id_role = new WP_User($userid);
    			$user_id_role->set_role(get_option('default_role'));
    		}
    		remove_role( $role );
    	}
    }

    This will scroll through each user of the roles you want to delete and set them to your “default role.” Thereby, helping you clean up your plugin when deleted.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove role, then replaced with …?’ is closed to new replies.