Skip to content

Commit 3d19b28

Browse files
committed
Administration: Introduce new_admin_email_subject filter.
This changeset introduces the `new_admin_email_subject` hook which allow developers to filter the subject of the email sent when a change of site admin email address is attempted. Props MadtownLems, johnbillion, alexanderkoledov, shooper, Marc_J, nikmeyer, xlthlx, devmuhib, nuhel, audrasjb. Fixes #59250. git-svn-id: https://develop.svn.wordpress.org/trunk@57283 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2c1a6ae commit 3d19b28

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/wp-admin/includes/misc.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,16 +1531,23 @@ function update_option_new_admin_email( $old_value, $value ) {
15311531
$site_title = parse_url( home_url(), PHP_URL_HOST );
15321532
}
15331533

1534-
wp_mail(
1535-
$value,
1536-
sprintf(
1537-
/* translators: New admin email address notification email subject. %s: Site title. */
1538-
__( '[%s] New Admin Email Address' ),
1539-
$site_title
1540-
),
1541-
$content
1534+
$subject = sprintf(
1535+
/* translators: New admin email address notification email subject. %s: Site title. */
1536+
__( '[%s] New Admin Email Address' ),
1537+
$site_title
15421538
);
15431539

1540+
/**
1541+
* Filters the subject of the email sent when a change of site admin email address is attempted.
1542+
*
1543+
* @since 6.5.0
1544+
*
1545+
* @param string $subject Subject of the email.
1546+
*/
1547+
$subject = apply_filters( 'new_admin_email_subject', $subject );
1548+
1549+
wp_mail( $value, $subject, $content );
1550+
15441551
if ( $switched_locale ) {
15451552
restore_previous_locale();
15461553
}

tests/phpunit/tests/admin/includesMisc.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,30 @@ public function test_shorten_url() {
2727
$this->assertSame( $v, url_shorten( $k ) );
2828
}
2929
}
30+
31+
/**
32+
* @ticket 59520
33+
*/
34+
public function test_new_admin_email_subject_filter() {
35+
// Default value
36+
$mailer = tests_retrieve_phpmailer_instance();
37+
update_option_new_admin_email( 'old@example.com', 'new@example.com' );
38+
$this->assertEquals( '[Test Blog] New Admin Email Address', $mailer->get_sent()->subject );
39+
40+
// Filtered value
41+
add_filter(
42+
'new_admin_email_subject',
43+
function () {
44+
return 'Filtered Admin Email Address';
45+
},
46+
10,
47+
1
48+
);
49+
50+
$mailer->mock_sent = array();
51+
52+
$mailer = tests_retrieve_phpmailer_instance();
53+
update_option_new_admin_email( 'old@example.com', 'new@example.com' );
54+
$this->assertEquals( 'Filtered Admin Email Address', $mailer->get_sent()->subject );
55+
}
3056
}

0 commit comments

Comments
 (0)