Skip to content

Commit 4fc9add

Browse files
committed
HTML & Shortcode: Honor hide-everywhere visibility after support was disabled
Blocks that previously supported visibility (HTML and Shortcode) silently reappear on the front end when content saved with `metadata.blockVisibility: false` is rendered after their support was disabled in #76138. Move the `block_has_support` check to run only for viewport-based visibility so the boolean `false` (hide everywhere) value continues to hide the block regardless of the block's current visibility support.
1 parent ba624a2 commit 4fc9add

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

lib/block-supports/block-visibility.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
function gutenberg_render_block_visibility_support( $block_content, $block ) {
1616
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
1717

18-
if ( ! $block_type || ! block_has_support( $block_type, 'visibility', true ) ) {
18+
if ( ! $block_type ) {
1919
return $block_content;
2020
}
2121

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

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

32+
if ( ! block_has_support( $block_type, 'visibility', true ) ) {
33+
return $block_content;
34+
}
35+
2836
if ( is_array( $block_visibility ) && ! empty( $block_visibility ) ) {
2937
// Get viewport configuration from nested structure.
3038
$viewport_config = $block_visibility['viewport'] ?? null;

phpunit/block-supports/block-visibility-test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function test_block_visibility_support_hides_block_when_visibility_false(
9393
$this->assertSame( '', $result, 'Block content should be empty when blockVisibility is false and support is opted in.' );
9494
}
9595

96-
public function test_block_visibility_support_shows_block_when_support_not_opted_in() {
96+
public function test_block_visibility_support_hides_block_when_visibility_false_even_without_support() {
9797
$this->register_visibility_block_with_support(
9898
'test/visibility-block',
9999
array( 'visibility' => false )
@@ -111,7 +111,7 @@ public function test_block_visibility_support_shows_block_when_support_not_opted
111111

112112
$result = gutenberg_render_block_visibility_support( $block_content, $block );
113113

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

117117
public function test_block_visibility_support_no_visibility_attribute() {

0 commit comments

Comments
 (0)