Skip to content

Block Visibility: Keep hide-everywhere working after a block opts out of visibility support#78780

Merged
t-hamano merged 2 commits into
trunkfrom
fix/shortcode-html-block-visibility-false
Jun 2, 2026
Merged

Block Visibility: Keep hide-everywhere working after a block opts out of visibility support#78780
t-hamano merged 2 commits into
trunkfrom
fix/shortcode-html-block-visibility-false

Conversation

@t-hamano
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano commented May 28, 2026

What?

Closes #78701

Honor metadata.blockVisibility: false on the front end even after a block opts out of visibility block support, so HTML and Shortcode blocks saved while their support was enabled stay hidden.

Why?

Visibility support was disabled for the Shortcode block and the HTML block in #76138. This caused an unintended display of content on the front end.

How?

When metadata.visibility is false, block rendering is always prevented on the frontend.

As another issue, custom HTML blocks and shortcode blocks with metadata.visibility set to false lack a UI in the editor to make them visible again. Users must delete these blocks once. It might be possible to adjust the visibility UI display logic in the editor, but this seems a bit complex, so this PR focuses solely on frontend fixes.

Testing Instructions

Input the following code using the code editor:

<!-- wp:html {"metadata":{"blockVisibility":false}} -->
This HTML should not be displayed on the frontend.
<!-- /wp:html -->

<!-- wp:shortcode {"metadata":{"blockVisibility":false}} -->
[shortcode]
<!-- /wp:shortcode -->

The content should not be displayed on the front end.

Use of AI Tools

Drafted with Claude Code (Opus 4.7). All output reviewed and validated by the author.

…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.
@t-hamano t-hamano self-assigned this May 28, 2026
@t-hamano t-hamano added [Feature] Block API API that allows to express the block paradigm. Backwards Compatibility Issues or PRs that impact backwards compatability [Block] HTML Affects the the HTML Block Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release [Block] Shortcode Affects the Shortcode Block labels May 28, 2026
@t-hamano
Copy link
Copy Markdown
Contributor Author

I'm not yet convinced if this approach is ideal. If we are to move forward with this PR, I would like to submit a core PR.

@t-hamano t-hamano added the [Type] Bug An existing feature does not function as intended label May 28, 2026
@t-hamano t-hamano moved this to 🔎 Needs Review in WordPress 7.0 Editor Tasks May 28, 2026
@t-hamano t-hamano marked this pull request as ready for review May 28, 2026 14:08
@t-hamano t-hamano requested a review from spacedmonkey as a code owner May 28, 2026 14:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @krysek76.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: krysek76.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

Flaky tests detected in 85df3c4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26814187492
📝 Reported issues:

@talldan
Copy link
Copy Markdown
Contributor

talldan commented May 29, 2026

Another option could be to make the block supports more granular.

The shortcode and HTML block could use config like this and the users then get back the ability to toggle the blocks:

// doesn't support viewport hiding, but supports 'everywhere' hiding.
supports.visibility = { viewport: false, everywhere: true }

false | true could be kept for shorthands for full or no support.

My understanding is that still works for those blocks because the 'everywhere' feature doesn't use css classnames, it completely skips rendering the block.

I don't like 'everywhere' as the term, but hopefully you get the general idea.

Copy link
Copy Markdown
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for dealing with this so quickly @t-hamano

The staggered checks LGTM

@t-hamano
Copy link
Copy Markdown
Contributor Author

t-hamano commented Jun 2, 2026

Thanks for the review!

I'm not yet convinced if this approach is ideal. If we are to move forward with this PR, I would like to submit a core PR.

After creating the core ticket and core PR, I would like to merge this PR.

@t-hamano t-hamano merged commit bca81ff into trunk Jun 2, 2026
49 of 50 checks passed
@t-hamano t-hamano deleted the fix/shortcode-html-block-visibility-false branch June 2, 2026 12:08
@github-project-automation github-project-automation Bot moved this from 🔎 Needs Review to ✅ Done in WordPress 7.0 Editor Tasks Jun 2, 2026
@github-actions github-actions Bot added this to the Gutenberg 23.4 milestone Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release Backwards Compatibility Issues or PRs that impact backwards compatability [Block] HTML Affects the the HTML Block [Block] Shortcode Affects the Shortcode Block [Feature] Block API API that allows to express the block paradigm. [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

Hidden (Ctrl + Shift + H) shortcode block shows up in browser in incognito mode

3 participants