wppaste
WordPress

wpmu_new_site_admin_notification( int $site_id, int $user_id ): bool

Since
5.6.0
Source
wp-includes/ms-functions.php:1715
Notifies the Multisite network administrator that a new site was created.

Description

Filter 'send_new_site_email' to disable or bypass.

Filter 'new_site_email' to filter the contents.

Compatibility

WordPress
since 5.6.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$site_idint
Site ID of the new site.
$user_idint
User ID of the administrator of the new site.

Return value

bool
Whether the email notification was sent.

Performance profile

How much work a call to wpmu_new_site_admin_notification() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Sends mail via wp_mail().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
16–113

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 121.

Plugin surface
2 hooks

Third-party callbacks on 'send_new_site_email', 'new_site_email' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionnetwork optionget_site_option()called directly
  • hookthird-party callbacksapply_filters()called directly
  • querycontent queryget_user_by()called directly
  • mailsends mailwp_mail()called directly

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 6 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wpmu_new_site_admin_notification() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always16–18get_site(), get_userdata(), get_site_option()
!apply_filters()25get_site(), get_userdata(), get_site_option(), apply_filters()
apply_filters()110get_site(), get_userdata(), get_site_option(), apply_filters(), get_user_by(), get_locale(), switch_to_locale(), __(), get_network(), sprintf(), __(), get_site_url(), get_blog_option(), sprintf(), _x(), sprintf(), apply_filters(), wp_specialchars_decode(), wp_mail()
apply_filters()111get_site(), get_userdata(), get_site_option(), apply_filters(), get_user_by(), switch_to_user_locale(), __(), get_network(), sprintf(), __(), get_site_url(), get_blog_option(), sprintf(), _x(), sprintf(), apply_filters(), wp_specialchars_decode(), wp_mail()
apply_filters()112get_site(), get_userdata(), get_site_option(), apply_filters(), get_user_by(), get_locale(), switch_to_locale(), __(), get_network(), sprintf(), __(), get_site_url(), get_blog_option(), sprintf(), _x(), sprintf(), apply_filters(), wp_specialchars_decode(), wp_mail(), restore_previous_locale()
apply_filters()113get_site(), get_userdata(), get_site_option(), apply_filters(), get_user_by(), switch_to_user_locale(), __(), get_network(), sprintf(), __(), get_site_url(), get_blog_option(), sprintf(), _x(), sprintf(), apply_filters(), wp_specialchars_decode(), wp_mail(), restore_previous_locale()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 121 instructions, 16–113 executed per call, 6 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 2

2 hooks fire while wpmu_new_site_admin_notification() runs, in this order:

  1. apply_filters( send_new_site_email )filterline 1735 (+20 into the body)

    Filters whether to send an email to the Multisite network administrator when a new site is created.

  2. apply_filters( new_site_email )filterline 1800 (+85 into the body)

    Filters the content of the email sent to the Multisite network administrator when a new site is created.

Uses · 16

  • get_site()Retrieves site data given a site ID or site object.
  • get_userdata()Retrieves user info by user ID.
  • get_site_option()Retrieve an option value for the current network based on name of option.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • get_user_by()Retrieves user info by a given field.
  • switch_to_user_locale()Switches the translations according to the given user's locale.
  • switch_to_locale()Switches the translations according to the given locale.
  • get_locale()Retrieves the current locale.
  • __()Retrieves the translation of $text.
  • get_network()Retrieves network data given a network ID or network object.
  • get_site_url()Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
  • get_blog_option()Retrieves option value for a given blog id based on name of option.
Show all 16

Source code

function wpmu_new_site_admin_notification( $site_id, $user_id ) {	$site  = get_site( $site_id );	$user  = get_userdata( $user_id );	$email = get_site_option( 'admin_email' ); 	if ( ! $site || ! $user || ! $email ) {		return false;	} 	/**	 * Filters whether to send an email to the Multisite network administrator when a new site is created.	 *	 * Return false to disable sending the email.	 *	 * @since 5.6.0	 *	 * @param bool    $send Whether to send the email.	 * @param WP_Site $site Site object of the new site.	 * @param WP_User $user User object of the administrator of the new site.	 */	if ( ! apply_filters( 'send_new_site_email', true, $site, $user ) ) {		return false;	} 	$switched_locale = false;	$network_admin   = get_user_by( 'email', $email ); 	if ( $network_admin ) {		// If the network admin email address corresponds to a user, switch to their locale.		$switched_locale = switch_to_user_locale( $network_admin->ID );	} else {		// Otherwise switch to the locale of the current site.		$switched_locale = switch_to_locale( get_locale() );	} 	$subject = sprintf(		/* translators: New site notification email subject. %s: Network title. */		__( '[%s] New Site Created' ),		get_network()->site_name	); 	$message = sprintf(		/* translators: New site notification email. 1: User login, 2: Site URL, 3: Site title. */		__(			'New site created by %1$s Address: %2$sName: %3$s'		),		$user->user_login,		get_site_url( $site->id ),		get_blog_option( $site->id, 'blogname' )	); 	$header = sprintf(		'From: "%1$s" <%2$s>',		_x( 'Site Admin', 'email "From" field' ),		$email	); 	$new_site_email = array(		'to'      => $email,		'subject' => $subject,		'message' => $message,		'headers' => $header,	); 	/**	 * Filters the content of the email sent to the Multisite network administrator when a new site is created.	 *	 * Content should be formatted for transmission via wp_mail().	 *	 * @since 5.6.0	 *	 * @param array $new_site_email {	 *     Used to build wp_mail().	 *	 *     @type string $to      The email address of the recipient.	 *     @type string $subject The subject of the email.	 *     @type string $message The content of the email.

Changelog

Introduced in 5.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/ms-functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.