Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/wp-includes/block-supports/block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@
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, 'visibility', true ) ) {
if ( ! $block_type ) {
return $block_content;
}

$block_visibility = $block['attrs']['metadata']['blockVisibility'] ?? null;

// Hide the block whenever the value is boolean false, regardless of the
// block's current visibility support. This prevents blocks that previously
// supported visibility from unintentionally appearing on the front end
// after their support was disabled.
if ( false === $block_visibility ) {
return '';
}

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

if ( is_array( $block_visibility ) && ! empty( $block_visibility ) ) {
$viewport_config = $block_visibility['viewport'] ?? null;

Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/tests/block-supports/block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ public function test_block_visibility_support_hides_block_when_visibility_false(
}

/**
* Tests that block visibility support renders block normally when visibility is false
* but blockVisibility support is not opted in.
* Tests that block visibility support hides the block when visibility is false
* even when blockVisibility support is not opted in.
*
* @ticket 64061
* @ticket 65389
*/
public function test_block_visibility_support_shows_block_when_support_not_opted_in(): void {
public function test_block_visibility_support_hides_block_when_visibility_false_even_without_support(): void {
$this->register_visibility_block_with_support(
'test/visibility-block',
array( 'visibility' => false )
Expand All @@ -103,7 +104,7 @@ public function test_block_visibility_support_shows_block_when_support_not_opted

$result = wp_render_block_visibility_support( $block_content, $block );

$this->assertSame( $block_content, $result, 'Block content should remain unchanged when blockVisibility support is not opted in.' );
$this->assertSame( '', $result, 'Block content should be empty when blockVisibility is false, even without visibility support.' );
}

/**
Expand Down
Loading