: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$user = get_userdata( $user_id );
$options_site_url = esc_url( network_admin_url( 'settings.php' ) );
/* translators: New user notification email. 1: User login, 2: User IP address, 3: URL to Network Settings screen. */
Disable these notifications: %3$s'
wp_unslash( $_SERVER['REMOTE_ADDR'] ),
* Filters the message body of the new user activation email sent
* to the network administrator.
* @param string $msg Email body.
* @param WP_User $user WP_User instance of the new user.
$msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user );
/* translators: New user notification email subject. %s: User login. */
wp_mail( $email, sprintf( __( 'New User Registration: %s' ), $user->user_login ), $msg );
* Checks whether a site name is already taken.
* The name is the site's subdomain or the site's subdirectory
* path depending on the network settings.
* Used during the new site registration process to ensure
* that each site name is unique.
* @param string $domain The domain to be checked.
* @param string $path The path to be checked.
* @param int $network_id Optional. Network ID. Only relevant on multi-network installations.
* @return int|null The site ID if the site name exists, null otherwise.
function domain_exists( $domain, $path, $network_id = 1 ) {
$path = trailingslashit( $path );
'network_id' => $network_id,
'update_site_meta_cache' => false,
$result = get_sites( $args );
$result = array_shift( $result );
* Filters whether a site name is taken.
* The name is the site's subdomain or the site's subdirectory
* path depending on the network settings.
* @param int|null $result The site ID if the site name exists, null otherwise.
* @param string $domain Domain to be checked.
* @param string $path Path to be checked.
* @param int $network_id Network ID. Only relevant on multi-network installations.
return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
* Notifies the site administrator that their site activation was successful.
* Filter {@see 'wpmu_welcome_notification'} to disable or bypass.
* Filter {@see 'update_welcome_email'} and {@see 'update_welcome_subject'} to
* modify the content and subject line of the notification email.
* @param int $blog_id Site ID.
* @param int $user_id User ID.
* @param string $password User password, or "N/A" if the user account is not new.
* @param string $title Site title.
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id.
* @return bool Whether the email notification was sent.
function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
$current_network = get_network();
* Filters whether to bypass the welcome email sent to the site administrator after site activation.
* Returning false disables the welcome email.
* @param int|false $blog_id Site ID, or false to prevent the email from sending.
* @param int $user_id User ID of the site administrator.
* @param string $password User password, or "N/A" if the user account is not new.
* @param string $title Site title.
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id.
if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) {
$user = get_userdata( $user_id );
$switched_locale = switch_to_user_locale( $user_id );
$welcome_email = get_site_option( 'welcome_email' );
if ( false == $welcome_email ) {
/* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
Your new SITE_NAME site has been successfully set up at:
You can log in to the administrator account with the following information:
Log in here: BLOG_URLwp-login.php
We hope you enjoy your new site. Thanks!
$url = get_blogaddress_by_id( $blog_id );
$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
$welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
$welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email );
$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
* Filters the content of the welcome email sent to the site administrator after site activation.
* Content should be formatted for transmission via wp_mail().
* @param string $welcome_email Message body of the email.
* @param int $blog_id Site ID.
* @param int $user_id User ID of the site administrator.
* @param string $password User password, or "N/A" if the user account is not new.
* @param string $title Site title.
* @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id.
$welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta );
$admin_email = get_site_option( 'admin_email' );
if ( '' === $admin_email ) {
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
$message = $welcome_email;
if ( empty( $current_network->site_name ) ) {
$current_network->site_name = 'WordPress';
/* translators: New site notification email subject. 1: Network title, 2: New site title. */
$subject = __( 'New %1$s Site: %2$s' );
* Filters the subject of the welcome email sent to the site administrator after site activation.
* @param string $subject Subject of the email.
$subject = apply_filters( 'update_welcome_subject', sprintf( $subject, $current_network->site_name, wp_unslash( $title ) ) );
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
if ( $switched_locale ) {
restore_previous_locale();
* Notifies the Multisite network administrator that a new site was created.
* Filter {@see 'send_new_site_email'} to disable or bypass.
* Filter {@see 'new_site_email'} to filter the contents.
* @param int $site_id Site ID of the new site.
* @param int $user_id User ID of the administrator of the new site.
* @return bool Whether the email notification was sent.
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 ) {
* Filters whether to send an email to the Multisite network administrator when a new site is created.
* Return false to disable sending the email.
* @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 ) ) {
$switched_locale = false;
$network_admin = get_user_by( 'email', $email );
// If the network admin email address corresponds to a user, switch to their locale.
$switched_locale = switch_to_user_locale( $network_admin->ID );
// Otherwise switch to the locale of the current site.
$switched_locale = switch_to_locale( get_locale() );
/* translators: New site notification email subject. %s: Network title. */
__( '[%s] New Site Created' ),
/* translators: New site notification email. 1: User login, 2: Site URL, 3: Site title. */
'New site created by %1$s
get_site_url( $site->id ),
get_blog_option( $site->id, 'blogname' )
_x( 'Site Admin', 'email "From" field' ),
* 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().
* @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_specialchars_decode( $new_site_email['subject'] ),
$new_site_email['message'],
$new_site_email['headers']
if ( $switched_locale ) {
restore_previous_locale();
* Notifies a user that their account activation has been successful.
* Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass.
* Filter {@see 'update_welcome_user_email'} and {@see 'update_welcome_user_subject'} to
* modify the content and subject line of the notification email.
* @param int $user_id User ID.
* @param string $password User password.
* @param array $meta Optional. Signup meta data. Default empty array.
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
$current_network = get_network();
* Filters whether to bypass the welcome email after user activation.
* Returning false disables the welcome email.
* @param int $user_id User ID.
* @param string $password User password.
* @param array $meta Signup meta data. Default empty array.
if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) {
$welcome_email = get_site_option( 'welcome_user_email' );
$user = get_userdata( $user_id );
$switched_locale = switch_to_user_locale( $user_id );
* Filters the content of the welcome email after user activation.
* Content should be formatted for transmission via wp_mail().
* @param string $welcome_email The message body of the account activation success email.
* @param int $user_id User ID.
* @param string $password User password.
* @param array $meta Signup meta data. Default empty array.
$welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta );
$welcome_email = str_replace( 'SITE_NAME', $current_network->site_name, $welcome_email );
$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
$welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
$welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
$admin_email = get_site_option( 'admin_email' );
if ( '' === $admin_email ) {
$admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST );
$from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress';
$message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
$message = $welcome_email;
if ( empty( $current_network->site_name ) ) {
$current_network->site_name = 'WordPress';
/* translators: New user notification email subject. 1: Network title, 2: New user login. */
$subject = __( 'New %1$s User: %2$s' );
* Filters the subject of the welcome email after user activation.
* @param string $subject Subject of the email.
$subject = apply_filters( 'update_welcome_user_subject', sprintf( $subject, $current_network->site_name, $user->user_login ) );
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
if ( $switched_locale ) {
restore_previous_locale();
* Gets the current network.
* Returns an object containing the 'id', 'domain', 'path', and 'site_name'
* properties of the network being viewed.
* @see wpmu_current_site()
* @global WP_Network $current_site The current network.
* @return WP_Network The current network.
function get_current_site() {
* Gets a user's most recent post.
* Walks through each of a user's blogs to find the post with
* the most recent post_date_gmt.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $user_id User ID.
* @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts.
function get_most_recent_post_of_user( $user_id ) {
$user_blogs = get_blogs_of_user( (int) $user_id );
$most_recent_post = array();
* Walk through each blog and get the most recent post
foreach ( (array) $user_blogs as $blog ) {
$prefix = $wpdb->get_blog_prefix( $blog->userblog_id );
$recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A );
// Make sure we found a post.
if ( isset( $recent_post['ID'] ) ) {
$post_gmt_ts = strtotime( $recent_post['post_date_gmt'] );
* If this is the first post checked
* or if this post is newer than the current recent post,
* make it the new most recent post.
if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {
$most_recent_post = array(
'blog_id' => $blog->userblog_id,
'post_id' => $recent_post['ID'],
'post_date_gmt' => $recent_post['post_date_gmt'],
'post_gmt_ts' => $post_gmt_ts,
return $most_recent_post;
* Checks an array of MIME types against a list of allowed types.
* WordPress ships with a set of allowed upload filetypes,
* which is defined in wp-includes/functions.php in
* get_allowed_mime_types(). This function is used to filter
* that list against the filetypes allowed provided by Multisite
* Super Admins at wp-admin/network/settings.php.
function check_upload_mimes( $mimes ) {
$site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
foreach ( $site_exts as $ext ) {
foreach ( $mimes as $ext_pattern => $mime ) {
if ( '' !== $ext && str_contains( $ext_pattern, $ext ) ) {