This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Hey there! If you’re diving into WordPress development, you might have come across the edit_user_created_user action hook. This hook fires after a new user has been created. It’s super useful for adding custom functionality when a user is created in WordPress.
To use the edit_user_created_user action, first, you need to register it using add_action
. You can write this code into the functions.php
file of your activated theme or in a custom WordPress Plugin. At WePlugins, we always prefer creating a custom WordPress Plugin when using hooks to ensure nothing breaks when you update your WordPress theme in the future.
In the example below, we define a function weplugins_execute_on_edit_user_created_user_event
which takes 2 parameters and then register it using add_action
. The first parameter edit_user_created_user is the name of the hook, and the second parameter weplugins_execute_on_edit_user_created_user_event
is the name of the function to be called. The third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed to the registered function.
Sometimes, you have to remove a registered hook, so you can use remove_action
to remove the edit_user_created_user action.
Parameters
Below are the 2 parameters required to use this hook:
- $user_id : (int|WP_Error) ID of the newly created user or WP_Error on failure.
- $notify : (string) Type of notification that should happen. See
wp_send_new_user_notifications()
for more information.
Live Example
Below is an example of how you can use this hook:
Example 1: Basic Usage
This example shows how to execute custom code when a new user is created.
function weplugins_execute_on_edit_user_created_user_event($user_id, $notify) { // Add your custom code here } add_action("edit_user_created_user", "weplugins_execute_on_edit_user_created_user_event", 10, 2);
Example 2: Logging User Creation
This example logs the user ID and notification type when a new user is created.
function weplugins_log_user_creation($user_id, $notify) { error_log("New user created with ID: " . $user_id . " and notification type: " . $notify); } add_action("edit_user_created_user", "weplugins_log_user_creation", 10, 2);
Example 3: Send Custom Email
This example sends a custom email to the admin when a new user is created.
function weplugins_send_custom_email_on_user_creation($user_id, $notify) { $user_info = get_userdata($user_id); wp_mail('admin@example.com', 'New User Created', 'A new user has been created: ' . $user_info->user_email); } add_action("edit_user_created_user", "weplugins_send_custom_email_on_user_creation", 10, 2);
To remove a hook callback, use the example below:
remove_action("edit_user_created_user", "weplugins_execute_on_edit_user_created_user_event", 10, 2);
Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you’re having any trouble using this hook or need customization, please contact us. We’d be happy to assist you!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.