admin管理员组文章数量:1122832
I can current filter the content type of the wp_mail function:
add_filter( 'wp_mail_content_type', function( $content_type ) {
return 'text/html';
});
And I can filter the message content
add_filter( 'wp_mail', function( $args ) {
$args['message'] = 'Filtered text here';
return $args;
});
But how can I only do the latter conditionally?
I only want to filter the message when the content type
== text/plain
.
I'm guessing there is a super-simple solution to this, but I haven't worked it out yet.
I can current filter the content type of the wp_mail function:
add_filter( 'wp_mail_content_type', function( $content_type ) {
return 'text/html';
});
And I can filter the message content
add_filter( 'wp_mail', function( $args ) {
$args['message'] = 'Filtered text here';
return $args;
});
But how can I only do the latter conditionally?
I only want to filter the message when the content type
== text/plain
.
I'm guessing there is a super-simple solution to this, but I haven't worked it out yet.
Share Improve this question asked Mar 13, 2018 at 16:32 Kevin RobinsonKevin Robinson 617 bronze badges1 Answer
Reset to default 0Note that the wp_mail
filter runs before the wp_mail_content_type
filter.
If you're using the PHP Mailer then you can try (untested):
add_action( 'phpmailer_init', function( $phpmailer ) {
if( 'text/plain' === $phpmailer->ContentType ) {
$phpmailer->Body = 'Filtered text here'; // <-- Message override
}
});
本文标签: hooksFilter wpmail based on content type
版权声明:本文标题:hooks - Filter wp_mail based on content type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286671a1927718.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论