-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block visibility supports: refactor metadata to use nested structure #74602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block visibility supports: refactor metadata to use nested structure #74602
Conversation
…ilize a nested 'viewport' object for visibility settings, ensuring consistent behavior across the block editor. Adjust tests to reflect the new structure and maintain functionality.
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +51 B (0%) Total Size: 3.05 MB
ℹ️ View Unchanged
|
|
|
||
| if ( is_array( $block_visibility ) && ! empty( $block_visibility ) ) { | ||
| // Get viewport configuration from nested structure. | ||
| $viewport_config = $block_visibility['viewport'] ?? null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty basic, but my general idea is that later, sources could define their own evaluation rules for when blocks are hidden.
This could be via filters, or some sort of registration pattern. Not sure yet.
Maybe theme.json if we want to build a UI around it.
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Everything works well for me 👍
What?
Related to:
Refactors block visibility metadata to use a nested structure where viewport settings are stored under a
viewportkey.Note
The backport PR should be updated once a path is decided upon.
Why?
This change prepares the foundation for adding additional visibility sources (e.g., user role, time period) in the future.
See discussion over at: #72502 (comment)
How?
blockVisibility: { mobile: false }→blockVisibility: { viewport: { mobile: false } }blockVisibility: false(hidden everywhere) remains the sameNotes on future extensibility
This nested structure enables future extensibility for additional visibility sources:
Later plugins could register custom sources with each source managing its own configuration schema. Core logic could iterate through registered sources or via filter, e.g.,
apply_filters( 'block_visibility_sources', $sources )Testing Instructions
There should be no regressions from #74249
Enable experimental flag in
/wp-admin/admin.php?page=gutenberg-experimentsHere's some example HTML:
Example HTML
Check that the correct blocks hide in the correct viewports, and that there are no regressions from #74249