Skip to content
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

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) {
Copy link
Contributor

@andrewserong andrewserong Aug 11, 2022

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?

Copy link
Contributor Author

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

return null;
}

if ( ! is_numeric( $spacing_scale['steps'] )
|| ! $spacing_scale['steps'] > 0
|| ! isset( $spacing_scale['mediumStep'] )
Expand Down