-
Notifications
You must be signed in to change notification settings - Fork 384
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
[Reader Mode] Add theme support features from theme.json
#7481
Conversation
eef4eed
to
bbe5ac0
Compare
bbe5ac0
to
b795721
Compare
b795721
to
2a3d437
Compare
theme.json
for WP >= 5.9 in Reader Themestheme.json
@westonruter Although the support for
amp-wp/src/ReaderThemeSupportFeatures.php Line 421 in 2a3d437
but there might be cases when someone defines them in
To solve the above scenarios WP 6.1 has two functions: but the caveat is they are available prior to WP 6.1. I'm considering defining them in our own class right now. Please let me know your thoughts? |
If someone is using block themes, I'd say it's highly unlikely that they would be holding off on updating WordPress core. Therefore, if you want to require WordPress 6.1+ to fully support fluid typography, that's fine with me. |
But I think we should update the way of determining measurement units. Someone can use different measurement unit even when fluid typography is not being used. |
- This is taken from `wp_get_typography_value_and_unit()`
…pped on WP < 5.9
PR can be tested for fluid typography by disabling CSS tree-shaking till #7291 get fixed. |
src/ReaderThemeSupportFeatures.php
Outdated
? esc_attr( wp_get_typography_font_size_value( $font_size ) ) | ||
: esc_attr( $font_size[ self::KEY_SIZE ] ) |
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.
Minor point, but I don't think esc_attr()
is right here. I think strip_tags()
is the right choice. See https://github.com/WordPress/wordpress-develop/blob/200868214a1ae0a108dac491677ba82e7541fc8d/src/wp-includes/theme.php#L1891-L1896
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.
It does make sense, but I am not sure if we will ever get tags here. Or better to never assume and update it to use strip_tags()
🤔
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.
Better to never assume, yeah
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.
Just realized, we will still need the escaping, as strip_tags
is not an escaping utility.
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.
Well, it is somewhat. It's what core uses in wp_custom_css_cb()
.
src/ReaderThemeSupportFeatures.php
Outdated
|
||
// Do not rely on `wp_is_block_theme()` as theme.json can be used in non-block themes. | ||
// See: https://developer.wordpress.org/themes/advanced-topics/theme-json/#a-theme-json-can-be-added-to-any-theme. | ||
return ( is_readable( get_stylesheet_directory() . '/theme.json' ) ? true : is_readable( get_template_directory() . '/theme.json' ) ); |
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 would seem simpler as:
return ( is_readable( get_stylesheet_directory() . '/theme.json' ) ? true : is_readable( get_template_directory() . '/theme.json' ) ); | |
return is_readable( get_stylesheet_directory() . '/theme.json' ) || is_readable( get_template_directory() . '/theme.json' ); |
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.
Actually, I suggest using wp_theme_has_theme_json()
if it exists, or else copy the function as a method into this class:
Note how it caches the file exists check.
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.
Note how it caches the file exists check.
Oh yes. Bette to copy it since we will need to check for theme.json on WP 5.9+ and this function is added in WP 6.2.
- Copied from `wp_theme_has_theme_json`
…on()` This reverts commit 1fc0531.
90568f3
to
7487201
Compare
5448a45
to
3cc3845
Compare
OK, let's change this: Line 116 in 4337065
To just |
Something else that isn't quite right, even with <!-- wp:paragraph {"backgroundColor":"primary","fontSize":"xx-large"} -->
<p class="has-primary-background-color has-background has-xx-large-font-size">Hello!</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent interdum, elit non cursus tincidunt, nibh nibh congue metus, ac gravida nunc ipsum ut augue. Donec tempor pulvinar maximus. Sed et tellus nec sapien vulputate sollicitudin. Nam auctor nulla imperdiet, sodales leo ultricies, cursus metus. Aenean ullamcorper dui vel neque luctus faucibus non vel odio. Aenean convallis mattis nisi, nec fringilla sem sagittis eget. Duis ut quam venenatis, blandit elit id, iaculis ipsum. Curabitur tristique euismod nisl, a finibus massa dignissim ac. Nullam nisl orci, imperdiet at libero sed, pulvinar vehicula lacus. Duis eleifend sollicitudin pharetra. Maecenas sapien nunc, mollis a velit sed, ultricies accumsan tortor. Ut accumsan sapien id turpis eleifend, at eleifend orci volutpat. Etiam massa arcu, congue sit amet sem vitae, gravida efficitur sem. Curabitur ornare velit velit, ut accumsan tellus convallis at. Nunc sagittis nisl mauris, nec hendrerit leo sagittis et.</p>
<!-- /wp:paragraph -->
|
Seems like the Line 203 in d03e179
|
Oh, if I actually look at Legacy in a mobile viewport it renders fine: Screen.recording.2023-03-17.13.20.20.webmWe could fix this by adding negative margins: p.has-background {
margin-left: -2.375em;
margin-right: -2.375em;
} Screen.recording.2023-03-17.13.24.26.webm |
Another case to check for: groups with backgrounds. <!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|40","right":"var:preset|spacing|40","bottom":"var:preset|spacing|40","left":"var:preset|spacing|40"}}},"backgroundColor":"primary","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-primary-background-color has-background" style="padding-top:var(--wp--preset--spacing--40);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--40);padding-left:var(--wp--preset--spacing--40)"><!-- wp:paragraph {"backgroundColor":"luminous-vivid-amber"} -->
<p class="has-luminous-vivid-amber-background-color has-background">First</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"backgroundColor":"vivid-red"} -->
<p class="has-vivid-red-background-color has-background">Second</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group --> Should look like this: |
- Print spacing sizes custom properties like `-wp--preset--spacing--30: clamp(1.5rem,5vw,2rem);`).
…ct spacing preset
Summary
Implemented in #6042, reader themes provide support for producing color palettes, gradient presets, and font size styles. This feature leverages
get theme support
to identify the necessary presets for generating the styles.Although
theme.json
can be used by any theme, it serves as a foundation for the new block themes. This PR seeks to enable theme support features styles generation using thetheme.json
presets to address the block styles breaking issues in reader mode.Fixes #7471
Checklist