0

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!

0

Have you tried

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

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.