-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Spacing presets: Add check for 0 spacing steps #43105
Conversation
…ice about invalid setting
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.
Good catch @glendaviesnz, this is working nicely for me!
Before, the following PHP Notice is output:
After, there is no notice and the presets aren't output. Setting to a value greater than 0 correctly still outputs the spacing sizes.
Not at all a blocker, but I was wondering if it's worth changing the check from 0 === $spacing_scale['steps']
to empty( $spacing_scale['steps'] )
so that any falsy value for steps would result in skipping the output without triggering an error? (E.g. 0
, false
, null
, etc)
The theory is that if a theme author doesn't want the core scale they explicitly set |
That sounds reasonable to me, particularly because |
@@ -1148,6 +1148,11 @@ protected static function get_property_value( $styles, $path, $theme_json = null | |||
public function set_spacing_sizes() { | |||
$spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() ); | |||
|
|||
// If theme authors want to prevent the generation of the core spacing scale they can set their theme.json spacingScale.steps to 0. | |||
if ( 0 === $spacing_scale['steps'] ) { |
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.
Oh, actually just another thought. This probably doesn't matter in practice because the base theme.json
contains the 'steps'
key, but if we keep the 0
check, should this line and the > 0
line below occur after the ! isset( $spacing_scale['steps'] )
check further down, to (theoretically) avoid an undefined index notice?
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.
yeh, makes more sense to check for invalid values first and then check for 0, have switched the order
Just retested and this is testing nicely for me, thanks for the update 👍 Again, not at all a blocker (do feel free to merge this PR as-is), but is there a reason we don't also allow opting out at the root feature level?
Whichever way we recommend themes do it, it'd be good to update https://developer.wordpress.org/themes/advanced-topics/theme-json/#enabling-and-disabling-settings with the desired approach prior to 6.1. If / when we document it, we can add |
no explicit reason @andrewserong , just hasn't been considered to-date - have added a note to explore this to the tracking issue |
Nice one, thanks @glendaviesnz! |
What?
Adds an early return from
set_spacing_sizes
if spacing.spaceScale.steps === 0.Why?
Theme authors should be able to set this to 0 to prevent the generation of the core default spacing presets, and currently doing so causing an
invalid valid
error notice to be thrown.How?
If pacing.spaceScale.steps === 0 return from method before spaceScale settings are validated
Testing Instructions
theme.json
file settings section:--wp--preset--spacing--*
CSS properties defined in the page source and that there is no PHP notice at the top of the page.Screenshots or screencast
Before:
After: