_wp_add_block_level_presets_class

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

WordPress Version: 6.4

/**
 * Update the block content with block level presets class name.
 *
 * @internal
 *
 * @since 6.2.0
 * @access private
 *
 * @param  string $block_content Rendered block content.
 * @param  array  $block         Block object.
 * @return string                Filtered block content.
 */
function _wp_add_block_level_presets_class($block_content, $block)
{
    if (!$block_content) {
        return $block_content;
    }
    // return early if the block doesn't have support for settings.
    $block_type = WP_Block_Type_Registry::get_instance()->get_registered($block['blockName']);
    if (!block_has_support($block_type, '__experimentalSettings', false)) {
        return $block_content;
    }
    // return early if no settings are found on the block attributes.
    $block_settings = isset($block['attrs']['settings']) ? $block['attrs']['settings'] : null;
    if (empty($block_settings)) {
        return $block_content;
    }
    // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
    // Add the class name to the first element, presuming it's the wrapper, if it exists.
    $tags = new WP_HTML_Tag_Processor($block_content);
    if ($tags->next_tag()) {
        $tags->add_class(_wp_get_presets_class_name($block));
    }
    return $tags->get_updated_html();
}

WordPress Version: 6.2

/**
 * Update the block content with block level presets class name.
 *
 * @internal
 *
 * @since 6.2.0
 * @access private
 *
 * @param  string $block_content Rendered block content.
 * @param  array  $block         Block object.
 * @return string                Filtered block content.
 */
function _wp_add_block_level_presets_class($block_content, $block)
{
    if (!$block_content) {
        return $block_content;
    }
    // return early if the block doesn't have support for settings.
    $block_type = WP_Block_Type_Registry::get_instance()->get_registered($block['blockName']);
    if (!block_has_support($block_type, array('__experimentalSettings'), false)) {
        return $block_content;
    }
    // return early if no settings are found on the block attributes.
    $block_settings = _wp_array_get($block, array('attrs', 'settings'), null);
    if (empty($block_settings)) {
        return $block_content;
    }
    // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.
    // Add the class name to the first element, presuming it's the wrapper, if it exists.
    $tags = new WP_HTML_Tag_Processor($block_content);
    if ($tags->next_tag()) {
        $tags->add_class(_wp_get_presets_class_name($block));
    }
    return $tags->get_updated_html();
}