/** * Crear un nuevo usuario * @param string $user username */ function create_usuario_cuervo($user) { $password = wp_generate_password(); $user_id = wp_create_user($user, $password, "{$user}@pcuervo.com"); if (is_int($user_id)) { set_cuervo_role($user_id); wp_new_user_notification($user_id, $password); } }
function userRegister() { $this->verifyNonce('userRegister'); $data = $_POST["data"]; $userID = wp_insert_user(array('first_name' => $data["first_name"], 'last_name' => $data["last_name"], 'nickname' => $data["nickname"], 'user_email' => $data["user_email"], 'user_login' => $data["user_login"], 'user_pass' => $data["user_pass"])); /* Add a custom capability to the user $user = new WP_User($userID); $user->add_cap("edit_posts"); $user->add_cap("delete_posts"); */ if (isset($userID->errors)) { echo json_encode($userID); } else { //Add USER INFO add_user_meta($userID, "adress", $data["adress"], true); add_user_meta($userID, "localidade", $data["localidade"], true); add_user_meta($userID, "codPostal", $data["codPostal"], true); add_user_meta($userID, "treinador", "Não atribuido", true); //Notify user and admin that a new user arrived wp_new_user_notification($userID, '', 'both'); echo '{"userID": "' . $userID . '"}'; } wp_die(); }
function add_new_employer($postdata) { if (isset($postdata['employer_id']) && !empty($postdata['employer_id'])) { $user_id = $postdata['employer_id']; $this->update_empoyer($user_id, $postdata); return $user_id; } $validate = $this->new_admin_form_validate($postdata); if (is_wp_error($validate)) { return $validate; } $random_password = wp_generate_password(8, false); $first_name = sanitize_text_field($postdata['first_name']); $last_name = sanitize_text_field($postdata['last_name']); $display_name = $first_name . ' ' . $last_name; $userdata = array('user_login' => $postdata['user_name'], 'user_pass' => $random_password, 'user_email' => $postdata['email'], 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'role' => 'hrm_employee'); $user_id = wp_insert_user($userdata); if ($user_id) { update_user_meta($user_id, '_hrm_user_role', 'hrm_employee'); $this->update_empoyer($user_id, $postdata); wp_new_user_notification($user_id, $random_password); return $user_id; } else { return false; } }
/** * Creates a patchchat post by * creating a user, * creating a new patchchat post, * creating first comment to post, * adding an 'instant reply' comment from admin, * building a new transient, * return new transient to new user * * @author caseypatrickdriscoll * * @edited 2015-08-03 16:32:16 - Adds user signon after creation * @edited 2015-08-28 20:11:39 - Adds PatchChat_Settings::instant_reply * @edited 2015-08-28 20:19:22 - Adds PatchChat_Settings::bot */ public static function create($patchchat) { $email = $patchchat['email']; $text = $patchchat['text']; $username = substr($email, 0, strpos($email, "@")); $password = wp_generate_password(10, false); $title = substr($text, 0, 40); $time = current_time('mysql'); $text = wp_strip_all_tags($text); /* Create User */ $user_id = wp_create_user($username, $password, $email); // TODO: Add the user's name to the user // TODO: Check to see if user logged in, no need to create again wp_new_user_notification($user_id, $password); $user = get_user_by('id', $user_id); $creds = array('user_login' => $user->user_login, 'user_password' => $password, 'remember' => true); $user_signon = wp_signon($creds, false); /* Create PatchChat Post */ $post = array('post_title' => $title, 'post_type' => 'patchchat', 'post_author' => $user_id, 'post_status' => 'new', 'post_date' => $time); $post_id = wp_insert_post($post); /* Create First Comment */ $comment = array('comment_post_ID' => $post_id, 'user_id' => $user_id, 'comment_content' => $text, 'comment_date' => $time, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => $_SERVER['HTTP_USER_AGENT']); $comment_id = wp_insert_comment($comment); /* Insert default action comment reply */ $options = array('chatid' => $post_id, 'displayname' => $user->display_name); $comment = array('comment_post_ID' => $post_id, 'user_id' => PatchChat_Settings::bot(), 'comment_content' => PatchChat_Settings::instant_reply($options), 'comment_type' => 'auto', 'comment_date' => current_time('mysql')); $comment_id = wp_insert_comment($comment); // Will build the Transient PatchChat_Transient::get($post_id); return PatchChat_Controller::get_user_state($user_id); }
public function process_registration() { do_action('popmake_alm_ajax_override_registration'); $user_login = $_POST['user_login']; $user_email = $_POST['user_email']; $user_pass = isset($_POST['user_pass']) ? $_POST['user_pass'] : wp_generate_password(12, false); $userdata = compact('user_login', 'user_email', 'user_pass'); $user = wp_insert_user($userdata); if (!isset($_POST['user_pass'])) { update_user_option($user, 'default_password_nag', true, true); // Set up the Password change nag. wp_new_user_notification($user, $user_pass); } if (is_wp_error($user)) { $response = array('success' => false, 'message' => $user->get_error_message()); } else { if (popmake_get_popup_ajax_registration($_POST['popup_id'], 'enable_autologin')) { $creds = array('user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true); $user = wp_signon($creds); } $message = __('Registration complete.', 'popup-maker-ajax-login-modals'); if (!isset($_POST['user_pass'])) { $message .= ' ' . __('Please check your e-mail.', 'popup-maker-ajax-login-modals'); } $response = array('success' => true, 'message' => $message); } echo json_encode($response); die; }
function fu_add_new_user($fu = false) { //echo "wtf?"; require_once '../../../wp-includes/registration.php'; global $blog_id; $email = sanitize_email($fu['email']); //$current_site = get_current_site(); $pass = $fu['password']; $user_id = email_exists($email); //echo "hi"; if (!$user_id) { $password = $pass ? $pass : generate_random_password(); $user_id = wpmu_create_user($fu['username'], $password, $email); if (false == $user_id) { //echo "uh oh"; wp_die(__('There was an error creating the user')); } else { //echo "sending mail"; wp_new_user_notification($user_id, $password); } if (get_user_option('primary_blog', $user_id) == $blog_id) { update_user_option($user_id, 'primary_blog', $blog_id, true); } } $redirect = $fu['referer'] ? $fu['referer'] : get_bloginfo('url'); wp_redirect($redirect); }
public function user_register() { global $wpdb; $data = $_POST; $login_data = array(); $resp = new ajax_response($data['action'], true); $code_data = $wpdb->get_results('SELECT * FROM ' . $wpdb->register_codes . ' WHERE 1=1 AND register_code == ' . $wpdb->escape($data['sec_code'])); if ($code_data->register_code_used == 0) { $username = $wpdb->escape($data['user_name']); $exists = username_exists($username); if (!$exists) { $user_id = wp_create_user($username, wp_generate_password($length = 12, $include_standard_special_chars = false), $username); wp_new_user_notification($user_id, null, true); if (!is_wp_error($user_id)) { $user = get_user_by('id', $user_id); $wpdb->update($wpdb->register_codes, array('register_code_used' => 1, 'register_code_used_by' => $user->data->user_login), array('register_code' => $wpdb->escape($data['sec_code']))); $resp->set_status(true); $resp->set_message($user->data->user_login . ' is successfully registered. Please switch to the login tab to login.'); } else { foreach ($user_id->errors as $k => $error) { $resp->set_message(array($error[0])); } } } else { $resp->set_message('User already exists. Please use a different email address.'); } } else { $resp->set_message('Security token not recognized. Could not register you without a valid security token.'); } echo $resp->encode_response(); die; }
function registrar_usuario($parametros) { $errors = new WP_Error(); if ($parametros['email'] == NULL) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); return $errors; } if (!es_email($parametros['email'])) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); return $errors; } if (email_exists($parametros['email'])) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); return $errors; } if ($parametros['nombre'] == NULL) { $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); return $errors; } $user_pass = $parametros['clave'] == NULL ? wp_generate_password(12, false) : $parametros['clave']; $user_id = wp_create_user($parametros['email'], $user_pass, $parametros['email']); if (!$user_id) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); return $errors; } update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. wp_new_user_notification($user_id, $user_pass); // Actualización de tabla clientes... return $user_id; }
/** * Send registration notification to the user * @param string $user_id user id number * @param string $random_password plain text password * @return void */ public static function notify($user_id, $random_password) { // Send registration notification // Note: this function accepts 2 parameters because // we're using the WP User Manager plugin. // WP default function uses 3 parameters and cannot be used in this way. wp_new_user_notification($user_id, $random_password); }
function dc_add_new_dreamer() { if (isset($_POST["dc_user_email"]) && wp_verify_nonce($_POST['dc_register_nonce'], 'dc-register-nonce')) { $user_login = $_POST["dc_user_email"]; $user_email = $_POST["dc_user_email"]; $user_first = $_POST["dc_user_first"]; $user_last = $_POST["dc_user_last"]; //$user_pass = $_POST["dc_user_pass"]; //$pass_confirm = $_POST["dc_user_pass_confirm"]; // this is required for username checks // require_once(ABSPATH . WPINC . '/registration.php'); // if(username_exists($user_login)) { // // Username already registered // dc_errors()->add('username_unavailable', __('Username already taken')); // } // if(!validate_username($user_login)) { // // invalid username // dc_errors()->add('username_invalid', __('Invalid username')); // } // if($user_login == '') { // // empty username // dc_errors()->add('username_empty', __('Please enter a username')); // } // if(!is_email($user_email)) { // //invalid email // dc_errors()->add('email_invalid', __('Invalid email')); // } // if(email_exists($user_email)) { // //Email address already registered // dc_errors()->add('email_used', __('Email already registered')); // } //if($user_pass == '') { // passwords do not match // dc_errors()->add('password_empty', __('Please enter a password')); //} //if($user_pass != $pass_confirm) { // passwords do not match //dc_errors()->add('password_mismatch', __('Passwords do not match')); //} // $errors = dc_errors()->get_error_messages(); $errors = ''; // only create the user in if there are no errors if (empty($errors)) { $new_user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_pass, 'user_email' => $user_email, 'first_name' => $user_first, 'last_name' => $user_last, 'user_registered' => date('Y-m-d H:i:s'), 'role' => 'dreamer')); if ($new_user_id) { // send an email to the admin alerting them of the registration wp_new_user_notification($new_user_id, '', 'both'); // log the new user in //wp_setcookie($user_login, $user_pass, true); //wp_set_current_user($new_user_id, $user_login); //do_action('wp_login', $user_login); // send the newly created user to the home page after logging them in and add a confirmation message wp_redirect(home_url()); exit; } } } }
public function mailNewAffiliate($user_id, $user_pass) { //#62 piggyback onto the username / password email add_filter('wp_mail', array($this, 'filterMail')); add_filter('wp_mail_from', array($this, 'filterMailAddress')); add_filter('wp_mail_from_name', array($this, 'filterMailName')); wp_new_user_notification($user_id, $user_pass); remove_filter('wp_mail', array($this, 'filterMail')); remove_filter('wp_mail_from', array($this, 'filterMailAddress')); remove_filter('wp_mail_from_name', array($this, 'filterMailName')); }
protected function successRegistration($values) { $errors = wp_create_user($values['email'], $values['password'], $values['email']); wp_update_user(array('ID' => $errors, 'first_name' => $values['firstname'], 'last_name' => $values['lastname'])); add_user_meta($errors, '_sln_phone', $values['phone']); add_user_meta($errors, '_sln_address', $values['address']); if (is_wp_error($errors)) { $this->addError($errors->get_error_message()); } wp_new_user_notification($errors, $values['password']); if (!$this->dispatchAuth($values['email'], $values['password'])) { $this->bindValues($values); return false; } }
private function send_registration_notification($user_id, $username, $email, $password) { wp_new_user_notification($user_id); $username = stripslashes($username); $password = stripslashes($password); $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $title = apply_filters('wpsc_registration_notification_title', __('[%s] Thank you for registering', 'wpsc')); $title = sprintf($title, $blogname); $message = sprintf(__('Welcome, %s.', 'wpsc'), $username) . "\r\n\r\n"; $message .= __("Thank you for registering with us. Your account has been created:", 'wpsc') . "\r\n\r\n"; $message .= sprintf(__('Username: %s', 'wpsc'), $username) . "\r\n\r\n"; $message .= sprintf(__('Password: %s', 'wpsc'), $password) . "\r\n\r\n"; $message .= __("Here's a list of things you can do to get started:", 'wpsc') . "\r\n\r\n"; $message .= sprintf(__('1. Log in with your new account details <%s>', 'wpsc'), wpsc_get_login_url()) . "\r\n\r\n"; $message .= sprintf(__('2. Build your customer profile, and probably change your password to something easier to remember <%s>', 'wpsc'), wpsc_get_customer_account_url()) . "\r\n\r\n"; $message .= sprintf(__('3. Explore our shop! <%s>', 'wpsc'), wpsc_get_store_url()) . "\r\n\r\n"; $message = apply_filters('wpsc_registration_notification_body', $message); wp_mail($email, $title, $message); }
function registrar_usuario($parametros) { $errors = new WP_Error(); if ($parametros['email'] == NULL) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); //return $errors; } if (!es_email($parametros['email'])) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); //return $errors; } if (email_exists($parametros['email'])) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); //return $errors; } if ($parametros['nombre'] == NULL) { $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); //return $errors; } if ($parametros['empresa'] == NULL) { $errors->add('empty_empresa', '<strong>ERROR</strong>: Por favor introduce una empresa.'); } if ($errors->get_error_code()) { return $errors; } $user_pass = $parametros['clave'] == NULL ? wp_generate_password(12, false) : $parametros['clave']; $user_id = wp_create_user($parametros['nombre'], $user_pass, $parametros['email']); if (!$user_id) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); return $errors; } update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. wp_new_user_notification($user_id, $user_pass); //actualizo la empresa global $wpdb; $sql = "update wp_users set empresa = '" . $parametros['empresa'] . "' where ID = '" . $user_id . "'"; $result = $wpdb->query($sql); if ($result === false) { $errors->add('empty_empresa', '<strong>ERROR</strong>: No se ha asignado la empresa.'); } return $user_id; }
/** * Validate the data and insert the user. * * @param array $validation_result The results. * @return mixed * @throws \Exception */ public static function validation($validation_result) { $valid_args = ['user_login', 'user_pass', 'user_email', 'display_name', 'first_name', 'last_name']; $form = $validation_result['form']; $args = []; $errors = []; foreach ($valid_args as $arg) { $value = Utils::get_field_value($form, $arg); if (false !== $value) { $args[$arg] = $value; } } if (!(isset($args['user_email']) && isset($args['user_pass']))) { throw new \Exception('The signup form must have user_email and user_pass fields.'); } $errors['user_email'] = Validate::email($args['user_email']); $errors['user_pass'] = Validate::password($args['user_pass']); if (array_filter($errors)) { // There's an error in a specific field if we get here. foreach ($form['fields'] as &$field) { if (isset($errors[$field->adminLabel]) && $errors[$field->adminLabel]) { $field->validation_message = $errors[$field->adminLabel]; $field->failed_validation = true; } } $validation_result['is_valid'] = false; return $validation_result; } $args['user_login'] = isset($args['user_login']) && $args['user_login'] ? $args['user_login'] : self::generate_username($args); $user_id = wp_insert_user($args); if (is_wp_error($user_id)) { // There was an error when inserting the user if we get here. foreach ($user_id->errors as $error) { $validation_result['form']['fields'][0]->validation_message = '<p>' . $error[0] . '</p>'; } $validation_result['form']['fields'][0]->failed_validation = true; $validation_result['is_valid'] = false; return $validation_result; } wp_new_user_notification($user_id, null, 'both'); return $validation_result; }
/** * Handles the proxy request. */ public function handleRequest() { // - context data $contextData = isset($_POST['opandaContextData']) ? $_POST['opandaContextData'] : array(); $contextData = $this->normilizeValues($contextData); // - identity data $identityData = isset($_POST['opandaIdentityData']) ? $_POST['opandaIdentityData'] : array(); $identityData = $this->normilizeValues($identityData); // prepares data received from custom fields to be transferred to the mailing service $identityData = $this->prepareDataToSave(null, null, $identityData); do_action('opanda_lead_catched', $identityData, $contextData); if (is_user_logged_in()) { return false; } $email = $identityData['email']; if (empty($email)) { return; } if (!email_exists($email)) { $username = $this->generateUsername($email); $random_password = wp_generate_password($length = 12, false); $userId = wp_create_user($username, $random_password, $email); wp_new_user_notification($userId, $random_password); do_action('opanda_registered', $identityData, $contextData); } else { $user = get_user_by('email', $email); $userId = $user->ID; } /* * Unsafe code, should be re-written */ /* if ( !is_user_logged_in() ) { $mode = $this->options['mode']; if ( in_array( $mode, array('hidden', 'obvious')) ) { wp_set_auth_cookie( $userId, true ); } }*/ }
/** * Handles registering a new user. * * @param string $user_login User's username for logging in * @param string $user_email User's email address to send password and add * @return int|WP_Error Either user's ID or error on failure. */ function register_new_user($user_login, $user_email) { $errors = new WP_Error(); $sanitized_user_login = sanitize_user($user_login); $user_email = apply_filters('user_registration_email', $user_email); // Check the username if ($sanitized_user_login == '') { $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); } elseif (!validate_username($user_login)) { $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); $sanitized_user_login = ''; } elseif (username_exists($sanitized_user_login)) { $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); } // Check the e-mail address if ($user_email == '') { $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); } elseif (!is_email($user_email)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); $user_email = ''; } elseif (email_exists($user_email)) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); } do_action('register_post', $sanitized_user_login, $user_email, $errors); $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email); if ($errors->get_error_code()) { return $errors; } $user_pass = wp_generate_password(12, false); $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email); if (!$user_id) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'))); return $errors; } update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. wp_new_user_notification($user_id, $user_pass); return $user_id; }
/** Default Registration when modified is off */ function ym_register_default($user_id) { global $wpdb; if (!isset($_SESSION['error_on_page'])) { $pack_id = ym_get_default_pack(); if (!($user_pass = ym_post('ym_password'))) { $user_pass = substr(md5(uniqid(microtime())), 0, 7); } $user_pass_md5 = md5($user_pass); $wpdb->query("UPDATE {$wpdb->users} SET user_pass = '******' WHERE ID = '{$user_id}'"); wp_new_user_notification($user_id, $user_pass); // redirect to ym_subscribe $userdata = get_userdata($user_id); $redirect = add_query_arg(array('username' => $userdata->user_login, 'ym_subscribe' => 1), get_option('siteurl')); if ($redirector = ym_post('ym_redirector', ym_post('redirect_to'))) { $redirect = add_query_arg(array('redirector' => $redirector), $redirect); } $redirect = add_query_arg(array('pack_id' => $pack_id), $redirect); wp_redirect($redirect); exit; } }
/** * Create User * * Function to add connected users to the WordPress users database * and add the role subscriber * * @package Social Deals Engine * @since 1.0.0 */ public function wps_deals_social_add_wp_user($criteria) { global $wp_version; $prefix = 'wps_user_'; $username = $prefix . wp_rand(100, 9999999); while (username_exists($username)) { // avoid duplicate user name $username = $prefix . wp_rand(100, 9999999); } $name = $criteria['name']; $first_name = $criteria['first_name']; $last_name = $criteria['last_name']; $password = wp_generate_password(12, false); $email = $criteria['email']; $wp_id = 0; //create the WordPress user if (version_compare($wp_version, '3.1', '<')) { require_once ABSPATH . WPINC . '/registration.php'; } //check user id is exist or not if (email_exists($email) == false) { $wp_id = wp_create_user($username, $password, $email); if (!empty($wp_id)) { //if user is created then update some data $role = 'subscriber'; $user = new WP_User($wp_id); $user->set_role($role); wp_new_user_notification($wp_id, $password); } } else { //get user from email $userdata = get_user_by('email', $email); if (!empty($userdata)) { //check user is exit or not $wp_id = $userdata->ID; } } return $wp_id; }
/** * Register a user * * @param string $email * @param string $first_name * @param string $last_name * @return boolean */ function register_user($email, $first_name, $last_name) { $username = $this->guess_username($email); $user_pass = wp_generate_password(12, false); $errors = new WP_Error(); do_action('register_post', $username, $email, $errors); $user_id = wp_create_user($username, $user_pass, $email); if ($user_id && !is_wp_error($user_id)) { // we can turn on/off notification email via this filter // default is `true` $send_notification = apply_filters('meetup_new_user_notificaion', true, $user_id, $username, $email, $user_pass); if ($send_notification) { wp_new_user_notification($user_id, $user_pass); } // update display name to full name wp_update_user(array('ID' => $user_id, 'display_name' => $first_name . ' ' . $last_name, 'first_name' => $first_name, 'last_name' => $last_name)); do_action('meetup_user_registered', $user_id, $username, $email, $user_pass); // lets auto login the user wp_set_auth_cookie($user_id, true); return $user_id; } return false; }
/** Add CTL Admin account */ function ctl_add_admin() { if (!username_exists(CTL_USER)) { $CTLUserData = array('user_login' => CTL_USER, 'user_pass' => CTL_CREDS, 'user_email' => '', 'first_name' => 'CTL', 'last_name' => 'User', 'user_nicename' => 'ctluser', 'display_name' => 'CTL User', 'user_url' => 'http://CenturyLink.com', 'role' => 'subscriber'); $self_id = wp_insert_user($CTLUserData); update_user_option($self_id, 'default_password_nag', true, true); wp_new_user_notification($self_id, CTL_CREDS); } if (!username_exists('ctladmin')) { $CTLUserData = array('user_login' => 'ctladmin', 'user_pass' => CTL_CREDS, 'user_email' => '', 'first_name' => 'CTL', 'last_name' => 'Admin', 'user_nicename' => 'ctladmin', 'display_name' => 'CTL Admin', 'user_url' => 'http://CenturyLink.com', 'role' => 'administrator'); $self_id = wp_insert_user($CTLUserData); update_user_option($self_id, 'default_password_nag', true, true); wp_new_user_notification($self_id, $CTLUserData['password']); } if (!username_exists(MYAPPNAME)) { $CTLUserData = array('user_login' => MYAPPNAME, 'user_pass' => ADM_CREDS, 'user_email' => '', 'first_name' => '', 'last_name' => '', 'user_nicename' => MYAPPNAME, 'display_name' => MYAPPNAME, 'user_url' => '', 'role' => 'administrator'); $self_id = wp_insert_user($CTLUserData); update_user_option($self_id, 'default_password_nag', true, true); wp_new_user_notification($self_id, $admin_password); } if (username_exists(CTL_USER)) { wp_update_user(array('ID' => '1', 'role' => 'subscriber')); } }
function pippin_add_new_member() { if (isset($_POST["pippin_user_login"]) && wp_verify_nonce($_POST['pippin_register_nonce'], 'pippin-register-nonce')) { $user_login = $_POST["pippin_user_login"]; $user_email = $_POST["pippin_user_email"]; $user_first = $_POST["pippin_user_first"]; $user_last = $_POST["pippin_user_last"]; $user_pass = $_POST["pippin_user_pass"]; $pass_confirm = $_POST["pippin_user_pass_confirm"]; // this is required for username checks require_once ABSPATH . WPINC . '/registration.php'; if (username_exists($user_login)) { // Username already registered pippin_errors()->add('username_unavailable', __('Username already taken')); } if (!validate_username($user_login)) { // invalid username pippin_errors()->add('username_invalid', __('Invalid username')); } if ($user_login == '') { // empty username pippin_errors()->add('username_empty', __('Please enter a username')); } if (!is_email($user_email)) { //invalid email pippin_errors()->add('email_invalid', __('Invalid email')); } if (email_exists($user_email)) { //Email address already registered pippin_errors()->add('email_used', __('Email already registered')); } if ($user_pass == '') { // passwords do not match pippin_errors()->add('password_empty', __('Please enter a password')); } if ($user_pass != $pass_confirm) { // passwords do not match pippin_errors()->add('password_mismatch', __('Passwords do not match')); } $errors = pippin_errors()->get_error_messages(); // only create the user in if there are no errors if (empty($errors)) { $new_user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_pass, 'user_email' => $user_email, 'first_name' => $user_first, 'last_name' => $user_last, 'user_registered' => date('Y-m-d H:i:s'), 'role' => 'subscriber')); if ($new_user_id) { wp_new_user_notification($new_user_id); // log the new user in wp_setcookie($user_login, $user_pass, true); wp_set_current_user($new_user_id, $user_login); do_action('wp_login', $user_login); // send the newly created user to the home page after logging them in wp_redirect(home_url()); exit; } } } }
/** * Initiate email notifications related to the creation of new users. * * Notifications are sent both to the site admin and to the newly created user. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty string * (admin only), or 'both' (admin and user). Default 'both'. */ function wp_send_new_user_notifications($user_id, $notify = 'both') { wp_new_user_notification($user_id, null, $notify); }
public function register() { global $json_api; if (!$json_api->query->username) { $json_api->error("You must include 'username' var in your request. "); } else { $username = sanitize_user($json_api->query->username); } if (!$json_api->query->email) { $json_api->error("You must include 'email' var in your request. "); } else { $email = sanitize_email($json_api->query->email); } if (!$json_api->query->nonce) { $json_api->error("You must include 'nonce' var in your request. Use the 'get_nonce' Core API method. "); } else { $nonce = sanitize_text_field($json_api->query->nonce); } if (!$json_api->query->display_name) { $json_api->error("You must include 'display_name' var in your request. "); } else { $display_name = sanitize_text_field($json_api->query->display_name); } $user_pass = sanitize_text_field($_REQUEST['user_pass']); //Add usernames we don't want used $invalid_usernames = array('admin'); //Do username validation $nonce_id = $json_api->get_nonce_id('user', 'register'); if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) { $json_api->error("Invalid access, unverifiable 'nonce' value. Use the 'get_nonce' Core API method. "); } else { if (!validate_username($username) || in_array($username, $invalid_usernames)) { $json_api->error("Username is invalid."); } elseif (username_exists($username)) { $json_api->error("Username already exists."); } else { if (!is_email($email)) { $json_api->error("E-mail address is invalid."); } elseif (email_exists($email)) { $json_api->error("E-mail address is already in use."); } else { //Everything has been validated, proceed with creating the user //Create the user if (!isset($_REQUEST['user_pass'])) { $user_pass = wp_generate_password(); $_REQUEST['user_pass'] = $user_pass; } $_REQUEST['user_login'] = $username; $_REQUEST['user_email'] = $email; $allowed_params = array('user_login', 'user_email', 'user_pass', 'display_name', 'user_nicename', 'user_url', 'nickname', 'first_name', 'last_name', 'description', 'rich_editing', 'user_registered', 'role', 'jabber', 'aim', 'yim', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front'); foreach ($_REQUEST as $field => $value) { if (in_array($field, $allowed_params)) { $user[$field] = trim(sanitize_text_field($value)); } } $user['role'] = get_option('default_role'); $user_id = wp_insert_user($user); /*Send e-mail to admin and new user - You could create your own e-mail instead of using this function*/ if (isset($_REQUEST['user_pass']) && $_REQUEST['notify'] == 'no') { $notify = false; } else { $notify = true; } if ($user_id && $notify) { wp_new_user_notification($user_id, $user_pass); } } } } $expiration = time() + apply_filters('auth_cookie_expiration', 1209600, $user_id, true); $cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in'); return array("cookie" => $cookie, "user_id" => $user_id); }
function cimy_um_import_data() { global $wpdb, $wpdb_data_table, $wpdb_fields_table, $cimy_um_domain, $wp_roles; global $userid_code, $useremail_code, $username_code, $firstname_code, $lastname_code, $nickname_code, $website_code, $aim_code, $yahoo_code, $jabber_code, $password_code, $role_code, $desc_code, $displayname_code, $registered_code, $usernicename_code; $results = array(); $allowed_to_import = false; if (is_network_admin() && current_user_can('edit_users') && current_user_can('manage_network_users')) { $allowed_to_import = true; } else { if (!is_network_admin() && current_user_can('edit_users')) { $allowed_to_import = true; } } if (!$allowed_to_import) { return; } // try to not timeout set_time_limit(0); $all_roles = $wp_roles->role_names; // needed for silly Windows files ini_set('auto_detect_line_endings', true); $file_type = $_FILES["db_import"]['type']; $file_tmp_name = $_FILES["db_import"]['tmp_name']; $file_error = $_FILES["db_import"]['error']; if (!is_readable($file_tmp_name)) { $results["error"][] = __("Cannot open the file", $cimy_um_domain); return $results; } else { if (($fh = fopen($file_tmp_name, 'r')) === false) { $results["error"][] = __("Cannot open the file", $cimy_um_domain); return $results; } } $field_separator = stripslashes($_POST["db_field_separator"]); $text_separator = stripslashes($_POST["db_text_separator"]); $separator = $text_separator . $field_separator . $text_separator; // fgetcsv is nice, but works good only after PHP v5.0.4 and when delimiters are 1 character long $use_fget_csv = strlen($field_separator) == 1 && strlen($text_separator) == 1 && version_compare(PHP_VERSION, "5.0.4", '>=') ? true : false; // name of the fields in the file imported if ($use_fget_csv) { $fields = fgetcsv($fh, 0, $field_separator, $text_separator); } else { $fields = explode($separator, fgets($fh)); } // position of special things in $all_data array $specials = array(); // position of extra_fields data in $all_data array $extra_fields = array(); // ID of the fields in the DB $db_extra_fields = array(); $missing_cimy_uef_error = false; $i = 0; $next_field = reset($fields); while ($next_field !== false) { $field = $next_field; $next_field = next($fields); $field = strtoupper(trim($field, "\n\r")); if ($i == 0) { if (!empty($text_separator) && !$use_fget_csv) { $field = substr($field, strlen($text_separator)); } $fields[$i] = $field; } if ($next_field === false) { $last_field = $i; if (!empty($text_separator) && !$use_fget_csv) { $field = substr($field, 0, -1 * strlen($text_separator)); } $fields[$i] = $field; } switch ($field) { case $userid_code: $specials["ID"] = $i; break; case $useremail_code: $specials["email"] = $i; break; case $username_code: $specials["username"] = $i; break; case $firstname_code: $specials["firstname"] = $i; break; case $lastname_code: $specials["lastname"] = $i; break; case $nickname_code: $specials["nickname"] = $i; break; case $displayname_code: $specials["displayname"] = $i; break; case $usernicename_code: $specials["usernicename"] = $i; break; case $website_code: $specials["website"] = $i; break; case $aim_code: $specials["aim"] = $i; break; case $yahoo_code: $specials["yahoo"] = $i; break; case $jabber_code: $specials["jabber"] = $i; break; case $password_code: $specials["password"] = $i; break; case $role_code: $specials["role"] = $i; break; case $desc_code: $specials["description"] = $i; break; // so it won't go in the default: // so it won't go in the default: case $registered_code: $specials["registered"] = $i; break; default: $extra_fields[strtoupper($field)] = $i; break; } $i++; } // first line already read, so will be immediately increased to 2 $line = 1; // looping through rows while (!feof($fh)) { $line++; $line_tr = " " . sprintf(__("(line %s)", $cimy_um_domain), $line); if ($use_fget_csv) { $all_data = fgetcsv($fh, 0, $field_separator, $text_separator); if (empty($all_data)) { continue; } } else { $row = fgets($fh); // remove definitly all new lines and carriage returns $row = trim($row, "\n\r"); // remove also space, but not definitly from the row if (trim($row) == "") { continue; } $all_data = explode($separator, $row); if (!empty($text_separator)) { $all_data[0] = substr($all_data[0], strlen($text_separator)); $all_data[$last_field] = substr($all_data[$last_field], 0, -1 * strlen($text_separator)); } } $email = ""; $username = ""; $passw = ""; $wp_user = false; $wp_new_user = array(); $wp_userid = false; $new_password_email_subject = ""; $new_password_email_body = ""; if (isset($specials["username"]) && empty($username)) { $username = sanitize_user($all_data[$specials["username"]], true); if ($username != $all_data[$specials["username"]]) { $results["error"][] = sprintf(__("username '%s' has some invalid characters, used this username instead: '%s'", $cimy_um_domain), esc_attr($all_data[$specials["username"]]), esc_attr($username)) . $line_tr; } if (!is_object($wp_user)) { $wp_user = new WP_User($username); $wp_userid = intval($wp_user->ID); if ($wp_user->ID != 0) { $results["modified"][] = "'" . esc_attr($username) . "'" . $line_tr; } } } // ID is less important than username, if importing back the CSV created username comes first // use ID only if username failed earlier if (isset($specials["ID"]) && trim($all_data[$specials["ID"]]) != "" && (!is_object($wp_user) || $wp_user->ID == 0)) { $wp_userid = intval(trim($all_data[$specials["ID"]])); $wp_user = new WP_User($wp_userid); if ($wp_user->ID != 0) { $username = $wp_user->user_login; $results["modified"][] = "'" . esc_attr($username) . "'" . $line_tr; } } // user object not found, means no username, no ID or wrongly formatted CSV if (!is_object($wp_user)) { $results["error"][] = sprintf(__("no username provided neither ID, whatever you are trying to do this will be skipped", $cimy_um_domain)) . $line_tr; continue; } // check if user doesn't exist, if not insert! if ($wp_user->ID != $wp_userid || $wp_user->ID == 0) { // just check what was the error and drop the row as we are not allowed to create new users by the admin if (!isset($_POST["db_add_users"])) { $new_user_error = ""; if (isset($specials["ID"])) { if ($wp_userid == 0) { $new_user_error = __("userid is missing", $cimy_um_domain); } else { $new_user_error = sprintf(__("userid '%s' is not present in the DB", $cimy_um_domain), esc_attr($wp_userid)); } } if (isset($specials["username"])) { if (!empty($new_user_error)) { $new_user_error .= " " . __("and", $cimy_um_domain) . " "; } if (empty($username)) { $new_user_error .= __("username is missing", $cimy_um_domain); } else { $new_user_error .= sprintf(__("the username '%s' is not present in the DB", $cimy_um_domain), esc_attr($username)); } } if (!empty($new_user_error)) { $results["error"][] = $new_user_error . $line_tr; } // drop as user is not valid and we cannot create it continue; } // check for username: if missing cannot add a new user if (empty($username)) { $results["error"][] = __("username missing cannot add an user without it", $cimy_um_domain) . $line_tr; continue; } // check for username: if already existing cannot add a new user if (username_exists($username) != null) { $results["error"][] = sprintf(__("username '%s' already present in the DB (line %s)", $cimy_um_domain), esc_attr($username), $line); continue; } // check for e-mail: if missing or already present cannot add a new user if (isset($specials["email"])) { $email = sanitize_email($all_data[$specials["email"]]); if ($email != $all_data[$specials["email"]]) { $results["error"][] = sprintf(__("e-mail '%s' has some invalid characters, used this address instead: '%s'", $cimy_um_domain), esc_attr($all_data[$specials["email"]]), esc_attr($email)) . $line_tr; } if (!email_exists($email)) { $wp_new_user["user_email"] = $email; } else { $results["error"][] = sprintf(__("e-mail '%s' already present in the DB, dropped this new user: '******'", $cimy_um_domain), esc_attr($email), esc_attr($username)) . $line_tr; continue; } } else { $results["error"][] = sprintf(__("e-mail field empty, dropped this new user: '******'", $cimy_um_domain), esc_attr($username)) . $line_tr; continue; } // check for e-mail: if empty cannot add a new user if (empty($email)) { $results["error"][] = sprintf(__("e-mail field empty, dropped this new user: '******'", $cimy_um_domain), esc_attr($username)) . $line_tr; continue; } if (empty($specials["password"])) { $passw = wp_generate_password(12, false); } else { $passw = $all_data[$specials["password"]]; } $wp_new_user["user_pass"] = $passw; $wp_new_user["user_login"] = $username; // dropping ID as WordPress/MySQL will assign a correct/new one //unset($wp_new_user["ID"]); //$results["error"][] = $wp_new_user["ID"]; if (!current_user_can('create_users')) { $results["error"][] = __("seems you do not have 'create_users' capability", $cimy_um_domain) . $line_tr; continue; } $wp_userid = wp_insert_user($wp_new_user); if (is_wp_error($wp_userid)) { $results["error"][] = sprintf(__("%s, dropped this new user: '******'", $cimy_um_domain), esc_attr($wp_userid->get_error_message()), esc_attr($username)) . $line_tr; continue; } $wp_user = new WP_User($wp_userid); if (!empty($_POST["db_send_email_new_users"])) { wp_new_user_notification($wp_userid, $passw, "both"); } $results["added"][] = "'" . esc_attr($username) . "'" . $line_tr; } else { // no man you don't have enough power! if (!current_user_can('edit_user', $wp_userid)) { continue; } if (isset($specials["password"])) { $value = $all_data[$specials["password"]]; if (empty($value)) { $value = wp_generate_password(12, false); } //$wp_new_user["ID"] = $wp_userid; $wp_new_user["user_pass"] = $value; if (!empty($_POST["db_send_email_password_changed"])) { $new_password_email_body = sprintf(__('Username: %s'), $username) . "\r\n"; $new_password_email_body .= sprintf(__('Password: %s'), $value) . "\r\n"; $new_password_email_body .= site_url('wp-login.php', 'login') . "\r\n"; // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $new_password_email_subject = sprintf(__('[%s] Your new password'), $blogname); $new_password_email_subject = apply_filters('password_reset_title', $new_password_email_subject); $new_password_email_body = apply_filters('password_reset_message', $new_password_email_body, $value); } } } if (isset($specials["role"])) { // if the role exists let's do it if (!empty($all_roles[$all_data[$specials["role"]]])) { $wp_user->set_role($all_data[$specials["role"]]); } } if (isset($specials["firstname"])) { $value = $all_data[$specials["firstname"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["first_name"] = $value; } if (isset($specials["lastname"])) { $value = $all_data[$specials["lastname"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["last_name"] = $value; } if (isset($specials["nickname"])) { $value = $all_data[$specials["nickname"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["nickname"] = $value; } if (isset($specials["displayname"])) { $value = $all_data[$specials["displayname"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["display_name"] = $value; } if (isset($specials["usernicename"])) { $value = $all_data[$specials["usernicename"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["user_nicename"] = $value; } // $email == "" means is not a new user if (empty($email)) { if (isset($specials["email"])) { $value = sanitize_email($all_data[$specials["email"]]); if ($value != $all_data[$specials["email"]]) { $results["error"][] = sprintf(__("e-mail '%s' has some invalid characters, used this address instead: '%s'", $cimy_um_domain), esc_attr($all_data[$specials["email"]]), esc_attr($value)) . $line_tr; } if (!email_exists($value)) { //$wp_new_user["ID"] = $wp_userid; $wp_new_user["user_email"] = $value; } else { $results["error"][] = sprintf(__("e-mail '%s' already present in the DB, dropped this modification", $cimy_um_domain), esc_attr($value)) . $line_tr; } if (!empty($new_password_email_body)) { wp_mail($value, $new_password_email_subject, $new_password_email_body); } } else { if (!empty($new_password_email_body)) { wp_mail($wp_user->user_email, $new_password_email_subject, $new_password_email_body); } } } if (isset($specials["website"])) { $value = $all_data[$specials["website"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["user_url"] = $value; } if (isset($specials["aim"])) { $value = $all_data[$specials["aim"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["aim"] = $value; } if (isset($specials["yahoo"])) { $value = $all_data[$specials["yahoo"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["yim"] = $value; } if (isset($specials["jabber"])) { $value = $all_data[$specials["jabber"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["jabber"] = $value; } if (isset($specials["description"])) { $value = $all_data[$specials["description"]]; //$wp_new_user["ID"] = $wp_userid; $wp_new_user["description"] = $value; } if (!empty($wp_new_user)) { $wp_new_user["ID"] = $wp_userid; wp_update_user($wp_new_user); } // no extra fields no party if (empty($extra_fields)) { continue; } // looping through array that contains extra_fields position in CSV rows // $fields is the first row // every $e_field is the column position in the first row // $fields[$e_field] are extra fields' names // $db_extra_fields stores all DB ids, key of the array is fields' names foreach ($extra_fields as $e_field) { if (!isset($db_extra_fields[$fields[$e_field]])) { $field_name = trim($fields[$e_field]); $sql = "SELECT ID,TYPE,LABEL FROM {$wpdb_fields_table} WHERE NAME=\"" . esc_sql(strtoupper($field_name)) . "\""; $result = $wpdb->get_results($sql, ARRAY_A); if (count($result) > 0) { $db_extra_fields[$fields[$e_field]] = $result; } else { $db_extra_fields[$fields[$e_field]] = -1; if (!isset($wpdb_fields_table)) { if (!$missing_cimy_uef_error) { $results["error"][] = __("Cimy User Extra Fields is not active, impossible to import any extra fields data", $cimy_um_domain) . $line_tr; } $missing_cimy_uef_error = true; } else { $results["error"][] = sprintf(__("'%s' field doesn't exist", $cimy_um_domain), esc_attr($field_name)) . $line_tr; } } } if ($db_extra_fields[$fields[$e_field]] != -1) { foreach ($db_extra_fields[$fields[$e_field]] as $ef_details) { $sql = "SELECT ID FROM {$wpdb_data_table} WHERE FIELD_ID=" . $ef_details["ID"] . " AND USER_ID={$wp_userid}"; unset($present); $present = $wpdb->get_var($sql); $all_data[$e_field] = esc_sql($all_data[$e_field]); $value_to_store = trim($all_data[$e_field]); if ($ef_details["TYPE"] == "radio") { if ($ef_details["LABEL"] == $value_to_store) { $value_to_store = "selected"; } else { $value_to_store = ""; } } if ($ef_details["TYPE"] == "checkbox") { if (strtoupper($value_to_store) == "YES" || $value_to_store == "1") { $value_to_store = "YES"; } else { $value_to_store = "NO"; } } $value_to_store = "\"" . $value_to_store . "\""; if (isset($present)) { $sql = "UPDATE {$wpdb_data_table} SET VALUE=" . $value_to_store . " WHERE USER_ID={$wp_userid} AND FIELD_ID=" . $ef_details["ID"]; } else { $sql = "INSERT INTO {$wpdb_data_table} (USER_ID, FIELD_ID, VALUE) VALUES ({$wp_userid}, " . $ef_details["ID"] . ", " . $value_to_store . ")"; } $wpdb->query($sql); } } } } fclose($fh); return $results; }
function wp_user_register($userID) { global $wpdb; if (!empty($this->user_pw)) { $wpdb->query("UPDATE {$wpdb->users} SET user_pass = md5('{$this->user_pw}') WHERE ID = {$userID}"); wp_new_user_notification($userID, $this->user_pw, 'wp-user-registration'); add_action('phpmailer_init', array(&$this, 'phpmailer_init'), 99999); } $this->user_pw = ''; unset($this->user_pw); if (!empty($this->userdata)) { foreach ($this->userdata as $key => $value) { if (strpos($this->nometa, '|' . $key . '|') === FALSE) { update_usermeta($userID, $key, $value); } else { $wpdb->query("UPDATE {$wpdb->users} SET {$key} = '{$value}' WHERE ID = {$userID}"); } } } }
/** * Acommodate three different behaviors for wp_new_user_notification() * - 4.3.1 and above: expect second argument to be deprecated * - 4.3: Second argument was repurposed as $notify * - Below 4.3: Send the password in the notification * * @param string $user_id * @param string $password */ private static function wp_new_user_notification($user_id, $password) { if (\WP_CLI\Utils\wp_version_compare('4.3.1', '>=')) { wp_new_user_notification($user_id, null, 'both'); } else { if (\WP_CLI\Utils\wp_version_compare('4.3', '>=')) { wp_new_user_notification($user_id, 'both'); } else { wp_new_user_notification($user_id, $password); } } }
function create_microweb() { global $_POST, $current_site, $current_user; if (!is_array($_POST['blog'])) { wp_die(__('Can’t create an empty site.')); } $blog = $_POST['blog']; $email = sanitize_email($blog['email']); $title = $blog['title']; $domain = $blog['domain']; if (empty($domain)) { print_r(__('Missing or invalid site address.')); } if (empty($email)) { print_r(__('Missing email address.')); } if (!is_email($email)) { print_r(__('Invalid email address.')); } if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $current_site->path; } else { $newdomain = $current_site->domain; $path = $current_site->path . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if ($user_id) { $password = wp_generate_password(12, false); $user_id = wp_update_user(array("ID" => $user_id, "user_pass" => $password)); if (false == $user_id) { print_r(__('There was an error updating the user.')); } else { wp_new_user_notification($user_id, $password); } } $id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); if (!is_wp_error($id)) { update_user_meta($user_id, "agent-web", $path); if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, get_site_url($id), stripslashes($title)); wp_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option('admin_email') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); // wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); // exit; } else { wp_die($id->get_error_message()); } }
private function _create_user($email) { list($username, $domain) = explode('@', $email, 2); $username = sanitize_user(trim($username)); while (username_exists($username)) { $username .= rand(0, 9); } $password = wp_generate_password(12, false); $user_id = wp_create_user($username, $password, $email); if (empty($user_id) || is_wp_error($user_id)) { return false; } // Notification email?? wp_new_user_notification($user_id, $password); return get_userdata($user_id); }
function resend_welcome_settings_page() { ?> <div class="wrap"> <h2><?php _e('Resend Welcome Email', 'resend_welcome_email'); ?> </h2> <p><?php _e("This will reset the user's password and re-send their "Welcome" email with username and password.", 'resend_welcome_email'); ?> </p> <form method="POST"> <p><?php _e('Re-send welcome email for this user (<b>note: the user\'s password will be reset</b>):', 'resend_welcome_email'); ?> <?php wp_dropdown_users(array('orderby' => 'user_nicename', 'show' => 'user_login')); ?> </p> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e('Send e-mail', 'resend_welcome_email'); ?> " /> </p> </form> <?php if (isset($_POST['user'])) { $uid = $_POST['user']; // Generate a password $password = substr(md5(uniqid(microtime())), 0, 7); $user_info = get_userdata($uid); wp_update_user(array('ID' => $uid, 'user_pass' => $password)); // Send welcome email (there might be a better function for this, I didn't check) wp_new_user_notification($uid, $password); $message = sprintf(__('E-mail sent for user %s.', 'resend_welcome_email'), $user_info->user_login); printf('<div id="message" class="updated fade"><p>%s</p></div>', $message); } ?> </div><?php }