在WordPress的通知电子邮件中自定义主题字段?

时间:2010-09-02 作者:user391

我可以自定义和编辑多站点博客发送的“密码重置”通知邮件中的主题字段吗?我尝试了一些插件,如我的品牌登录和白色标签CMS等,但我无法在密码重置通知中编辑此插件。

有人帮我了解如何编辑它吗?

Update:

今天我尝试了另一个安装。但它没有做出任何改变。“发件人”邮件地址中的“wordpress”一词仍然存在。我已添加-

add_filter ( \'wp_mail_from_name\', \'my_filter_that_outputs_the_new_name\' );

Doug给出的代码。我错过什么了吗?你能帮我解决这个问题吗?

1 个回复
最合适的回答,由SO网友:Doug 整理而成

你可以change them using a filter. 要使用的筛选器挂钩包括:

对于first email 消息(确认他们确实要重置密码):

  • \'retrieve_password_title\'
  • \'retrieve_password_message\'

对于follow-up email 消息(发送新用户名和密码):

  • \'password_reset_title\'
  • \'password_reset_message\'


Update: 要创建和使用这些过滤器,请在functions.php 文件:

function my_retrieve_password_subject_filter($old_subject) {
    // $old_subject is the default subject line created by WordPress.
    // (You don\'t have to use it.)

    $blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);
    $subject = sprintf( __(\'[%s] Password Reset\'), $blogname );
    // This is how WordPress creates the subject line. It looks like this:
    // [Doug\'s blog] Password Reset
    // You can change this to fit your own needs.

    // You have to return your new subject line:
    return $subject;
}

function my_retrieve_password_message_filter($old_message, $key) {
    // $old_message is the default message already created by WordPress.
    // (You don\'t have to use it.)
    // $key is the password-like token that allows the user to get 
    // a new password

    $message = __(\'Someone has asked to reset the password for the following site and username.\') . "\\r\\n\\r\\n";
    $message .= network_site_url() . "\\r\\n\\r\\n";
    $message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
    $message .= __(\'To reset your password visit the following address, otherwise just ignore this email and nothing will happen.\') . "\\r\\n\\r\\n";
    $message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), \'login\') . "\\r\\n";

    // This is how WordPress creates the message. 
    // You can change this to meet your own needs.

    // You have to return your new message:
    return $message;
}

// To get these filters up and running:
add_filter ( \'retrieve_password_title\', \'my_retrieve_password_subject_filter\', 10, 1 );
add_filter ( \'retrieve_password_message\', \'my_retrieve_password_message_filter\', 10, 2 );
如果还想修改follow-up email. 使用WordPress code 作为创建主题行和消息的指南(查找变量$title$message).

结束

相关推荐