admin管理员组

文章数量:1026396

I have a plug-in that spawns a process to carry out a print function. The item to print, in this case a Woocommerce product, is passed via the URL (via product_id). Before carrying out printing, all registered shortcodes must be stripped from the product description. If I call strip_shortcodes() it does nothing. I guess the array of registered shortcodes is out of scope? Can anyone suggest an efficient way to enable the process to use strip_shortcodes()?

I have a plug-in that spawns a process to carry out a print function. The item to print, in this case a Woocommerce product, is passed via the URL (via product_id). Before carrying out printing, all registered shortcodes must be stripped from the product description. If I call strip_shortcodes() it does nothing. I guess the array of registered shortcodes is out of scope? Can anyone suggest an efficient way to enable the process to use strip_shortcodes()?

Share Improve this question edited Mar 29, 2019 at 2:35 Eje 1654 bronze badges asked Mar 28, 2019 at 18:30 togethernettogethernet 212 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You can manually add shortcodes to the array of tags to be stripped in strip_shortcodes() via filter. If the global $shortcode_tags either doesn't exist or doesn't contain what it should when your process is running then you'll need to use that filter to add them back in.

$tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content );

I needed to bring $shortcode_tags into scope before calling strip_shortcodes()

I did this by adding the declaration

global $shortcode_tags;

I have a plug-in that spawns a process to carry out a print function. The item to print, in this case a Woocommerce product, is passed via the URL (via product_id). Before carrying out printing, all registered shortcodes must be stripped from the product description. If I call strip_shortcodes() it does nothing. I guess the array of registered shortcodes is out of scope? Can anyone suggest an efficient way to enable the process to use strip_shortcodes()?

I have a plug-in that spawns a process to carry out a print function. The item to print, in this case a Woocommerce product, is passed via the URL (via product_id). Before carrying out printing, all registered shortcodes must be stripped from the product description. If I call strip_shortcodes() it does nothing. I guess the array of registered shortcodes is out of scope? Can anyone suggest an efficient way to enable the process to use strip_shortcodes()?

Share Improve this question edited Mar 29, 2019 at 2:35 Eje 1654 bronze badges asked Mar 28, 2019 at 18:30 togethernettogethernet 212 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You can manually add shortcodes to the array of tags to be stripped in strip_shortcodes() via filter. If the global $shortcode_tags either doesn't exist or doesn't contain what it should when your process is running then you'll need to use that filter to add them back in.

$tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content );

I needed to bring $shortcode_tags into scope before calling strip_shortcodes()

I did this by adding the declaration

global $shortcode_tags;

本文标签: shortcodeHow to use stripshortcodes() from a spawned process