wp-includes/user.php:2221Inserts 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: 'modern'
$use_sslbooldefault: false
$user_registeredstring
$user_activation_keystringdefault: empty
$spambooldefault: false
$show_admin_bar_frontstringdefault: 'true'
$rolestring
$localestringdefault: empty
$meta_inputarraydefault: empty
int|WP_Error18 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.
Fires after the user password is set.
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(); } elseif ( $userdata instanceof Traversable ) { $userdata = iterator_to_array( $userdata ); } elseif ( $userdata instanceof ArrayAccess ) { $userdata_obj = $userdata; $userdata = array(); foreach ( array( 'ID', 'user_pass', 'user_login', 'user_nicename', 'user_url', 'user_email', 'display_name', 'nickname', 'first_name', 'last_name', 'description', 'rich_editing', 'syntax_highlighting', 'infinite_scrolling', 'comment_shortcuts', 'admin_color', 'use_ssl', 'user_registered', 'user_activation_key', 'spam', 'show_admin_bar_front', 'role', 'locale', 'meta_input', ) as $key ) { if ( isset( $userdata_obj[ $key ] ) ) { $userdata[ $key ] = $userdata_obj[ $key ]; } } } else { $userdata = (array) $userdata; } // 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; if ( empty( $userdata['user_pass'] ) ) { wp_trigger_error( __FUNCTION__, __( 'The user_pass field is required when creating a new user. The user will need to reset their password before logging in.' ), E_USER_WARNING ); // Set the password as an empty string to force the password reset flow. $userdata['user_pass'] = ''; } // Hash the password. $user_pass = wp_hash_password( $userdata['user_pass'] ); }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.