Skip to content

Commit 17fa6e5

Browse files
authored
fix (global spacing & buttons): migrate global buttons and icons, spacing and borders (#3518)
1 parent 82f3613 commit 17fa6e5

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

src/plugins/global-settings/buttons-and-icons/index.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Stackable_Global_Buttons_And_Icons {
2121
function __construct() {
2222
// Register our settings.
2323
add_action( 'register_stackable_global_settings', array( $this, 'register_buttons_and_icons' ) );
24+
add_action( 'stackable_early_version_upgraded', array( $this, 'migrate_buttons_and_icons_schema_changes' ), 10, 2 );
2425

2526
if ( is_frontend() ) {
2627

@@ -113,6 +114,67 @@ public function add_body_class_buttons_and_icons( $classes ) {
113114
$classes[] = 'stk-has-design-system-buttons-and-icons';
114115
return $classes;
115116
}
117+
118+
public function migrate_buttons_and_icons_schema_changes( $old_version, $new_version ) {
119+
if ( empty( $old_version ) || version_compare( $old_version, "3.16.0", ">=" ) ) {
120+
return;
121+
}
122+
123+
$option_name = 'stackable_global_buttons_and_icons';
124+
$settings = get_option( $option_name );
125+
126+
if ( empty( $settings ) || ! is_array( $settings ) ) {
127+
return;
128+
}
129+
130+
$number_to_string_properties = [
131+
'button-min-height',
132+
'button-icon-gap',
133+
'button-column-gap',
134+
'button-row-gap',
135+
'icon-list-row-gap',
136+
];
137+
138+
$four_range_to_string_properties = [
139+
'button-padding',
140+
'icon-button-padding',
141+
'button-border-radius',
142+
];
143+
144+
$updated = false;
145+
146+
// Migrate number_properties to string_properties
147+
foreach ( $number_to_string_properties as $property ) {
148+
if ( isset( $settings[ $property ] ) && is_array( $settings[ $property ] ) ) {
149+
foreach ( $settings[ $property ] as $key => $value ) {
150+
if ( is_numeric( $value ) ) {
151+
$settings[ $property ][ $key ] = strval( $value );
152+
$updated = true;
153+
}
154+
}
155+
}
156+
}
157+
158+
// Migrate four_range_properties to string_four_range_properties
159+
foreach ( $four_range_to_string_properties as $property ) {
160+
if ( isset( $settings[ $property ] ) && is_array( $settings[ $property ] ) ) {
161+
foreach ( $settings[ $property ] as $viewport => $sides ) {
162+
if ( is_array( $sides ) ) {
163+
foreach ( $sides as $side => $value ) {
164+
if ( is_numeric( $value ) ) {
165+
$settings[ $property ][ $viewport ][ $side ] = strval( $value );
166+
$updated = true;
167+
}
168+
}
169+
}
170+
}
171+
}
172+
}
173+
174+
if ( $updated ) {
175+
update_option( $option_name, $settings );
176+
}
177+
}
116178
}
117179

118180
new Stackable_Global_Buttons_And_Icons();

src/plugins/global-settings/spacing-and-borders/index.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Stackable_Global_Spacing_And_Borders {
2121
function __construct() {
2222
// Register our settings.
2323
add_action( 'register_stackable_global_settings', array( $this, 'register_spacing_and_borders' ) );
24+
add_action( 'stackable_early_version_upgraded', array( $this, 'migrate_spacing_and_borders_schema_changes' ), 10, 2 );
2425

2526
if ( is_frontend() ) {
2627

@@ -114,6 +115,68 @@ public function add_body_class_spacing_and_borders( $classes ) {
114115
$classes[] = 'stk-has-design-system-spacing-and-borders';
115116
return $classes;
116117
}
118+
119+
public function migrate_spacing_and_borders_schema_changes( $old_version, $new_version ) {
120+
if ( empty( $old_version ) || version_compare( $old_version, "3.16.0", ">=" ) ) {
121+
return;
122+
}
123+
124+
$option_name = 'stackable_global_spacing_and_borders';
125+
$settings = get_option( $option_name );
126+
127+
if ( empty( $settings ) || ! is_array( $settings ) ) {
128+
return;
129+
}
130+
131+
$number_to_string_properties = [
132+
'block-margin-bottom',
133+
'columns-column-gap',
134+
'columns-row-gap',
135+
];
136+
137+
$four_range_to_string_properties = [
138+
'container-border-radius',
139+
'container-padding',
140+
'block-background-border-radius',
141+
'block-background-padding',
142+
'image-border-radius',
143+
];
144+
145+
$updated = false;
146+
147+
// Migrate number_properties to string_properties
148+
foreach ( $number_to_string_properties as $property ) {
149+
if ( isset( $settings[ $property ] ) && is_array( $settings[ $property ] ) ) {
150+
foreach ( $settings[ $property ] as $key => $value ) {
151+
if ( is_numeric( $value ) ) {
152+
$settings[ $property ][ $key ] = strval( $value );
153+
$updated = true;
154+
}
155+
}
156+
}
157+
}
158+
159+
// Migrate four_range_properties to string_four_range_properties
160+
foreach ( $four_range_to_string_properties as $property ) {
161+
if ( isset( $settings[ $property ] ) && is_array( $settings[ $property ] ) ) {
162+
foreach ( $settings[ $property ] as $viewport => $sides ) {
163+
if ( is_array( $sides ) ) {
164+
foreach ( $sides as $side => $value ) {
165+
if ( is_numeric( $value ) ) {
166+
$settings[ $property ][ $viewport ][ $side ] = strval( $value );
167+
$updated = true;
168+
}
169+
}
170+
}
171+
}
172+
}
173+
}
174+
175+
if ( $updated ) {
176+
update_option( $option_name, $settings );
177+
}
178+
}
179+
117180
}
118181

119182
new Stackable_Global_Spacing_And_Borders();

0 commit comments

Comments
 (0)