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
This commit is contained in:
John Blackbourn 2020-09-25 22:31:27 +00:00
parent 5d1a29deaa
commit 5346800a92

View File

@ -586,17 +586,18 @@ function wp_install_maybe_enable_pretty_permalinks() {
if ( ! function_exists( 'wp_new_blog_notification' ) ) : 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. * and provides them with a record of their login credentials.
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param string $blog_title Site title. * @param string $blog_title Site title.
* @param string $blog_url Site url. * @param string $blog_url Site URL.
* @param int $user_id User ID. * @param int $user_id Administrator's user ID.
* @param string $password User's Password. * @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 ) { function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
$user = new WP_User( $user_id ); $user = new WP_User( $user_id );
@ -629,7 +630,40 @@ https://wordpress.org/
$login_url $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; endif;