How to make user inactive by default while registering?

/*
Plugin Name: Role-less New Users
Description: Removes all roles from new registrations.
Author: 5ubliminal
*/
// Hook into the registration process
add_action('user_register', function($user_id){
    $user = new WP_User($user_id);
    // Remove all user roles after registration
    foreach($user->roles as $role){
        $user->remove_role($role);
    }
}, 11);

Create a new .php file. Paste the code above in it. Put it in your /wp-content/plugins folder and activate it. Do test it!

PS: Be advised, PHP 5.3 syntax, closures used. Incompatible with PHP 5.2 or older.

Leave a Comment