admin管理员组文章数量:1431413
I have an email triggered like below. I want a user to be able to customize the content.
I want to provide the user to be able to put esc_html($user->display_name)
somehow may some thing with a text like {{user_name}}
$body = sprintf('Hey %s, your awesome post has been published!
See <%s>',
esc_html($user->display_name),
get_permalink($post)
);
// Now send to the post author.
wp_mail($user->user_email, 'Your post has been published!', $body);
Is it possible to do?
I have an email triggered like below. I want a user to be able to customize the content.
I want to provide the user to be able to put esc_html($user->display_name)
somehow may some thing with a text like {{user_name}}
$body = sprintf('Hey %s, your awesome post has been published!
See <%s>',
esc_html($user->display_name),
get_permalink($post)
);
// Now send to the post author.
wp_mail($user->user_email, 'Your post has been published!', $body);
Is it possible to do?
Share Improve this question edited Dec 17, 2018 at 21:30 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Dec 17, 2018 at 21:06 user145078user1450781 Answer
Reset to default 0I would just use str_replace()
to handle a "pseudo" shortcode. Something like this:
$body = sprintf('Hey {{username}}, your awesome post has been published!
See <%s>', get_permalink($post) );
// Add replacement values to the array as necessary.
$old = array( '{{username}}' );
$new = array( esc_html($user->display_name) );
$body = str_replace( $old, $new, $body );
// Now send to the post author.
wp_mail($user->user_email, 'Your post has been published!', $body);
I just worked from what you started with. I'm assuming you're doing something ahead of this to get the $user
object. Also, I made the replacement values for str_replace()
as arrays, so you can add to that as necessary (instead of running it multiple times).
本文标签: plugin developmentAllow user to add the php code in wpmail()
版权声明:本文标题:plugin development - Allow user to add the php code in wp_mail() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572675a2664141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论