do_action( 'wp_insert_site', WP_Site $new_site )

Fires once a site has been inserted into the database.


Parameters

$new_site WP_Site
New site object.

Top ↑

Source

File: wp-includes/ms-site.php. View all references

do_action( 'wp_insert_site', $new_site );


Top ↑

Changelog

Changelog
Version Description
5.1.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Per Søderlind

    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.