更改密码更改电子邮件主题的通知?

时间:2019-02-27 作者:joq3

在更改密码时,我无法更改发送的电子邮件的主题。我已通过以下操作成功更改消息:

// 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\' );
}
但是我如何更改默认为的主题[Sitename] Notice of Password Change

非常感谢。

2 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

这个$change_mail 正在筛选的变量具有subject 值,您可以使用与修改消息相同的方式修改该值:

// 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;
}
(我取消了您对的呼叫remove_filter() 因为它什么都做不了。之后什么都没有return 将运行。)

SO网友:filipecsweb

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 );

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register