$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Do_shortcode before send email content|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Do_shortcode before send email content

matteradmin9PV0评论

I'm having a little problem figuring out how to execute shortcodes stored in a mail content option of a plugin.

The thing is, I have a field in my options page named '_message' that works with WYSIWYG Editor, and I want to save shortcodes there and then execute them before send the email.

There is some way of detect shortcodes in strings?. Ex:

$message = 'blablabla [sale_products] blablaba'; do_shortcode($message);

If you have another suggestion of how can this be done, that would be great!

I'm having a little problem figuring out how to execute shortcodes stored in a mail content option of a plugin.

The thing is, I have a field in my options page named '_message' that works with WYSIWYG Editor, and I want to save shortcodes there and then execute them before send the email.

There is some way of detect shortcodes in strings?. Ex:

$message = 'blablabla [sale_products] blablaba'; do_shortcode($message);

If you have another suggestion of how can this be done, that would be great!

Share Improve this question edited Nov 3, 2018 at 17:52 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Nov 3, 2018 at 17:31 Renan A. DiazRenan A. Diaz 11 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

Have you tried

$message = apply_filters('the_content', $your_data);

I think this filter could handle the shortcode. (not tested)

While this is not very obvious, do_shortcode is usually applied as a filter on a function that generates a certain text. It is, for instance, defined as a standard filter on the_content like this:

add_filter ('the_content','do_shortcode');

So, the trick is to define it as a filter on get_option in your plugin. If you look at the source code of get_option you'll see that on the last line there is a filter applied, the name of which depends on the name of the option. Suppose the name of the option that stores the message is my_message You would have something like this:

add_filter ('option_my_message','do_shortcode');

That should mean that if you have $message = get_option('my_message') in your plugin, you would get it with shortcodes evaluated.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far