do_action( 'user_register', int $user_id, array $userdata )

Fires immediately after a new user is registered.


Parameters

$user_id int
User ID.
$userdata array
The raw array of data passed to wp_insert_user() .
More Arguments from wp_insert_user( ... $userdata ) An array, object, or WP_User object of user data arguments.
  • IDint
    User ID. If supplied, the user will be updated.
  • user_passstring
    The plain-text user password.
  • user_loginstring
    The user's login username.
  • user_nicenamestring
    The URL-friendly user name.
  • user_urlstring
    The user URL.
  • user_emailstring
    The user email address.
  • display_namestring
    The user's display name.
    Default is the user's username.
  • nicknamestring
    The user's nickname.
    Default is the user's username.
  • first_namestring
    The user's first name. For new users, will be used to build the first part of the user's display name if $display_name is not specified.
  • last_namestring
    The user's last name. For new users, will be used to build the second part of the user's display name if $display_name is not specified.
  • descriptionstring
    The user's biographical description.
  • rich_editingstring
    Whether to enable the rich-editor for the user.
    Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
  • syntax_highlightingstring
    Whether to enable the rich code editor for the user.
    Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
  • comment_shortcutsstring
    Whether to enable comment moderation keyboard shortcuts for the user. Accepts 'true' or 'false' as a string literal, not boolean. Default 'false'.
  • admin_colorstring
    Admin color scheme for the user. Default 'fresh'.
  • use_sslbool
    Whether the user should always access the admin over https. Default false.
  • user_registeredstring
    Date the user registered in UTC. Format is 'Y-m-d H:i:s'.
  • user_activation_keystring
    Password reset key. Default empty.
  • spambool
    Multisite only. Whether the user is marked as spam.
    Default false.
  • show_admin_bar_frontstring
    Whether to display the Admin Bar for the user on the site's front end. Accepts 'true' or 'false' as a string literal, not boolean. Default 'true'.
  • rolestring
    User's role.
  • localestring
    User's locale. Default empty.
  • meta_inputarray
    Array of custom user meta values keyed by meta key.
    Default empty.

Top ↑

More Information

This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

Not all user meta data has been stored in the database when this action is triggered. For example, nickname is in the database but first_name and last_name are not (as of v3.9.1). The password has already been encrypted when this action is triggered.

Typically, this hook is used for saving additional user meta passed by custom registration forms.


Top ↑

Source

File: wp-includes/user.php. View all references

do_action( 'user_register', $user_id, $userdata );


Top ↑

Changelog

Changelog
Version Description
5.8.0 The $userdata parameter was added.
1.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Example migrated from Codex:

    This example will save a first_name field passed by a custom registration field.

    Also, keep in mind that validation of registration fields should not be performed within this hook! Validate using the registration_errors hook instead (the user_register hook will not be called if registration_errors validation fails).

    add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
    
    function myplugin_registration_save( $user_id ) {
    
        if ( isset( $_POST['first_name'] ) )
            update_user_meta($user_id, 'first_name', $_POST['first_name']);
    
    }

You must log in before being able to contribute a note or feedback.