-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block visibility support: use CSS range syntax for media queries #74526
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 support: use CSS range syntax for media queries #74526
Conversation
…ries - Refactor media query generation in `block-visibility.php` to use 'width <=', 'width >=', and range syntax for breakpoints. - Update corresponding tests in `block-visibility-test.php` to reflect changes in media query format.
2a7a488 to
99d2e1b
Compare
westonruter
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.
This is looking great.
While partially stylistic choice, I find either using sprintf() or string interpolation to make the string literals easier to read.
Using string interpolation and update PHP doc. Co-authored-by: Weston Ruter <weston@ruter.net>
Much better, thank you! |
…p` by removing unnecessary checks. - Updated test assertion message in `block-visibility-test.php` for clarity on visibility rules.
|
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. |
|
Updated this with the feedback from WordPress/wordpress-develop#10629 as well (both should be synced now) |
| ); | ||
| } | ||
|
|
||
| if ( ! empty( $css_rules ) ) { |
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.
Why is the check no longer needed? We have similar checks in all the other places we're using gutenberg_style_engine_get_stylesheet_from_css_rules.
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.
@westonruter picked it up over at WordPress/wordpress-develop#10629 (comment)
By this point, $hidden_on isn't empty, so the loop runs at least once and $css_rules has at least one element.
gutenberg_style_engine_get_stylesheet_from_css_rules already handles empty values too.
tellthemachines
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.
LGTM!
|
Thanks for the quick review, folks! 🙇🏻 |
What?
Follow up to: #73994
block-visibility.phpto use 'width <=', 'width >=', and range syntax for breakpoints.block-visibility-test.php.See: WordPress/wordpress-develop#10629 (review)
Props to @westonruter for the nudge
Why?
I'll quote from WordPress/performance#1696
How?
Use range syntax instead of adding
1pxto the next breakpoint.See: https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Using#targeting_media_features
Testing
Unit tests:
npm run test:unit:php:base -- --filter=WP_Block_Supports_Block_Visibility_TestTo test manually, enable the experiment:
Then copy and paste this into your post editor, publish and view the frontend.
Kapture.2025-12-14.at.19.37.29.mp4
Make sure to test with the experiment off as well. The last item should never show with the experiment on and off.