The newblog_notify_siteadmin() WordPress PHP function notifies the network admin that a new site has been activated.
Usage
To use the newblog_notify_siteadmin() function, call it with the required $blog_id
parameter:
newblog_notify_siteadmin( $blog_id );
Parameters
$blog_id
(WP_Site|int) (Required): The new site’s object or ID.$deprecated
(string) (Optional): Not used. Default: ”
More information
See WordPress Developer Resources: newblog_notify_siteadmin
Examples
Notify admin of a new site
In this example, we notify the network admin of a new site with ID 5.
// Notify the network admin of a new site with ID 5 newblog_notify_siteadmin( 5 );
Notify admin after creating a new site
In this example, we create a new site and notify the network admin of its activation.
// Create a new site $new_site = wp_insert_site(array( 'domain' => 'example.com', 'path' => '/new-site/', )); // Notify the network admin of the new site newblog_notify_siteadmin( $new_site->id );
Using a custom filter for the notification email
In this example, we customize the content of the notification email using the newblog_notify_siteadmin
filter.
// Customize the content of the notification email function custom_newblog_email_content( $email_content, $blog_id ) { $new_content = "A new site has been activated: " . get_site_url( $blog_id ); return $new_content; } add_filter( 'newblog_notify_siteadmin', 'custom_newblog_email_content', 10, 2 ); // Notify the network admin of a new site with ID 6 newblog_notify_siteadmin( 6 );
Customizing the notification email subject
In this example, we customize the subject of the notification email using the update_new_site_admin_email_subject
filter.
// Customize the subject of the notification email function custom_newblog_email_subject( $subject, $blog_id ) { $new_subject = "New Site Alert: " . get_blog_details( $blog_id )->blogname; return $new_subject; } add_filter( 'update_new_site_admin_email_subject', 'custom_newblog_email_subject', 10, 2 ); // Notify the network admin of a new site with ID 7 newblog_notify_siteadmin( 7 );
Notify admin when a new site is added
In this example, we hook the wp_insert_site
action to notify the network admin whenever a new site is added.
// Hook the wp_insert_site action to notify the network admin function notify_admin_on_new_site( $site_id ) { newblog_notify_siteadmin( $site_id ); } add_action( 'wp_insert_site', 'notify_admin_on_new_site' ); // Create a new site $new_site = wp_insert_site(array( 'domain' => 'example.com', 'path' => '/another-new-site/', ));