do_action( ‘wp_insert_site’, WP_Site $new_site )

Fires once a site has been inserted into the database.

Parameters

$new_siteWP_Site
New site object.

Source

do_action( 'wp_insert_site', $new_site );

Changelog

VersionDescription
5.1.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The hook wpmu_new_blog gives you a deprecated notice and tells you to use wp_insert_site. Don’t do that, wp_insert_site fires too early. Instead, use wp_initialize_site with a priority higher than 100, as in:

    add_action( 'wp_initialize_site', 'wpdocs_action_wp_initialize_site', 900 );
    
    /**
     * Fires when a site's initialization routine should be executed.
     *
     * @param WP_Site $new_site New site object.
     */
    function wpdocs_action_wp_initialize_site( WP_Site $new_site ) : void {
    	switch_to_blog( $new_site->blog_id );
    
    	// do the job
    
    	restore_current_blog();
    }

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