it-swarm.cn

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

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

有没有人帮我理解如何编辑它?

更新:

今天我尝试了另一个装置。但它没有做任何改变。来自邮件地址的Word'wordpress'仍在那里。我已添加 -

add_filter ( 'wp_mail_from_name', 'my_filter_that_outputs_the_new_name' );

道格给出的代码。我错过了什么?你能帮我解决一下吗?

4
user391

您可以 使用过滤器 更改它们。您要使用的过滤器挂钩是:

  1. 对于 第一封电子邮件 消息(确认他们确实要重置密码):[。_____。]
    • 'retrieve_password_title'
    • 'retrieve_password_message'
  2. 对于 后续电子邮件 message(发送新用户名和密码):[。_____。]
    • 'password_reset_title'
    • 'password_reset_message'

更新: 要创建和使用这些过滤器,请在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 );

如果您还想修改 后续电子邮件 ,您会做类似的事情。使用 WordPress代码 作为创建主题行和消息的指南(查找变量$title$message)。

6
Doug