Skip to content

Commit cab34c7

Browse files
committed
create array/object for four-range values
1 parent fd86128 commit cab34c7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/global-settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,18 @@ public static function generate_global_block_layouts( $option_name, $settings_na
950950
}
951951
} else if ( is_array( $value ) ) {
952952
$default_value = Stackable_Global_Settings::get_block_layout_defaults( $defaults, $property, $device );
953+
954+
// In case the default value is a number (same value for all sides)
955+
if ( ! is_array( $default_value ) ) {
956+
$_default_value = $default_value;
957+
$default_value = array(
958+
"top" => $_default_value,
959+
"right" => $_default_value,
960+
"bottom" => $_default_value,
961+
"left" => $_default_value
962+
);
963+
}
964+
953965
$top = isset( $value[ 'top' ] ) ? $value[ 'top' ] : $default_value[ 'top' ];
954966
$right = isset( $value[ 'right' ] ) ? $value[ 'right' ] : $default_value[ 'right' ];
955967
$bottom = isset( $value[ 'bottom' ] ) ? $value[ 'bottom' ] : $default_value[ 'bottom' ];

src/plugins/global-settings/utils/use-block-layout-editor-loader.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,19 @@ const renderGlobalStyles = (
5454
if ( typeof value === 'string' ) {
5555
style = `${ property }: ${ value };`
5656
} else if ( typeof value === 'object' ) {
57-
const defaultValue = getDefault( blockLayoutDefaults, _property, device )
57+
let defaultValue = getDefault( blockLayoutDefaults, _property, device )
58+
59+
// In case the default value is a number (same value for all sides)
60+
if ( typeof defaultValue !== 'object' ) {
61+
const _defaultValue = defaultValue
62+
defaultValue = {
63+
top: _defaultValue,
64+
right: _defaultValue,
65+
bottom: _defaultValue,
66+
left: _defaultValue,
67+
}
68+
}
69+
5870
const top = value.top !== undefined ? value.top : defaultValue.top
5971
const right = value.right !== undefined ? value.right : defaultValue.right
6072
const bottom = value.bottom !== undefined ? value.bottom : defaultValue.bottom

0 commit comments

Comments
 (0)