diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/ms-functions.php --- a/wp/wp-includes/ms-functions.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/ms-functions.php Wed Sep 21 18:19:35 2022 +0200 @@ -543,7 +543,7 @@ // Has someone already signed up for this username? $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); - if ( null != $signup ) { + if ( $signup instanceof stdClass ) { $registered_at = mysql2date( 'U', $signup->registered ); $now = time(); $diff = $now - $registered_at; @@ -556,7 +556,7 @@ } $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); - if ( null != $signup ) { + if ( $signup instanceof stdClass ) { $diff = time() - mysql2date( 'U', $signup->registered ); // If registered more than two days ago, cancel registration and let this signup go through. if ( $diff > 2 * DAY_IN_SECONDS ) { @@ -708,7 +708,7 @@ $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); $path = $base; } else { - $mydomain = "$domain"; + $mydomain = $domain; $path = $base . $blogname . '/'; } if ( domain_exists( $mydomain, $path, $current_network->id ) ) { @@ -724,7 +724,7 @@ // Has someone already signed up for this domain? // TODO: Check email too? $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); - if ( ! empty( $signup ) ) { + if ( $signup instanceof stdClass ) { $diff = time() - mysql2date( 'U', $signup->registered ); // If registered more than two days ago, cancel registration and let this signup go through. if ( $diff > 2 * DAY_IN_SECONDS ) { @@ -928,13 +928,13 @@ * * @since MU (3.0.0) * - * @param string|bool $domain Site domain. - * @param string $path Site path. - * @param string $title Site title. - * @param string $user_login User login name. - * @param string $user_email User email address. - * @param string $key Activation key created in wpmu_signup_blog(). - * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. + * @param string|false $domain Site domain, or false to prevent the email from sending. + * @param string $path Site path. + * @param string $title Site title. + * @param string $user_login User login name. + * @param string $user_email User email address. + * @param string $key Activation key created in wpmu_signup_blog(). + * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. */ if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user_login, $user_email, $key, $meta ) ) { return false; @@ -1575,7 +1575,7 @@ } /** - * Notify a user that their blog activation has been successful. + * Notifies the site administrator that their site activation was successful. * * Filter {@see 'wpmu_welcome_notification'} to disable or bypass. * @@ -1584,28 +1584,28 @@ * * @since MU (3.0.0) * - * @param int $blog_id Blog ID. + * @param int $blog_id Site ID. * @param int $user_id User ID. - * @param string $password User password. + * @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 + * @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 after site activation. + * Filters whether to bypass the welcome email sent to the site administrator after site activation. * * Returning false disables the welcome email. * * @since MU (3.0.0) * - * @param int|bool $blog_id Blog ID. - * @param int $user_id User ID. - * @param string $password User password. - * @param string $title Site title. - * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. + * @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 ) ) { return false; @@ -1645,16 +1645,16 @@ $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email ); /** - * Filters the content of the welcome email after site activation. + * Filters the content of the welcome email sent to the site administrator after site activation. * * Content should be formatted for transmission via wp_mail(). * * @since MU (3.0.0) * * @param string $welcome_email Message body of the email. - * @param int $blog_id Blog ID. - * @param int $user_id User ID. - * @param string $password User password. + * @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. */ @@ -1678,7 +1678,7 @@ $subject = __( 'New %1$s Site: %2$s' ); /** - * Filters the subject of the welcome email after site activation. + * Filters the subject of the welcome email sent to the site administrator after site activation. * * @since MU (3.0.0) * @@ -1696,6 +1696,120 @@ } /** + * 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. + * + * @since 5.6.0 + * + * @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 ) { + 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; +} + +/** * Notify a user that their account activation has been successful. * * Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass. @@ -1970,7 +2084,7 @@ return $term_id; } - $term_id = intval( $term_id ); + $term_id = (int) $term_id; $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); @@ -2161,7 +2275,7 @@ wp_die( sprintf( /* translators: %s: Home URL. */ - __( 'An error occurred adding you to this site. Back to the homepage.' ), + __( 'An error occurred adding you to this site. Go to the homepage.' ), home_url() ) ); @@ -2184,7 +2298,7 @@ * * @since MU (3.0.0) * - * @param array $details { + * @param array|false $details { * User details. Must at least contain values for the keys listed below. * * @type int $user_id The ID of the user being added to the current blog. @@ -2515,6 +2629,7 @@ * @param int|false $space_used The amount of used space, in megabytes. Default false. */ $space_used = apply_filters( 'pre_get_space_used', false ); + if ( false === $space_used ) { $upload_dir = wp_upload_dir(); $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES; @@ -2835,18 +2950,18 @@ * @since 4.9.0 * * @param array $email_change_email { - * Used to build wp_mail(). + * Used to build wp_mail(). * - * @type string $to The intended recipient. - * @type string $subject The subject of the email. - * @type string $message The content of the email. - * The following strings have a special meaning and will get replaced dynamically: - * - ###OLD_EMAIL### The old network admin email address. - * - ###NEW_EMAIL### The new network admin email address. - * - ###SITENAME### The name of the network. - * - ###SITEURL### The URL to the site. - * @type string $headers Headers. - * } + * @type string $to The intended recipient. + * @type string $subject The subject of the email. + * @type string $message The content of the email. + * The following strings have a special meaning and will get replaced dynamically: + * - ###OLD_EMAIL### The old network admin email address. + * - ###NEW_EMAIL### The new network admin email address. + * - ###SITENAME### The name of the network. + * - ###SITEURL### The URL to the site. + * @type string $headers Headers. + * } * @param string $old_email The old network admin email address. * @param string $new_email The new network admin email address. * @param int $network_id ID of the network.