Skip to content

Commit

Permalink
Administration: Introduce new_admin_email_subject filter.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
audrasjb committed Jan 14, 2024
1 parent 2c1a6ae commit 3d19b28
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/wp-admin/includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1531,16 +1531,23 @@ function update_option_new_admin_email( $old_value, $value ) {
$site_title = parse_url( home_url(), PHP_URL_HOST );
}

wp_mail(
$value,
sprintf(
/* translators: New admin email address notification email subject. %s: Site title. */
__( '[%s] New Admin Email Address' ),
$site_title
),
$content
$subject = sprintf(
/* translators: New admin email address notification email subject. %s: Site title. */
__( '[%s] New Admin Email Address' ),
$site_title
);

/**
* Filters the subject of the email sent when a change of site admin email address is attempted.
*
* @since 6.5.0
*
* @param string $subject Subject of the email.
*/
$subject = apply_filters( 'new_admin_email_subject', $subject );

wp_mail( $value, $subject, $content );

if ( $switched_locale ) {
restore_previous_locale();
}
Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/tests/admin/includesMisc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,30 @@ public function test_shorten_url() {
$this->assertSame( $v, url_shorten( $k ) );
}
}

/**
* @ticket 59520
*/
public function test_new_admin_email_subject_filter() {
// Default value
$mailer = tests_retrieve_phpmailer_instance();
update_option_new_admin_email( '[email protected]', '[email protected]' );
$this->assertEquals( '[Test Blog] New Admin Email Address', $mailer->get_sent()->subject );

// Filtered value
add_filter(
'new_admin_email_subject',
function () {
return 'Filtered Admin Email Address';
},
10,
1
);

$mailer->mock_sent = array();

$mailer = tests_retrieve_phpmailer_instance();
update_option_new_admin_email( '[email protected]', '[email protected]' );
$this->assertEquals( 'Filtered Admin Email Address', $mailer->get_sent()->subject );
}
}

0 comments on commit 3d19b28

Please sign in to comment.