@@ -44,6 +44,7 @@ class Stackable_Size_And_Spacing_Preset_Controls {
4444 function __construct () {
4545 add_action ( 'register_stackable_global_settings ' , array ( $ this , 'register_use_size_presets_by_default ' ) );
4646 add_action ( 'stackable_early_version_upgraded ' , array ( $ this , 'use_size_presets_by_default_set_default ' ), 10 , 2 );
47+ add_action ( 'stackable_early_version_upgraded ' , array ( $ this , 'migrate_global_typography_font_size ' ), 10 , 2 );
4748 add_filter ( 'stackable_js_settings ' , array ( $ this , 'add_setting ' ) );
4849
4950 add_filter ( 'stackable_inline_styles_nodep ' , array ( $ this , 'add_preset_controls_styles ' ) );
@@ -79,6 +80,40 @@ public function use_size_presets_by_default_set_default( $old_version, $new_vers
7980 }
8081 }
8182
83+ /**
84+ * Migrates global typography font sizes from numbers to strings
85+ * when upgrading to v3.16.0 and above
86+ *
87+ * @since 3.16.0
88+ */
89+ public function migrate_global_typography_font_size ( $ old_version , $ new_version ) {
90+ if ( ! empty ( $ old_version ) && version_compare ( $ old_version , "3.16.0 " , "< " ) ) {
91+ $ typography_option = get_option ( 'stackable_global_typography ' );
92+
93+ if ( ! empty ( $ typography_option ) && isset ( $ typography_option [ 0 ] ) && is_array ( $ typography_option [ 0 ] ) ) {
94+ $ updated = false ;
95+
96+ foreach ( $ typography_option [ 0 ] as $ key => $ item ) {
97+ if ( ! is_array ( $ item ) ) {
98+ continue ;
99+ }
100+
101+ foreach ( [ 'fontSize ' , 'tabletFontSize ' , 'mobileFontSize ' ] as $ size_key ) {
102+ if ( isset ( $ item [ $ size_key ] ) && is_numeric ( $ item [ $ size_key ] ) ) {
103+ $ typography_option [ 0 ][ $ key ][ $ size_key ] = strval ( $ item [ $ size_key ] );
104+ $ updated = true ;
105+ }
106+ }
107+ }
108+
109+ if ( $ updated ) {
110+ update_option ( 'stackable_global_typography ' , $ typography_option );
111+ }
112+ }
113+ }
114+ }
115+
116+
82117 // Make the setting available in the editor
83118 public function add_setting ( $ settings ) {
84119 $ settings ['stackable_use_size_presets_by_default ' ] = get_option ( 'stackable_use_size_presets_by_default ' );
0 commit comments