@@ -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