diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 904c99b17b..5d6813c27b 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -1169,10 +1169,15 @@ function convert_chars($content, $deprecated = '') { * @return string Balanced text */ function balanceTags( $text, $force = false ) { - if ( $force || get_option('use_balanceTags') == 1 ) - return force_balance_tags( $text ); - else - return $text; + if ( $force || get_option('use_balanceTags') == 1 ) { + $balance_tags_delimiters = apply_filters( 'balance_tags_delimiters', array( '', '' ) ); + // Capture lets PREG_SPLIT_DELIM_CAPTURE return the delimiters + $delimiters_regex = '/(' . implode( '|', $balance_tags_delimiters ) . ')/'; + $parts = preg_split( $delimiters_regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); + return implode( '', array_map( 'force_balance_tags', $parts ) ); + } + + return $text; } /**