Skip to content

Commit 504ca03

Browse files
committed
fix: add global typography font size migration
1 parent 81ec94f commit 504ca03

File tree

1 file changed

+36
-0
lines changed
  • src/plugins/global-settings/preset-controls

1 file changed

+36
-0
lines changed

src/plugins/global-settings/preset-controls/index.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,41 @@ 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+
$typography_option = get_option( 'stackable_global_typography' );
91+
92+
if ( ! empty( $old_version ) && version_compare( $old_version, "3.16.0", "<" )
93+
&& ! empty( $typography_option ) && isset( $typography_option[ 0 ] )
94+
) {
95+
$typography = $typography_option[ 0 ];
96+
$updated = false;
97+
98+
foreach ( $typography as $key => $item ) {
99+
if ( ! is_array( $item ) ) {
100+
continue;
101+
}
102+
103+
foreach ( [ 'fontSize', 'tabletFontSize', 'mobileFontSize' ] as $size_key ) {
104+
if ( isset( $item[ $size_key ] ) && is_numeric( $item[ $size_key ] ) ) {
105+
$typography[ $key ][ $size_key ] = strval( $item[ $size_key ] );
106+
$updated = true;
107+
}
108+
}
109+
}
110+
111+
if ( $updated ) {
112+
$typography_option[ 0 ] = $typography;
113+
update_option( 'stackable_global_typography', $typography_option );
114+
}
115+
}
116+
}
117+
82118
// Make the setting available in the editor
83119
public function add_setting( $settings ) {
84120
$settings['stackable_use_size_presets_by_default'] = get_option( 'stackable_use_size_presets_by_default' );

0 commit comments

Comments
 (0)