plugin development - Allow user to add the php code in wp_mail()

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

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 user145078user145078
Add a comment  | 

1 Answer 1

Reset to default 0

I 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).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745572676a4633775.html

相关推荐

  • plugin development - Allow user to add the php code in wp_mail()

    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

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信