Skip to content

Commit 82f3613

Browse files
authored
fix (global typography): Migrate global typography font sizes to string (#3517)
* fix: add checks before migrating * fix: add global typography font size migration * fix: move db lookup * fix: add additional checks * fix: remove typography var
1 parent ba514ab commit 82f3613

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

src/block-components/alignment/deprecated/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ export const deprecateInnerBlockRowGapAndContainerHeight = {
2929
const getAttrName = getAttrNameFunction( attrNameTemplate )
3030
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
3131

32+
const newAttributes = {
33+
...attributes,
34+
}
35+
3236
const containerHeight = getAttribute( 'containerHeight' )
3337
const innerBlockRowGap = getAttribute( 'innerBlockRowGap' )
3438

35-
const newAttributes = {
36-
...attributes,
37-
[ getAttrName( 'containerHeight' ) ]: String( containerHeight ),
38-
[ getAttrName( 'innerBlockRowGap' ) ]: String( innerBlockRowGap ),
39+
if ( typeof containerHeight === 'number' ) {
40+
newAttributes[ getAttrName( 'containerHeight' ) ] = String( containerHeight )
41+
}
42+
43+
if ( typeof innerBlockRowGap === 'number' ) {
44+
newAttributes[ getAttrName( 'innerBlockRowGap' ) ] = String( innerBlockRowGap )
3945
}
4046

4147
return newAttributes

src/block-components/columns/deprecated/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ export const deprecateColumnAndRowGap = {
4141
const getAttrName = getAttrNameFunction( attrNameTemplate )
4242
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
4343

44+
const newAttributes = {
45+
...attributes,
46+
}
47+
4448
const columnSpacing = getAttribute( 'columnSpacing' )
4549
const columnGap = getAttribute( 'columnGap' )
4650
const rowGap = getAttribute( 'rowGap' )
4751

48-
const newAttributes = {
49-
...attributes,
50-
[ getAttrName( 'columnSpacing' ) ]: String( columnSpacing ),
51-
[ getAttrName( 'columnGap' ) ]: String( columnGap ),
52-
[ getAttrName( 'rowGap' ) ]: String( rowGap ),
52+
if ( typeof columnSpacing === 'number' ) {
53+
newAttributes[ getAttrName( 'columnSpacing' ) ] = String( columnSpacing )
54+
}
55+
56+
if ( typeof columnGap === 'number' ) {
57+
newAttributes[ getAttrName( 'columnGap' ) ] = String( columnGap )
58+
}
59+
60+
if ( typeof rowGap === 'number' ) {
61+
newAttributes[ getAttrName( 'rowGap' ) ] = String( rowGap )
5362
}
5463

5564
return newAttributes

src/block-components/helpers/size/deprecated.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ export const deprecateSizeControlHeight = {
2929
const getAttrName = getAttrNameFunction( attrNameTemplate )
3030
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
3131

32-
const height = getAttribute( 'height' )
33-
3432
const newAttributes = {
3533
...attributes,
36-
[ getAttrName( 'height' ) ]: String( height ),
34+
}
35+
36+
const height = getAttribute( 'height' )
37+
38+
if ( typeof height === 'number' ) {
39+
newAttributes[ getAttrName( 'height' ) ] = String( height )
3740
}
3841

3942
return newAttributes

src/block-components/typography/deprecated.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ export const deprecateTypographyFontSize = {
130130
const getAttrName = getAttrNameFunction( attrNameTemplate )
131131
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
132132

133-
const fontSize = getAttribute( 'fontSize' )
134-
135133
const newAttributes = {
136134
...attributes,
137-
[ getAttrName( 'fontSize' ) ]: String( fontSize ),
135+
}
136+
137+
const fontSize = getAttribute( 'fontSize' )
138+
139+
if ( typeof fontSize === 'number' ) {
140+
newAttributes[ getAttrName( 'fontSize' ) ] = String( fontSize )
138141
}
139142

140143
return newAttributes

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

Lines changed: 35 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,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

Comments
 (0)