1<?php
2/**
3 * Block visibility block support flag.
4 *
5 * @package WordPress
6 * @since 6.9.0
7 */
8
9/**
10 * Render nothing if the block is hidden.
11 *
12 * @since 6.9.0
13 * @access private
14 *
15 * @param string $block_content Rendered block content.
16 * @param array $block Block object.
17 * @return string Filtered block content.
18 */
19function wp_render_block_visibility_support( $block_content, $block ) {
20 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
21
22 if ( ! $block_type || ! block_has_support( $block_type, 'visibility', true ) ) {
23 return $block_content;
24 }
25
26 if ( isset( $block['attrs']['metadata']['blockVisibility'] ) && false === $block['attrs']['metadata']['blockVisibility'] ) {
27 return '';
28 }
29
30 return $block_content;
31}
32
33add_filter( 'render_block', 'wp_render_block_visibility_support', 10, 2 );
34