I18N: Switch locale to admin locale when sending admin notifications.
If sending an email to the site administrator's email address, look up if a user with the same email exists and switch to that user's locale. If not, falls back to the site locale as usual. Props benniledl, swissspidy, mukesh27. Fixes #61518. Built from https://develop.svn.wordpress.org/trunk@59128 git-svn-id: http://core.svn.wordpress.org/trunk@58524 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
48f12f72df
commit
b771c0ddc9
|
@ -1719,8 +1719,6 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
|||
$emails = array_flip( $emails );
|
||||
}
|
||||
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
|
||||
$comment_author_domain = '';
|
||||
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
|
||||
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
|
||||
|
@ -1733,6 +1731,46 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
|||
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
||||
$comment_content = wp_specialchars_decode( $comment->comment_content );
|
||||
|
||||
$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) );
|
||||
|
||||
if ( '' === $comment->comment_author ) {
|
||||
$from = "From: \"$blogname\" <$wp_email>";
|
||||
if ( '' !== $comment->comment_author_email ) {
|
||||
$reply_to = "Reply-To: $comment->comment_author_email";
|
||||
}
|
||||
} else {
|
||||
$from = "From: \"$comment->comment_author\" <$wp_email>";
|
||||
if ( '' !== $comment->comment_author_email ) {
|
||||
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
|
||||
}
|
||||
}
|
||||
|
||||
$message_headers = "$from\n"
|
||||
. 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
|
||||
|
||||
if ( isset( $reply_to ) ) {
|
||||
$message_headers .= $reply_to . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the comment notification email headers.
|
||||
*
|
||||
* @since 1.5.2
|
||||
*
|
||||
* @param string $message_headers Headers for the comment notification email.
|
||||
* @param string $comment_id Comment ID as a numeric string.
|
||||
*/
|
||||
$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$user = get_user_by( 'email', $email );
|
||||
|
||||
if ( $user ) {
|
||||
$switched_locale = switch_to_user_locale( $user->ID );
|
||||
} else {
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
}
|
||||
|
||||
switch ( $comment->comment_type ) {
|
||||
case 'trackback':
|
||||
/* translators: %s: Post title. */
|
||||
|
@ -1801,27 +1839,6 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
|||
$notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";
|
||||
}
|
||||
|
||||
$wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) );
|
||||
|
||||
if ( '' === $comment->comment_author ) {
|
||||
$from = "From: \"$blogname\" <$wp_email>";
|
||||
if ( '' !== $comment->comment_author_email ) {
|
||||
$reply_to = "Reply-To: $comment->comment_author_email";
|
||||
}
|
||||
} else {
|
||||
$from = "From: \"$comment->comment_author\" <$wp_email>";
|
||||
if ( '' !== $comment->comment_author_email ) {
|
||||
$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
|
||||
}
|
||||
}
|
||||
|
||||
$message_headers = "$from\n"
|
||||
. 'Content-Type: text/plain; charset="' . get_option( 'blog_charset' ) . "\"\n";
|
||||
|
||||
if ( isset( $reply_to ) ) {
|
||||
$message_headers .= $reply_to . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the comment notification email text.
|
||||
*
|
||||
|
@ -1842,23 +1859,12 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) :
|
|||
*/
|
||||
$subject = apply_filters( 'comment_notification_subject', $subject, $comment->comment_ID );
|
||||
|
||||
/**
|
||||
* Filters the comment notification email headers.
|
||||
*
|
||||
* @since 1.5.2
|
||||
*
|
||||
* @param string $message_headers Headers for the comment notification email.
|
||||
* @param string $comment_id Comment ID as a numeric string.
|
||||
*/
|
||||
$message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment->comment_ID );
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
|
||||
}
|
||||
|
||||
if ( $switched_locale ) {
|
||||
restore_previous_locale();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1908,8 +1914,6 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
|
|||
}
|
||||
}
|
||||
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
|
||||
$comment_author_domain = '';
|
||||
if ( WP_Http::is_ip_address( $comment->comment_author_IP ) ) {
|
||||
$comment_author_domain = gethostbyaddr( $comment->comment_author_IP );
|
||||
|
@ -1924,6 +1928,37 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
|
|||
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
||||
$comment_content = wp_specialchars_decode( $comment->comment_content );
|
||||
|
||||
$message_headers = '';
|
||||
|
||||
/**
|
||||
* Filters the list of recipients for comment moderation emails.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @param string[] $emails List of email addresses to notify for comment moderation.
|
||||
* @param int $comment_id Comment ID.
|
||||
*/
|
||||
$emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
|
||||
|
||||
/**
|
||||
* Filters the comment moderation email headers.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param string $message_headers Headers for the comment moderation email.
|
||||
* @param int $comment_id Comment ID.
|
||||
*/
|
||||
$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$user = get_user_by( 'email', $email );
|
||||
|
||||
if ( $user ) {
|
||||
$switched_locale = switch_to_user_locale( $user->ID );
|
||||
} else {
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
}
|
||||
|
||||
switch ( $comment->comment_type ) {
|
||||
case 'trackback':
|
||||
/* translators: %s: Post title. */
|
||||
|
@ -1995,17 +2030,6 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
|
|||
|
||||
/* translators: Comment moderation notification email subject. 1: Site title, 2: Post title. */
|
||||
$subject = sprintf( __( '[%1$s] Please moderate: "%2$s"' ), $blogname, $post->post_title );
|
||||
$message_headers = '';
|
||||
|
||||
/**
|
||||
* Filters the list of recipients for comment moderation emails.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @param string[] $emails List of email addresses to notify for comment moderation.
|
||||
* @param int $comment_id Comment ID.
|
||||
*/
|
||||
$emails = apply_filters( 'comment_moderation_recipients', $emails, $comment_id );
|
||||
|
||||
/**
|
||||
* Filters the comment moderation email text.
|
||||
|
@ -2027,23 +2051,12 @@ if ( ! function_exists( 'wp_notify_moderator' ) ) :
|
|||
*/
|
||||
$subject = apply_filters( 'comment_moderation_subject', $subject, $comment_id );
|
||||
|
||||
/**
|
||||
* Filters the comment moderation email headers.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @param string $message_headers Headers for the comment moderation email.
|
||||
* @param int $comment_id Comment ID.
|
||||
*/
|
||||
$message_headers = apply_filters( 'comment_moderation_headers', $message_headers, $comment_id );
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
wp_mail( $email, wp_specialchars_decode( $subject ), $notify_message, $message_headers );
|
||||
}
|
||||
|
||||
if ( $switched_locale ) {
|
||||
restore_previous_locale();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2063,6 +2076,15 @@ if ( ! function_exists( 'wp_password_change_notification' ) ) :
|
|||
* but check to see if it's the admin whose password we're changing, and skip this.
|
||||
*/
|
||||
if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
|
||||
|
||||
$admin_user = get_user_by( 'email', get_option( 'admin_email' ) );
|
||||
|
||||
if ( $admin_user ) {
|
||||
$switched_locale = switch_to_user_locale( $admin_user->ID );
|
||||
} else {
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
}
|
||||
|
||||
/* translators: %s: User name. */
|
||||
$message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n";
|
||||
/*
|
||||
|
@ -2103,6 +2125,10 @@ if ( ! function_exists( 'wp_password_change_notification' ) ) :
|
|||
$wp_password_change_notification_email['message'],
|
||||
$wp_password_change_notification_email['headers']
|
||||
);
|
||||
|
||||
if ( $switched_locale ) {
|
||||
restore_previous_locale();
|
||||
}
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
@ -2152,7 +2178,14 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) :
|
|||
$send_notification_to_admin = apply_filters( 'wp_send_new_user_notification_to_admin', true, $user );
|
||||
|
||||
if ( 'user' !== $notify && true === $send_notification_to_admin ) {
|
||||
|
||||
$admin_user = get_user_by( 'email', get_option( 'admin_email' ) );
|
||||
|
||||
if ( $admin_user ) {
|
||||
$switched_locale = switch_to_user_locale( $admin_user->ID );
|
||||
} else {
|
||||
$switched_locale = switch_to_locale( get_locale() );
|
||||
}
|
||||
|
||||
/* translators: %s: Site title. */
|
||||
$message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.7-alpha-59127';
|
||||
$wp_version = '6.7-alpha-59128';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue