wp-includes/user.php:2126Inserts a user into the database.
$userdataarray|object|WP_User$IDint
$user_passstring
$user_loginstring
$user_nicenamestring
$user_urlstring
$user_emailstring
$display_namestringdefault: is the user's username
$nicknamestringdefault: is the user's username
$first_namestring
$last_namestring
$descriptionstring
$rich_editingstringdefault: 'true'
$syntax_highlightingstringdefault: 'true'
$comment_shortcutsstringdefault: 'false'
$admin_colorstringdefault: 'fresh'
$use_sslbooldefault: false
$user_registeredstring
$user_activation_keystringdefault: empty
$spambooldefault: false
$show_admin_bar_frontstringdefault: 'true'
$rolestring
$localestringdefault: empty
$meta_inputarraydefault: empty
int|WP_Error17 hooks fire while wp_insert_user() runs, in this order:
Filters a username after it has been sanitized.
Filters the list of disallowed usernames.
Filters a user's nicename before the user is created or updated.
Filters a user's email before the user is created or updated.
Filters a user's URL before the user is created or updated.
Filters a user's nickname before the user is created or updated.
Filters a user's first name before the user is created or updated.
Filters a user's last name before the user is created or updated.
Filters a user's display name before the user is created or updated.
Filters a user's description before the user is created or updated.
Filters user data before the record is created or updated.
Filters a user's meta values and keys immediately after the user is created or updated and before any user meta is inserted or updated.
Filters a user's custom meta values and keys immediately after the user is created or updated and before any user meta is inserted or updated.
Fires immediately after an existing user is updated.
Fires after the user is marked as a SPAM user.
Fires after the user is marked as a HAM user. Opposite of SPAM.
Fires immediately after a new user is registered.
function wp_insert_user( $userdata ) { global $wpdb; if ( $userdata instanceof stdClass ) { $userdata = get_object_vars( $userdata ); } elseif ( $userdata instanceof WP_User ) { $userdata = $userdata->to_array(); } // Are we updating or creating? if ( ! empty( $userdata['ID'] ) ) { $user_id = (int) $userdata['ID']; $update = true; $old_user_data = get_userdata( $user_id ); if ( ! $old_user_data ) { return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) ); } // Slash current user email to compare it later with slashed new user email. $old_user_data->user_email = wp_slash( $old_user_data->user_email ); // Hashed in wp_update_user(), plaintext if called directly. $user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass; } else { $update = false; // Hash the password. $user_pass = wp_hash_password( $userdata['user_pass'] ); } $sanitized_user_login = sanitize_user( $userdata['user_login'], true ); /** * Filters a username after it has been sanitized. * * This filter is called before the user is created or updated. * * @since 2.0.3 * * @param string $sanitized_user_login Username after it has been sanitized. */ $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login ); // Remove any non-printable chars from the login string to see if we have ended up with an empty username. $user_login = trim( $pre_user_login ); // user_login must be between 0 and 60 characters. if ( empty( $user_login ) ) { return new WP_Error( 'empty_user_login', __( 'Cannot create a user with an empty login name.' ) ); } elseif ( mb_strlen( $user_login ) > 60 ) { return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); } if ( ! $update && username_exists( $user_login ) ) { return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); } /** * Filters the list of disallowed usernames. * * @since 4.4.0 * * @param array $usernames Array of disallowed usernames. */ $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); if ( in_array( strtolower( $user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) { return new WP_Error( 'invalid_username', __( 'Sorry, that username is not allowed.' ) ); } /* * If a nicename is provided, remove unsafe user characters before using it. * Otherwise build a nicename from the user_login. */ if ( ! empty( $userdata['user_nicename'] ) ) { $user_nicename = sanitize_user( $userdata['user_nicename'], true ); } else { $user_nicename = mb_substr( $user_login, 0, 50 ); }Introduced in 2.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.