【问题标题】:How can I change the header of WordPress 'retrieve_password' email?如何更改 WordPress 'retrieve_password' 电子邮件的标题?
【发布时间】:2014-07-16 03:02:09
【问题描述】:

我注意到 WordPress 为我们提供了一些过滤器来自定义密码重置请求电子邮件,例如 wp_mail_fromretrieve_password_titleretrieve_password_message,最后两个在 wp-login.phpretrieve_password 函数中执行,如下所示:

$title = apply_filters( 'retrieve_password_title', $title );
$message = apply_filters( 'retrieve_password_message', $message, $key );

if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
    wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );

return true;

这很酷,但我也意识到 wp_mail 函数不使用任何标题,这让我相信一切都应该用过滤器覆盖。

是否有过滤器来覆盖标题?具体Content-Type?哪里是注册它们的最佳地点?

【问题讨论】:

  • 我找到了过滤器'wp_mail_content_type,但我不确定哪里是注册它的最佳位置。在消息过滤器中?

标签: php wordpress email-headers


【解决方案1】:

要仅在wp-login.php 页面运行过滤器wp_mail_content_type,我们可以使用one of its action hooks。未经测试:

add_action( 'login_form_retrievepassword', function()
{
    add_filter( 'wp_mail_content_type', function( $old_content_type )
    {
        $new_content_type = 'text/plain';
        return $new_content_type;
    });
});

【讨论】:

  • 我不想更改所有内容类型,因为我有不同的邮件发件人和不同的模板(纯文本和 html)。
  • (题外话),请查看拒绝原因:stackoverflow.com/review/suggested-edits/4913168
  • Stack or not Stack,如果一个框架有一个代码约定/标准,它应该像任何“好的行为实践”一样被遵循。例如不改变别人的代码。在这种情况下,我们应该遵循 WP 标准还是仅仅因为“我们不会改变其他人的风格”而保留您的“不良风格”代码。可以将我的代码内联并缩小吗?
  • 让我们来点哲学吧 ;) 我几乎遵循所有 WP 标准我的花括号位置。
猜你喜欢
  • 2018-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-28
  • 2012-03-20
  • 2020-06-14
  • 1970-01-01
相关资源
最近更新 更多