CoreFiles by mySites.guru
block-visibility.php33 lines, 859 bytes, from wordpress-6.9-beta3.zip
Raw History Compare with 6.9-beta2
md5
c74df3fa78fae68e8551d2ae21d54f22
sha1
619fd6205ea45fb9c3ff05f8097e64fa5402995a
sha256
6e8ef10bce0099e8d4dbc60cf0bb863f9c7eafcba945feba0f82d604e339b10a
<?php
/**
 * Block visibility block support flag.
 *
 * @package WordPress
 * @since 6.9.0
 */

/**
 * Render nothing if the block is hidden.
 *
 * @since 6.9.0
 * @access private
 *
 * @param string $block_content Rendered block content.
 * @param array  $block         Block object.
 * @return string Filtered block content.
 */
function wp_render_block_visibility_support( $block_content, $block ) {
	$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );

	if ( ! $block_type || ! block_has_support( $block_type, 'blockVisibility', true ) ) {
		return $block_content;
	}

	if ( isset( $block['attrs']['metadata']['blockVisibility'] ) && false === $block['attrs']['metadata']['blockVisibility'] ) {
		return '';
	}

	return $block_content;
}

add_filter( 'render_block', 'wp_render_block_visibility_support', 10, 2 );

The same content is in 6 releases, WordPress 6.9-beta1 to 6.9-RC2. See them all, or every version of this file.