user_register

Home » Hooks » user_register

The user_register hook is a WordPress action hook that is triggered after a new user is registered on a WordPress site. This hook allows developers to perform custom actions when a user is added to the site, such as sending a notification email or adding custom user meta data.

The user_register hook is used primarily by plugin and theme developers who want to extend the functionality of WordPress registration process. With this hook, developers can add their own custom code to be executed when a user is registered, providing a way to customize the user registration process to meet specific needs.

Here is an example usage code of the user_register hook:

function my_custom_function( $user_id ) {
    // Send a notification email to the site administrator
    wp_mail( 'admin@example.com', 'New User Registered', 'A new user has registered on your site.' );
}
add_action( 'user_register', 'my_custom_function' );

In the above example, we have added a custom function called my_custom_function to be executed when a new user is registered. This function sends a notification email to the site administrator, letting them know that a new user has registered on the site.

Overall, the user_register hook is a powerful tool for developers who want to extend the functionality of the WordPress registration process and add their own custom code to be executed when a user is registered.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.