From 5346800a924fdbd291328ad2233fde48a89eed07 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 25 Sep 2020 22:31:27 +0000 Subject: [PATCH] Upgrade/Install: Introduce the `wp_installed_email` filter for filtering the contents of the email sent when WordPress is installed, without needing to override the `wp_new_blog_notification()` pluggable function. Props Dharm1025, nikolam, johnbillion Fixes #42133 git-svn-id: https://develop.svn.wordpress.org/trunk@49048 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/upgrade.php | 46 +++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php index e0170f2705..bb6ea18bc5 100644 --- a/src/wp-admin/includes/upgrade.php +++ b/src/wp-admin/includes/upgrade.php @@ -586,17 +586,18 @@ function wp_install_maybe_enable_pretty_permalinks() { if ( ! function_exists( 'wp_new_blog_notification' ) ) : /** - * Notifies the site admin that the setup is complete. + * Notifies the site admin that the installation of WordPress is complete. * - * Sends an email with wp_mail to the new administrator that the site setup is complete, + * Sends an email to the new administrator that the installation is complete * and provides them with a record of their login credentials. * * @since 2.1.0 * * @param string $blog_title Site title. - * @param string $blog_url Site url. - * @param int $user_id User ID. - * @param string $password User's Password. + * @param string $blog_url Site URL. + * @param int $user_id Administrator's user ID. + * @param string $password Administrator's password. Note that a placeholder message is + * usually passed instead of the actual password. */ function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) { $user = new WP_User( $user_id ); @@ -629,7 +630,40 @@ https://wordpress.org/ $login_url ); - wp_mail( $email, __( 'New WordPress Site' ), $message ); + $installed_email = array( + 'to' => $email, + 'subject' => __( 'New WordPress Site' ), + 'message' => $message, + 'headers' => '', + ); + + /** + * Filters the contents of the email sent to the site administrator when WordPress is installed. + * + * @since 5.6.0 + * + * @param array $installed_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_User $user The site administrator user object. + * @param string $blog_title The site title. + * @param string $blog_url The site URL. + * @param string $password The site administrator's password. Note that a placeholder message + * is usually passed instead of the user's actual password. + */ + $installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password ); + + wp_mail( + $installed_email['to'], + $installed_email['subject'], + $installed_email['message'], + $installed_email['headers'] + ); } endif;