wpmu_new_site_admin_notification

函式
wpmu_new_site_admin_notification ( $site_id, $user_id )
引數
  • (int) $site_id Site ID of the new site.
    Required:
  • (int) $user_id User ID of the administrator of the new site.
    Required:
返回值
  • (bool) Whether the email notification was sent.
定義位置
相關方法
wp_new_user_notificationwpmu_welcome_notificationwp_site_admin_email_change_notificationwp_new_blog_notificationwp_send_new_user_notifications
引入
5.6.0
棄用
-

wpmu_new_site_admin_notification – 這個函式在新站點建立時向網路管理員傳送電子郵件通知。

通知Multisite網路管理員,一個新的網站已經建立。

過濾器 {@see ‘send_new_site_email’}可以禁用或繞過。

過濾{@see ‘new_site_email’}來過濾內容。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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_locale( get_user_locale( $network_admin ) );
} 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$s
Name: %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.
* @type string $headers Headers.
* }
* @param WP_Site $site Site object of the new site.
* @param WP_User $user User object of the administrator of the new site.
*/
$new_site_email = apply_filters( 'new_site_email', $new_site_email, $site, $user );
wp_mail(
$new_site_email['to'],
wp_specialchars_decode( $new_site_email['subject'] ),
$new_site_email['message'],
$new_site_email['headers']
);
if ( $switched_locale ) {
restore_previous_locale();
}
return true;
}
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_locale( get_user_locale( $network_admin ) ); } 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$s Name: %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. * @type string $headers Headers. * } * @param WP_Site $site Site object of the new site. * @param WP_User $user User object of the administrator of the new site. */ $new_site_email = apply_filters( 'new_site_email', $new_site_email, $site, $user ); wp_mail( $new_site_email['to'], wp_specialchars_decode( $new_site_email['subject'] ), $new_site_email['message'], $new_site_email['headers'] ); if ( $switched_locale ) { restore_previous_locale(); } return true; }
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_locale( get_user_locale( $network_admin ) );
	} 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$s
Name: %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.
	 *     @type string $headers Headers.
	 * }
	 * @param WP_Site $site         Site object of the new site.
	 * @param WP_User $user         User object of the administrator of the new site.
	 */
	$new_site_email = apply_filters( 'new_site_email', $new_site_email, $site, $user );

	wp_mail(
		$new_site_email['to'],
		wp_specialchars_decode( $new_site_email['subject'] ),
		$new_site_email['message'],
		$new_site_email['headers']
	);

	if ( $switched_locale ) {
		restore_previous_locale();
	}

	return true;
}

常見問題

FAQs
檢視更多 >