shortcode_unautop

The timeline below displays how wordpress function shortcode_unautop has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

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);
}

WordPress Version: 6.1

/**
 * 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,WordPress.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);
}

WordPress Version: 5.6

/**
 * 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 $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = implode('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,WordPress.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/';
    // phpcs:enable
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 5.3

/**
 * 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 $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,WordPress.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/';
    // phpcs:enable
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 5.1

/**
 * 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 $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/';
    // phpcs:enable
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 4.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 $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/';
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 4.3

/**
 * 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 $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/s';
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 4.1

/**
 * Don't auto-p wrap shortcodes that stand alone
 *
 * Ensures that shortcodes are not wrapped in `<p>...</p>`.
 *
 * @since 2.9.0
 *
 * @param string $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/s';
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 4.0

/**
 * Don't auto-p wrap shortcodes that stand alone
 *
 * Ensures that shortcodes are not wrapped in <<p>>...<</p>>.
 *
 * @since 2.9.0
 *
 * @param string $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $spaces = wp_spaces_regexp();
    $pattern = '/' . '<p>' . '(?:' . $spaces . ')*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '(?:' . $spaces . ')*+' . '<\/p>' . '/s';
    return preg_replace($pattern, '$1', $pee);
}

WordPress Version: 3.7

/**
 * Don't auto-p wrap shortcodes that stand alone
 *
 * Ensures that shortcodes are not wrapped in <<p>>...<</p>>.
 *
 * @since 2.9.0
 *
 * @param string $pee The content.
 * @return string The filtered content.
 */
function shortcode_unautop($pee)
{
    global $shortcode_tags;
    if (empty($shortcode_tags) || !is_array($shortcode_tags)) {
        return $pee;
    }
    $tagregexp = join('|', array_map('preg_quote', array_keys($shortcode_tags)));
    $pattern = '/' . '<p>' . '\s*+' . '(' . '\[' . "({$tagregexp})" . '(?![\w-])' . '[^\]\/]*' . '(?:' . '\/(?!\])' . '[^\]\/]*' . ')*?' . '(?:' . '\/\]' . '|' . '\]' . '(?:' . '[^\[]*+' . '(?:' . '\[(?!\/\2\])' . '[^\[]*+' . ')*+' . '\[\/\2\]' . ')?' . ')' . ')' . '\s*+' . '<\/p>' . '/s';
    return preg_replace($pattern, '$1', $pee);
}