Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/wp-admin/includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1461,22 +1461,23 @@ function update_option_new_admin_email( $old_value, $value ) {

$switched_locale = switch_to_user_locale( get_current_user_id() );

/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
/* translators: Do not translate USERNAME, ADMIN_URL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$email_text = __(
'Howdy,

A site administrator (###USERNAME###) recently requested to have the
administration email address changed on this site:
###SITEURL###

The new administration email address will be:
###NEW_EMAIL###

To confirm this change, please click on the following link:
###ADMIN_URL###

You can safely ignore and delete this email if you do not want to
take this action.

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###'
Expand All @@ -1489,12 +1490,14 @@ function update_option_new_admin_email( $old_value, $value ) {
*
* - `###USERNAME###` The current user's username.
* - `###ADMIN_URL###` The link to click on to confirm the email change.
* - `###EMAIL###` The proposed new site admin email address.
* - `###NEW_EMAIL###` The proposed new site admin email address.
* - `###EMAIL###` Deprecated. Use `###NEW_EMAIL###` instead.
* - `###SITENAME###` The name of the site.
* - `###SITEURL###` The URL to the site.
*
* @since MU (3.0.0)
* @since 4.9.0 This filter is no longer Multisite specific.
* @since 7.2.0 The `###NEW_EMAIL###` placeholder was added. `###EMAIL###` is deprecated.
*
* @param string $email_text Text in the email.
* @param array $new_admin_email {
Expand All @@ -1506,10 +1509,13 @@ function update_option_new_admin_email( $old_value, $value ) {
*/
$content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email );

// The ###EMAIL### placeholder is deprecated in favor of ###NEW_EMAIL###.
$content = str_replace( '###EMAIL###', '###NEW_EMAIL###', $content );

$current_user = wp_get_current_user();
$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
$content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'options.php?adminhash=' . $hash ) ), $content );
$content = str_replace( '###EMAIL###', $value, $content );
$content = str_replace( '###NEW_EMAIL###', $value, $content );
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $content );
$content = str_replace( '###SITEURL###', home_url(), $content );

Expand Down
16 changes: 10 additions & 6 deletions src/wp-includes/ms-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2811,21 +2811,20 @@ function update_network_option_new_admin_email( $old_value, $value ) {

$switched_locale = switch_to_user_locale( get_current_user_id() );

/* translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
/* translators: Do not translate USERNAME, ADMIN_URL, NEW_EMAIL, SITENAME, SITEURL: those are placeholders. */
$email_text = __(
'Howdy ###USERNAME###,

You recently requested to have the network admin email address on
your network changed.
your network changed to:
###NEW_EMAIL###

If this is correct, please click on the following link to change it:
###ADMIN_URL###

You can safely ignore and delete this email if you do not want to
take this action.

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###'
Expand All @@ -2838,11 +2837,13 @@ function update_network_option_new_admin_email( $old_value, $value ) {
*
* - `###USERNAME###` The current user's username.
* - `###ADMIN_URL###` The link to click on to confirm the email change.
* - `###EMAIL###` The proposed new network admin email address.
* - `###NEW_EMAIL###` The proposed new network admin email address.
* - `###EMAIL###` Deprecated. Use `###NEW_EMAIL###` instead.
* - `###SITENAME###` The name of the network.
* - `###SITEURL###` The URL to the network.
*
* @since 4.9.0
* @since 7.2.0 The `###NEW_EMAIL###` placeholder was added. `###EMAIL###` is deprecated.
*
* @param string $email_text Text in the email.
* @param array $new_admin_email {
Expand All @@ -2854,10 +2855,13 @@ function update_network_option_new_admin_email( $old_value, $value ) {
*/
$content = apply_filters( 'new_network_admin_email_content', $email_text, $new_admin_email );

// The ###EMAIL### placeholder is deprecated in favor of ###NEW_EMAIL###.
$content = str_replace( '###EMAIL###', '###NEW_EMAIL###', $content );

$current_user = wp_get_current_user();
$content = str_replace( '###USERNAME###', $current_user->user_login, $content );
$content = str_replace( '###ADMIN_URL###', esc_url( network_admin_url( 'settings.php?network_admin_hash=' . $hash ) ), $content );
$content = str_replace( '###EMAIL###', $value, $content );
$content = str_replace( '###NEW_EMAIL###', $value, $content );
$content = str_replace( '###SITENAME###', wp_specialchars_decode( get_site_option( 'site_name' ), ENT_QUOTES ), $content );
$content = str_replace( '###SITEURL###', network_home_url(), $content );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,48 @@ function () {
update_option_new_admin_email( 'old@example.com', 'new@example.com' );
$this->assertSame( 'Filtered Admin Email Address', $mailer->get_sent()->subject );
}

/**
* @ticket 43706
*/
public function test_new_admin_email_content_includes_new_email_address() {
update_option_new_admin_email( 'old@example.com', 'new@example.com' );

$body = str_replace( "\r\n", "\n", tests_retrieve_phpmailer_instance()->get_sent()->body );

$this->assertStringContainsString( "The new administration email address will be:\nnew@example.com", $body );
$this->assertStringNotContainsString( '###', $body, 'The email should not contain unreplaced placeholders.' );
}

/**
* @ticket 43706
*
* @dataProvider data_new_admin_email_content_placeholders
*
* @param string $placeholder The placeholder used in the filtered email content.
*/
public function test_new_admin_email_content_filter_replaces_email_placeholders( $placeholder ) {
add_filter(
'new_admin_email_content',
static function () use ( $placeholder ) {
return "Confirm {$placeholder}";
}
);

update_option_new_admin_email( 'old@example.com', 'new@example.com' );

$this->assertSame( 'Confirm new@example.com', trim( tests_retrieve_phpmailer_instance()->get_sent()->body ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_new_admin_email_content_placeholders() {
return array(
'new placeholder' => array( '###NEW_EMAIL###' ),
'deprecated placeholder' => array( '###EMAIL###' ),
);
}
}
59 changes: 59 additions & 0 deletions tests/phpunit/tests/multisite/updateNetworkOptionNewAdminEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @group ms-required
* @group multisite
*
* @covers ::update_network_option_new_admin_email
*/
class Tests_Multisite_UpdateNetworkOptionNewAdminEmail extends WP_UnitTestCase {

public function set_up() {
parent::set_up();
reset_phpmailer_instance();
}

/**
* @ticket 43706
*/
public function test_new_network_admin_email_content_includes_new_email_address() {
update_network_option_new_admin_email( 'old@example.com', 'new@example.com' );

$body = str_replace( "\r\n", "\n", tests_retrieve_phpmailer_instance()->get_sent()->body );

$this->assertStringContainsString( "network changed to:\nnew@example.com", $body );
$this->assertStringNotContainsString( '###', $body, 'The email should not contain unreplaced placeholders.' );
}

/**
* @ticket 43706
*
* @dataProvider data_new_network_admin_email_content_placeholders
*
* @param string $placeholder The placeholder used in the filtered email content.
*/
public function test_new_network_admin_email_content_filter_replaces_email_placeholders( $placeholder ) {
add_filter(
'new_network_admin_email_content',
static function () use ( $placeholder ) {
return "Confirm {$placeholder}";
}
);

update_network_option_new_admin_email( 'old@example.com', 'new@example.com' );

$this->assertSame( 'Confirm new@example.com', trim( tests_retrieve_phpmailer_instance()->get_sent()->body ) );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_new_network_admin_email_content_placeholders() {
return array(
'new placeholder' => array( '###NEW_EMAIL###' ),
'deprecated placeholder' => array( '###EMAIL###' ),
);
}
}
Loading