/** * Register a customer to the store website. * * @since 4.0 * * @param string $username Username * @param string $email Email address * @param boolean $redirect Whether or not to redirect to the login page. * * @return mixed Null if redirected or errors are present, User ID if created successfully. */ function wpsc_register_customer($username = '', $email = '', $redirect = true) { $errors = new WP_Error(); do_action('register_post', $username, $email, $errors); $errors = apply_filters('registration_errors', $errors, $username, $email); if ($errors->get_error_code()) { wpsc_set_validation_error($errors); return; } $password = wp_generate_password(12, false); $user_id = wp_insert_user(apply_filters('wpsc_register_customer_args', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email))); $message_collection = WPSC_Message_Collection::get_instance(); if (is_wp_error($user_id)) { foreach ($user_id->get_error_messages() as $message) { $message_collection->add($message, 'error'); } return; } if (!$user_id) { $message = apply_filters('wpsc_register_unknown_error_message', __('Sorry, but we could not process your registration information. Please <a href="mailto:%s">contact us</a>, or try again later.', 'wpsc')); $message_collection->add(sprintf($message, get_option('admin_email'), 'error')); return; } update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. $notification = wpsc_send_registration_notification($user_id, $username, $email, $password); if (!$notification) { $message = apply_filters('wpsc_register_email_did_not_send', __('We were able to create your account, but our server was unable to send an email to you. Please <a href="mailto:%s">contact us</a>.', 'wpsc')); $message_collection->add(sprintf($message, get_option('admin_email'), 'error')); return; } else { $message_collection->add(__('We just sent you an email containing your generated password. Just follow the directions in that email to complete your registration.', 'wpsc'), 'success', 'main', 'flash'); } if ($redirect) { wp_redirect(wpsc_get_login_url()); exit; } else { return $user_id; } }
private function callback_register() { $form_args = wpsc_get_register_form_args(); $validation = wpsc_validate_form($form_args); if (is_wp_error($validation)) { wpsc_set_validation_errors($validation); return; } extract($_POST, EXTR_SKIP); $errors = new WP_Error(); do_action('register_post', $username, $email, $errors); $errors = apply_filters('registration_errors', $errors, $username, $email); if ($errors->get_error_code()) { wpsc_set_validation_error($errors); return; } $password = wp_generate_password(12, false); $user_id = wp_create_user($username, $password, $email); if (is_wp_error($user_id)) { foreach ($user_id->get_error_messages() as $message) { $this->message_collection->add($message, 'error'); } return; } if (!$user_id) { $message = apply_filters('wpsc_register_unknown_error_message', __('Sorry, but we could not process your registration information. Please <a href="mailto:%s">contact us</a>, or try again later.', 'wpsc')); $this->message_collection->add(sprintf($message, get_option('admin_email'), 'error')); return; } update_user_option($user_id, 'default_password_nag', true, true); //Set up the Password change nag. $this->send_registration_notification($user_id, $username, $email, $password); $this->message_collection->add(__('We just sent you an e-mail containing your generated password. Just follow the directions in that e-mail to complete your registration.', 'wpsc'), 'success', 'main', 'flash'); wp_redirect(wpsc_get_login_url()); exit; }