WordPress Version: 6.4
/**
* Don't auto-p wrap shortcodes that stand alone.
*
* Ensures that shortcodes are not wrapped in `<p>...</p>`.
*
* @since 2.9.0
*
* @global array $shortcode_tags
*
* @param string $text The content.
* @return string The filtered content.
*/
function shortcode_unautop($text)
{
global $shortcode_tags;
if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
return $text;
}
$tagregexp = implode('|', array_map('preg_quote', array_keys($shortcode_tags)));
$spaces = wp_spaces_regexp();
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,Universal.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
$pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/';
// phpcs:enable
return preg_replace($pattern, '$1', $text);
}