filter_block_content

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

WordPress Version: 6.3

/**
 * Filters and sanitizes block content to remove non-allowable HTML
 * from parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      Optional. An array of allowed HTML elements and attributes,
 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
 *                                          for the list of accepted context names. Default 'post'.
 * @param string[]       $allowed_protocols Optional. Array of allowed URL protocols.
 *                                          Defaults to the result of wp_allowed_protocols().
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (str_contains($text, '<!--') && str_contains($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 2.1

/**
 * Filters and sanitizes block content to remove non-allowable HTML
 * from parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      Optional. An array of allowed HTML elements and attributes,
 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
 *                                          for the list of accepted context names. Default 'post'.
 * @param string[]       $allowed_protocols Optional. Array of allowed URL protocols.
 *                                          Defaults to the result of wp_allowed_protocols().
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 6.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML
 * from parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      Optional. An array of allowed HTML elements and attributes,
 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
 *                                          for the list of accepted context names. Default 'post'.
 * @param string[]       $allowed_protocols Optional. Array of allowed URL protocols.
 *                                          Defaults to the result of wp_allowed_protocols().
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 1.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML
 * from parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      Optional. An array of allowed HTML elements and attributes,
 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
 *                                          for the list of accepted context names. Default 'post'.
 * @param string[]       $allowed_protocols Optional. Array of allowed URL protocols.
 *                                          Defaults to the result of wp_allowed_protocols().
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 6.1

/**
 * Filters and sanitizes block content to remove non-allowable HTML
 * from parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      Optional. An array of allowed HTML elements and attributes,
 *                                          or a context name such as 'post'. See wp_kses_allowed_html()
 *                                          for the list of accepted context names. Default 'post'.
 * @param string[]       $allowed_protocols Optional. Array of allowed URL protocols.
 *                                          Defaults to the result of wp_allowed_protocols().
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 9.6

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 5.9

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 8.7

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 5.8

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 7.9

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 7.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .10

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 6.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .11

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 5.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .12

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 4.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .13

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 3.2

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .15

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 2.5

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .18

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 1.4

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .16

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: 0.8

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .19

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    if (false !== strpos($text, '<!--') && false !== strpos($text, '--->')) {
        $text = preg_replace_callback('%<!--(.*?)--->%', '_filter_block_content_callback', $text);
    }
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}

WordPress Version: .10

/**
 * Filters and sanitizes block content to remove non-allowable HTML from
 * parsed block attribute values.
 *
 * @since 5.3.1
 *
 * @param string         $text              Text that may contain block content.
 * @param array[]|string $allowed_html      An array of allowed HTML elements
 *                                          and attributes, or a context name
 *                                          such as 'post'.
 * @param string[]       $allowed_protocols Array of allowed URL protocols.
 * @return string The filtered and sanitized content result.
 */
function filter_block_content($text, $allowed_html = 'post', $allowed_protocols = array())
{
    $result = '';
    $blocks = parse_blocks($text);
    foreach ($blocks as $block) {
        $block = filter_block_kses($block, $allowed_html, $allowed_protocols);
        $result .= serialize_block($block);
    }
    return $result;
}