You need to recurse into the shortcode content ($m[5]
as returned by get_shortcode_regex()
), the standard way being to use preg_replace_callback()
:
public function wrapShortcode( $content )
{
$content = preg_replace_callback( "https://wordpress.stackexchange.com/" . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $content );
remove_filter( 'the_content', array( $this, 'wrapShortcode' ), -9999999 );
// Stray spaces can create lost paragraph tags.
$content = preg_replace( '/(\/\w+>)\s+(<\/\w+)/', '$1$2', $content );
return apply_filters( 'bq_wrapShortcode', $content );
}
public function wrapShortcodeCallback( $m )
{
$id = md5( time() . '-' . $this->tag_index ++ );
if ( $m[5] !== '' ) {
// Recurse into content.
$m[5] = preg_replace_callback( "https://wordpress.stackexchange.com/" . get_shortcode_regex() . '/s', array( $this, 'wrapShortcodeCallback' ), $m[5] );
$scCont="[" . $m[1] . $m[2] . $m[3] . ']' . $m[5] . '[/' . $m[2] . ']' . $m[6];
} else {
$scCont="[" . $m[1] . $m[2] . $m[3] . $m[4] . ']' . $m[6];
}
return '<div class="shortcode" data-name="'.$m[2].'">'.$scCont.'</div>';
}