$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - Change Notice of Password change email subject?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - Change Notice of Password change email subject?

matteradmin8PV0评论

I'm having issues to change the subject of the email sent out when password is changed. I have managed to change the message by doing this:

// Change Email to HTML function
function set_email_html_content_type() {
    return 'text/html';
}

// Replace the default password change email
add_filter('password_change_email', 'change_password_mail_message', 10, 3);
function change_password_mail_message( $change_mail, $user, $userdata ) {
    // Call Change Email to HTML function
    add_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
    $message = "<p>Test HTML email</p>";

    $change_mail[ 'message' ] = $message;
        return $change_mail;

    // Remove filter HTML content type
    remove_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
}

But how do I change the subject which is default as [Sitename] Notice of Password Change

Thank you!

I'm having issues to change the subject of the email sent out when password is changed. I have managed to change the message by doing this:

// Change Email to HTML function
function set_email_html_content_type() {
    return 'text/html';
}

// Replace the default password change email
add_filter('password_change_email', 'change_password_mail_message', 10, 3);
function change_password_mail_message( $change_mail, $user, $userdata ) {
    // Call Change Email to HTML function
    add_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
    $message = "<p>Test HTML email</p>";

    $change_mail[ 'message' ] = $message;
        return $change_mail;

    // Remove filter HTML content type
    remove_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
}

But how do I change the subject which is default as [Sitename] Notice of Password Change

Thank you!

Share Improve this question asked Feb 27, 2019 at 14:28 joq3joq3 3813 silver badges21 bronze badges 1
  • You don't need to make use of wp_mail_content_type filter as all you want to do and more can be achieved modifying the var $change_mail. Just check my answer. – filipecsweb Commented Feb 27, 2019 at 15:00
Add a comment  | 

2 Answers 2

Reset to default 2

The $change_mail variable that you're filtering has a subject value that you can modify the same way you modified the message:

// Replace the default password change email
add_filter('password_change_email', 'change_password_mail_message', 10, 3);
function change_password_mail_message( $change_mail, $user, $userdata ) {
    // Call Change Email to HTML function
    add_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
    $message = "<p>Test HTML email</p>";

    $change_mail[ 'message' ] = $message;
    $change_mail[ 'subject' ] = 'My new email subject';

    return $change_mail;
}

(I removed your call to remove_filter() because it wouldn't do anything. Nothing after return will run.)

Try this:

/**
 * Hooked into `password_change_email` filter hook.
 *
 * @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.
 *
 * @return  array   $pass_change_email
 */
function change_password_mail_message( $pass_change_email, $user, $userdata ) {
    $subject   = "Your new subject";
    $message   = "<p>Test HTML email</p>";
    $headers[] = 'Content-Type: text/html';

    $pass_change_email['subject'] = $subject;
    $pass_change_email['message'] = $message;
    $pass_change_email['headers'] = $headers;

    return $pass_change_email;
}

/**
 * Filters the contents of the email sent when the user's password is changed.
 *
 * @see change_password_mail_message()
 */
add_filter( 'password_change_email', 'change_password_mail_message', 10, 3 );
Post a comment

comment list (0)

  1. No comments so far