I am currently developing a multi-site plug-in for WordPress. I need to run a function when a new site is created.
2 Answers
I guess you are looking for an action/filter.
wpmu_new_blog
this action is fired in wpmu_create_blog
function (wp-includes/ms-functions.php)
do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
-
-
-
-
1Actions and filters are the fundamental knowledge of wordpress plugin development. Hooking an action is the most basic stuff. If you have no idea what they idea, I would suggest googling about add_action first.– JesseFeb 25, 2013 at 6:12
Since WP 5.1.0, wpmu_new_blog
has been deprecated in favour of wp_insert_site
:
/**
* Fires once a site has been inserted into the database.
*
* @since 5.1.0
*
* @param WP_Site $new_site New site object.
*/
do_action( 'wp_insert_site', $new_site );
Use it like this in your plugin or theme:
add_action('wp_insert_site', function($site) {
// do something
});
A good place to look for available hooks is wp-includes/ms-default-filters.php