Skip to content
Merged
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
3 changes: 3 additions & 0 deletions backport-changelog/7.1/12053.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/12053

* https://github.com/WordPress/gutenberg/pull/78780
10 changes: 9 additions & 1 deletion lib/block-supports/block-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
function gutenberg_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 ) ) {
// Get viewport configuration from nested structure.
$viewport_config = $block_visibility['viewport'] ?? null;
Expand Down
4 changes: 2 additions & 2 deletions phpunit/block-supports/block-visibility-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function test_block_visibility_support_hides_block_when_visibility_false(
$this->assertSame( '', $result, 'Block content should be empty when blockVisibility is false and support is opted in.' );
}

public function test_block_visibility_support_shows_block_when_support_not_opted_in() {
public function test_block_visibility_support_hides_block_when_visibility_false_even_without_support() {
$this->register_visibility_block_with_support(
'test/visibility-block',
array( 'visibility' => false )
Expand All @@ -111,7 +111,7 @@ public function test_block_visibility_support_shows_block_when_support_not_opted

$result = gutenberg_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.' );
}

public function test_block_visibility_support_no_visibility_attribute() {
Expand Down
Loading