I'd like to wrap existing shortcodes in post content inside a new shortcode that I'm adding to my plugin. The existing content looks like this:
Some text - could be <span>HTML</span> or other shortcodes
....
[component id=12]
[component id=13]
[component id=14]
....
Some text - could be <span>HTML</span> or another shortcodes
I'm trying to write a script that will go post by post, extract out any shortcodes of the form [component id=X]
and wrap them in another shortcode as follows:
Some text - could be <span>HTML</span> or other shortcodes
....
[components]
[component id=12]
[component id=13]
[component id=14]
[/components]
....
Some text - could be <span>HTML</span> or another shortcodes
I'm having trouble writing up the regex for this. I'm hoping to use preg_replace_callback()
to achieve this, but not sure if this is the appropriate function or not.