Hi i want to edit the template of the password change email when admin change the password of a user i want to send the password to user in email i try to edit the code but no use. Here is my Code
.
if ( ! empty( $send_password_change_email ) ) {
/* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
$pass_change_text = __( 'Hi ###USERNAME###,
This notice confirms that your password was changed on ###SITENAME###.
your new password is this :###PASSWORD###
If you did not change your password, please contact the Site Administrator at
###ADMIN_EMAIL###
This email has been sent to ###EMAIL###
Regards,
All at ###SITENAME###
###SITEURL###' );
$pass_change_email = array(
'to' => $user['user_email'],
/* translators: User password change notification email subject. 1: Site name */
'subject' => __( '[%s] Notice of Password Change' ),
'message' => $pass_change_text,
'headers' => '',
);
/**
* Filters the contents of the email sent when the user's password is changed.
*
* @since 4.3.0
*
* @param array $pass_change_email {
* Used to build wp_mail().
* @type string $to The intended recipients. Add emails in a comma separated string.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* The following strings have a special meaning and will get replaced dynamically:
* - ###USERNAME### The current user's username.
* - ###ADMIN_EMAIL### The admin email in case this was unexpected.
* - ###EMAIL### The user's email address.
* - ###SITENAME### The name of the site.
* - ###SITEURL### The URL to the site.
* @type string $headers Headers. Add headers in a newline (\r\n) separated string.
* }
* @param array $user The original user array.
* @param array $userdata The updated user array.
*
*/
$pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata );
$pass_change_email['message']=str_replace( '###PASSWORD###',$user['user_password'], $pass_change_email['message'] );
$pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] );
$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] );
$pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] );
$pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] );
$pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] );
wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] );
}
Anyone know how to get the password which admin change for the user?
If the email send gets triggered at the same time as the admin hit the "Update profile" button, then you can use the post data: $_POST['pass1']
(or $_POST['pass1-text']
). You can change the line to as below
$pass_change_email['message']=str_replace( '###PASSWORD###',$_POST['pass1'], $pass_change_email['message'] );
If these emails get generated asynchronously, then you may not be able to get the value as passwords are normally hashed. Not recommended but a way around this would be to save the password as plan text in a custom field, send the email then delete that custom field.