do_action( ‘add_user_to_blog’, int $user_id, string $role, int $blog_id )

Fires immediately after a user is added to a site.

Parameters

$user_idint
User ID.
$rolestring
User role.
$blog_idint
Blog ID.

Source

do_action( 'add_user_to_blog', $user_id, $role, $blog_id );

Changelog

VersionDescription
MU (3.0.0)Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Here is a use case when you may need to add users to common sites (forums, support trackers etc ) on the network apart from the main site and their own site(s).

    /**
     * Add a user to network sites.
     *
     * @param int $user_id User ID.
     */
    function wpdocs_add_user_to_network_sites( $user_id ) {
    
    	// Put common sites here
    	$blogs = array( 1, 2, 3, 5,8 ); 
      
    	foreach ( $blogs as $blog ) {
    		add_user_to_blog( $user_id, $blog, 'subscriber' );
    	}
    }
    add_action( 'user_register', 'wpdocs_add_user_to_network_sites' );

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