Definition:
function register_new_user( $user_login, $user_email ) {}
Handles registering a new user.
Parameters
- string $user_login: User’s username for logging in
- string $user_email: User’s email address to send password and add
Return values
returns:Either user’s ID or error on failure.
Defined filters
- user_registration_email
apply_filters( 'user_registration_email', $user_email )
- registration_errors
apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email )
Defined actions
- register_post
do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
Source code
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; }
2671
Hey great site, lots of useful info. I am stuck in designing a register form. If I wanted to add a first an last name field to my register form on my wordpress website (there is currently just username and email field, with auto generated password after you submit), how would I use the values that the user inputs into these fields into a table on the mysql database? I already created first_name and last_name fields on phpmyadmin but I dont know how to insert data from there. Thanks!
You should not use a database alteration. Instead you could save this data as user meta using get_user_meta and update_user_meta