Skip to content

Commit bdc79c0

Browse files
committed
Users: Introduce filters for the contents of email notifications for new user registrations and password resets.
Introduces: * `wp_password_change_notification_subject` * `wp_password_change_notification_message` * `wp_password_change_notification_headers` * `wp_new_user_notification_admin_subject` * `wp_new_user_notification_admin_message` * `wp_new_user_notification_admin_headers` * `wp_new_user_notification_subject` * `wp_new_user_notification_message` * `wp_new_user_notification_headers` Props pbearne, dipesh.kakadiya Fixes #38068 git-svn-id: https://develop.svn.wordpress.org/trunk@41153 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 817e0c1 commit bdc79c0

1 file changed

Lines changed: 109 additions & 3 deletions

File tree

src/wp-includes/pluggable.php

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,42 @@ function wp_password_change_notification( $user ) {
17471747
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
17481748
// we want to reverse this for the plain text arena of emails.
17491749
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1750+
17501751
/* translators: %s: site title */
1751-
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Password Changed' ), $blogname ), $message );
1752+
$subject = sprintf( __( '[%s] Password Changed' ), $blogname );
1753+
1754+
/**
1755+
* Filters the subject of the password change notification email sent to the site admin.
1756+
*
1757+
* @since 4.9.0
1758+
*
1759+
* @param string $subject Email subject.
1760+
* @param WP_User $user User object for user whose password was changed.
1761+
* @param string $blogname The site title.
1762+
*/
1763+
$subject = apply_filters( 'wp_password_change_notification_subject', $subject, $user, $blogname );
1764+
1765+
/**
1766+
* Filters the message body of the password change notification email sent to the site admin.
1767+
*
1768+
* @since 4.9.0
1769+
*
1770+
* @param string $message Email message.
1771+
* @param WP_User $user User object for user whose password was changed.
1772+
*/
1773+
$message = apply_filters( 'wp_password_change_notification_message', $message, $user );
1774+
1775+
/**
1776+
* Filters the email headers of the password change notification admin email sent to the site admin.
1777+
*
1778+
* @since 4.9.0
1779+
*
1780+
* @param string $headers Email headers.
1781+
* @param WP_User $user User object for user whose password was changed.
1782+
*/
1783+
$headers = apply_filters( 'wp_password_change_notification_headers', '', $user );
1784+
1785+
wp_mail( get_option( 'admin_email' ), wp_specialchars_decode( $subject ), $message, $headers );
17521786
}
17531787
}
17541788
endif;
@@ -1786,11 +1820,48 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' )
17861820

17871821
if ( 'user' !== $notify ) {
17881822
$switched_locale = switch_to_locale( get_locale() );
1823+
1824+
/* translators: %s: site title */
1825+
$subject = sprintf( __( '[%s] New User Registration' ), $blogname );
1826+
/* translators: %s: site title */
17891827
$message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
1828+
/* translators: %s: user login */
17901829
$message .= sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
1830+
/* translators: %s: user email address */
17911831
$message .= sprintf( __( 'Email: %s' ), $user->user_email ) . "\r\n";
17921832

1793-
@wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message );
1833+
/**
1834+
* Filters the subject of the new user notification email sent to the site admin.
1835+
*
1836+
* @since 4.9.0
1837+
*
1838+
* @param string $subject Email subject.
1839+
* @param WP_User $user User object for newly registered user.
1840+
* @param string $blogname The site title.
1841+
*/
1842+
$subject = apply_filters( 'wp_new_user_notification_admin_subject', $subject, $user, $blogname );
1843+
1844+
/**
1845+
* Filters the message body of the new user notification email sent to the site admin.
1846+
*
1847+
* @since 4.9.0
1848+
*
1849+
* @param string $message Email message.
1850+
* @param WP_User $user User object for newly registered user.
1851+
*/
1852+
$message = apply_filters( 'wp_new_user_notification_admin_message', $message, $user );
1853+
1854+
/**
1855+
* Filters the email headers of the new user notification email sent to the site admin.
1856+
*
1857+
* @since 4.9.0
1858+
*
1859+
* @param string $headers Email headers.
1860+
* @param WP_User $user User object for newly registered user.
1861+
*/
1862+
$headers = apply_filters( 'wp_new_user_notification_admin_headers', '', $user );
1863+
1864+
@wp_mail( get_option( 'admin_email' ), wp_specialchars_decode( $subject ), $message, $headers );
17941865

17951866
if ( $switched_locale ) {
17961867
restore_previous_locale();
@@ -1818,13 +1889,48 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' )
18181889

18191890
$switched_locale = switch_to_locale( get_user_locale( $user ) );
18201891

1892+
/* translators: %s: site title */
1893+
$subject = sprintf( __( '[%s] Your username and password info' ), $blogname );
1894+
/* translators: %s: user login */
18211895
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
18221896
$message .= __('To set your password, visit the following address:') . "\r\n\r\n";
18231897
$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";
18241898

18251899
$message .= wp_login_url() . "\r\n";
18261900

1827-
wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message);
1901+
/**
1902+
* Filters the subject of the new user email sent to the new user.
1903+
*
1904+
* @since 4.9.0
1905+
*
1906+
* @param string $subject Email subject.
1907+
* @param WP_User $user User object for newly registered user.
1908+
* @param string $blogname The site title.
1909+
*/
1910+
$subject = apply_filters( 'wp_new_user_notification_subject', $subject, $user, $blogname );
1911+
1912+
/**
1913+
* Filters the message body of the new user email sent to the new user.
1914+
*
1915+
* @since 4.9.0
1916+
*
1917+
* @param string $message Email message.
1918+
* @param WP_User $user User object for newly registered user.
1919+
* @param string $key User activation key.
1920+
*/
1921+
$message = apply_filters( 'wp_new_user_notification_message', $message, $user, $key );
1922+
1923+
/**
1924+
* Filters the email headers of the new user email sent to the new user.
1925+
*
1926+
* @since 4.9.0
1927+
*
1928+
* @param string $headers Email headers.
1929+
* @param WP_User $user User object for newly registered user.
1930+
*/
1931+
$headers = apply_filters( 'wp_new_user_notification_headers', '', $user );
1932+
1933+
wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $headers );
18281934

18291935
if ( $switched_locale ) {
18301936
restore_previous_locale();

0 commit comments

Comments
 (0)