Skip to content
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
Prev Previous commit
Put t-short sizing back if more than 7 steps so better labeling in se…
…lect menu
  • Loading branch information
glendaviesnz committed Sep 20, 2022
commit 9631c914020fecfff7daa2cfb3faa2e244ccee83
40 changes: 32 additions & 8 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 @@ -1249,6 +1249,7 @@ public function set_spacing_sizes() {
$unit = '%' === $spacing_scale['unit'] ? '%' : sanitize_title( $spacing_scale['unit'] );
$current_step = $spacing_scale['mediumStep'];
$steps_mid_point = round( $spacing_scale['steps'] / 2, 0 );
$x_small_count = null;
$below_sizes = array();
$slug = 40;
$remainder = 0;
Expand All @@ -1268,11 +1269,20 @@ public function set_spacing_sizes() {
}

$below_sizes[] = array(
'name' => null,
/* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Small. */
'name' => $below_midpoint_count === $steps_mid_point - 1 ? __( 'Small', 'gutenberg' ) : sprintf( __( '%sX-Small', 'gutenberg' ), strval( $x_small_count ) ),
'slug' => (string) $slug,
'size' => round( $current_step, 2 ) . $unit,
);

if ( $below_midpoint_count === $steps_mid_point - 2 ) {
$x_small_count = 2;
}

if ( $below_midpoint_count < $steps_mid_point - 2 ) {
$x_small_count++;
}

$slug -= 10;
}

Expand All @@ -1284,28 +1294,42 @@ public function set_spacing_sizes() {
'size' => $spacing_scale['mediumStep'] . $unit,
);

$current_step = $spacing_scale['mediumStep'];
$above_sizes = array();
$slug = 60;
$steps_above = ( $spacing_scale['steps'] - $steps_mid_point ) + $remainder;
$current_step = $spacing_scale['mediumStep'];
$x_large_count = null;
$above_sizes = array();
$slug = 60;
$steps_above = ( $spacing_scale['steps'] - $steps_mid_point ) + $remainder;

for ( $above_midpoint_count = 0; $above_midpoint_count < $steps_above; $above_midpoint_count++ ) {
$current_step = '+' === $spacing_scale['operator']
? $current_step + $spacing_scale['increment']
: ( $spacing_scale['increment'] >= 1 ? $current_step * $spacing_scale['increment'] : $current_step / $spacing_scale['increment'] );

$above_sizes[] = array(
'name' => null,
/* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Large. */
'name' => 0 === $above_midpoint_count ? __( 'Large', 'gutenberg' ) : sprintf( __( '%sX-Large', 'gutenberg' ), strval( $x_large_count ) ),
'slug' => (string) $slug,
'size' => round( $current_step, 2 ) . $unit,
);

if ( 1 === $above_midpoint_count ) {
$x_large_count = 2;
}

if ( $above_midpoint_count > 1 ) {
$x_large_count++;
}

$slug += 10;
}

$spacing_sizes = array_merge( $below_sizes, $above_sizes );

for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) {
$spacing_sizes[ $spacing_sizes_count ]['name'] = strval( $spacing_sizes_count + 1 );
// If there are 7 or less steps in the scale revert to numbers for labels instead of t-shirt sizes.
if ( $spacing_scale['steps'] <= 7 ) {
for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) {
$spacing_sizes[ $spacing_sizes_count ]['name'] = strval( $spacing_sizes_count + 1 );
}
}

_wp_array_set( $this->theme_json, array( 'settings', 'spacing', 'spacingSizes', 'default' ), $spacing_sizes );
Expand Down