I’m doing a site in wordpress and I need some help.
I have a custom registration form where users can sign up and get special roles, but I want to save the users to the database as not activated so that the admin activates them through a plugin. Problem is that the code I’m using, just saves the user in the db immediately and the account is usable.
Any ideas on how to create a new user as not activated?
$newUser = wp_create_user($un, $pw, $em);
if (!$newUser || is_wp_error($newUser)) {
$error = "[:en]Please fill in all fields.[:it]Please fill in all fields.";
} else {
$userinfo = array('ID'=>$newUser, 'first_name' => $fn, 'last_name' => $ln);
wp_update_user($userinfo);
update_usermeta($newUser, 'company', $co);
$user = new WP_User($newUser);
$user->remove_role('subscriber');
$user->add_role($tp);
$success = "[:en]Your registration has been submitted for approval.[:it]Your registration has been submitted for approval.";
wp_new_user_notification($newUser, $pw);
}
5 Answers
WordPress does not have a active/deactivate function out of the box
This worked for me to create users with aditional data.
wp_insert_user(array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email,
'wp_user_level' => $role,
'show_admin_bar_front' => 'false' //you probably won't want normal users to see the admin bar
));
http://codex.wordpress.org/Function_Reference/wp_insert_user
Try adding a temporary role with no rights at all.
PS.
I see you are directly trying to insert the user without validating your data first.
That’s not very safe.