The after_signup_site WordPress action fires after site signup information has been written to the database.
Usage
add_action('after_signup_site', 'your_custom_function', 10, 7); function your_custom_function($domain, $path, $title, $user, $user_email, $key, $meta) { // your custom code here }
Parameters
$domain
(string) – The requested domain.$path
(string) – The requested path.$title
(string) – The requested site title.$user
(string) – The user’s requested login name.$user_email
(string) – The user’s email address.$key
(string) – The user’s activation key.$meta
(array) – Signup meta data. By default, contains the requested privacy setting and lang_id.
More information
See WordPress Developer Resources: after_signup_site
Examples
Send a welcome email
Send a welcome email to the user after they sign up for a new site.
add_action('after_signup_site', 'send_welcome_email', 10, 7); function send_welcome_email($domain, $path, $title, $user, $user_email, $key, $meta) { // Prepare email content $subject = 'Welcome to ' . $title; $message = 'Hello ' . $user . ',<br><br>'; $message .= 'Thank you for signing up at ' . $domain . $path . '.<br><br>'; $message .= 'Enjoy your new site!<br><br>'; $message .= 'Regards,<br>'; $message .= 'Your Friendly Team'; // Send email wp_mail($user_email, $subject, $message); }
Log signup information
Log signup information to a custom log file for analysis.
add_action('after_signup_site', 'log_signup_information', 10, 7); function log_signup_information($domain, $path, $title, $user, $user_email, $key, $meta) { // Prepare log entry $log_entry = date('Y-m-d H:i:s') . ' | ' . $user . ' | ' . $user_email . ' | ' . $domain . $path . "\n"; // Append to log file file_put_contents('signups.log', $log_entry, FILE_APPEND); }
Add new site to a Mailchimp list
Add new site owner to a Mailchimp list after signing up.
add_action('after_signup_site', 'add_user_to_mailchimp', 10, 7); function add_user_to_mailchimp($domain, $path, $title, $user, $user_email, $key, $meta) { // Mailchimp API key and list ID $api_key = 'your_mailchimp_api_key'; $list_id = 'your_mailchimp_list_id'; // Add user to Mailchimp list // Replace with the actual Mailchimp API call }
Create a custom post for new site
Create a custom post type entry on the main site after a new site is created.
add_action('after_signup_site', 'create_custom_post_for_new_site', 10, 7); function create_custom_post_for_new_site($domain, $path, $title, $user, $user_email, $key, $meta) { // Switch to main site switch_to_blog(1); // Prepare custom post data $custom_post = array( 'post_title' => $title, 'post_content' => 'New site created by ' . $user . ' (' . $user_email . ') at ' . $domain . $path, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'your_custom_post_type' ); // Insert custom post wp_insert_post($custom_post); // Switch back to original site restore_current_blog(); }
Assign a custom role to the new site owner
Assign a custom role to the new site owner after signing up.
add_action('after_signup_site', 'assign_custom_role_to_new_user', 10, 7); function assign_custom_role_to_new_user($domain, $path, $title, $user, $user_email, $key, $meta) { // Get user by their email $new_user = get_user_by('email', $user_email); // Check if the user exists if ($new_user) { // Assign custom role to the user $new_user->set_role('your_custom_role'); } }