function wpcreateuser(){ $loginName = rawurldecode($_REQUEST['login']); $firstName = rawurldecode($_REQUEST['firstname']); $lastName = rawurldecode($_REQUEST['lastname']); $email = rawurldecode($_REQUEST['email']); $user_data = array( 'ID' => '', 'user_pass' => wp_generate_password(), 'user_login' => $loginName, 'display_name' => $loginName, 'first_name' => $firstName, 'last_name' => $lastName, 'user_email' => $email, 'role' => get_option('default_role') // Use default role or another role, e.g. 'editor' ); $tempPass = genTempPassword(8); $user_id = wp_insert_user( $user_data ); wp_set_password($tempPass, $user_id); $headers = "From: Wordpress <".get_bloginfo('admin_email').">\r\n".'X-Mailer: PHP/' . phpversion(); $subject = "[".get_bloginfo('name')."] Your username and password"; $siteurl = get_bloginfo('siteurl')."/wp-login.php"; $msg = wordwrap("Username: ".$loginName." \r\n "."Password: ".$tempPass." \r\n ".$siteurl); wp_mail($email, $subject, $msg, $headers); die(); } function genTempPassword ($length = 8) { // given a string length, returns a random password of that length $password = ""; // define possible characters $possible = "0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; }
Thursday, October 17, 2013
Create WP User and send email notification
Share This!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment