@@ -68,15 +68,20 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
6868 return array ();
6969 }
7070
71- $ attributes = array ();
72- $ classes = array ();
73- $ styles = array ();
74-
7571 $ typography_supports = _wp_array_get ( $ block_type ->supports , array ( 'typography ' ), false );
7672 if ( ! $ typography_supports ) {
7773 return array ();
7874 }
7975
76+ $ skip_typography_serialization = _wp_array_get ( $ typography_supports , array ( '__experimentalSkipSerialization ' ), false );
77+ if ( $ skip_typography_serialization ) {
78+ return array ();
79+ }
80+
81+ $ attributes = array ();
82+ $ classes = array ();
83+ $ styles = array ();
84+
8085 $ has_font_family_support = _wp_array_get ( $ typography_supports , array ( '__experimentalFontFamily ' ), false );
8186 $ has_font_size_support = _wp_array_get ( $ typography_supports , array ( 'fontSize ' ), false );
8287 $ has_font_style_support = _wp_array_get ( $ typography_supports , array ( '__experimentalFontStyle ' ), false );
@@ -85,26 +90,19 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
8590 $ has_text_decoration_support = _wp_array_get ( $ typography_supports , array ( '__experimentalTextDecoration ' ), false );
8691 $ has_text_transform_support = _wp_array_get ( $ typography_supports , array ( '__experimentalTextTransform ' ), false );
8792
88- // Covers all typography features.
89- $ skip_typography_serialization = _wp_array_get ( $ typography_supports , array ( '__experimentalSkipSerialization ' ), false );
90-
91- // Font Size.
92- if ( $ has_font_size_support && ! $ skip_typography_serialization ) {
93+ if ( $ has_font_size_support ) {
9394 $ has_named_font_size = array_key_exists ( 'fontSize ' , $ block_attributes );
9495 $ has_custom_font_size = isset ( $ block_attributes ['style ' ]['typography ' ]['fontSize ' ] );
9596
96- // Apply required class or style.
9797 if ( $ has_named_font_size ) {
9898 $ classes [] = sprintf ( 'has-%s-font-size ' , $ block_attributes ['fontSize ' ] );
9999 } elseif ( $ has_custom_font_size ) {
100100 $ styles [] = sprintf ( 'font-size: %s; ' , $ block_attributes ['style ' ]['typography ' ]['fontSize ' ] );
101101 }
102102 }
103103
104- // Font Family.
105- if ( $ has_font_family_support && ! $ skip_typography_serialization ) {
104+ if ( $ has_font_family_support ) {
106105 $ has_font_family = isset ( $ block_attributes ['style ' ]['typography ' ]['fontFamily ' ] );
107- // Apply required class and style.
108106 if ( $ has_font_family ) {
109107 $ font_family = $ block_attributes ['style ' ]['typography ' ]['fontFamily ' ];
110108 if ( strpos ( $ font_family , 'var:preset|font-family ' ) !== false ) {
@@ -118,43 +116,35 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
118116 }
119117 }
120118
121- // Font style.
122- if ( $ has_font_style_support && ! $ skip_typography_serialization ) {
123- // Apply font style.
119+ if ( $ has_font_style_support ) {
124120 $ font_style = gutenberg_typography_get_css_variable_inline_style ( $ block_attributes , 'fontStyle ' , 'font-style ' );
125121 if ( $ font_style ) {
126122 $ styles [] = $ font_style ;
127123 }
128124 }
129125
130- // Font weight.
131- if ( $ has_font_weight_support && ! $ skip_typography_serialization ) {
132- // Apply font weight.
126+ if ( $ has_font_weight_support ) {
133127 $ font_weight = gutenberg_typography_get_css_variable_inline_style ( $ block_attributes , 'fontWeight ' , 'font-weight ' );
134128 if ( $ font_weight ) {
135129 $ styles [] = $ font_weight ;
136130 }
137131 }
138132
139- // Line Height.
140- if ( $ has_line_height_support && ! $ skip_typography_serialization ) {
133+ if ( $ has_line_height_support ) {
141134 $ has_line_height = isset ( $ block_attributes ['style ' ]['typography ' ]['lineHeight ' ] );
142- // Add the style (no classes for line-height).
143135 if ( $ has_line_height ) {
144136 $ styles [] = sprintf ( 'line-height: %s; ' , $ block_attributes ['style ' ]['typography ' ]['lineHeight ' ] );
145137 }
146138 }
147139
148- // Text Decoration.
149- if ( $ has_text_decoration_support && ! $ skip_typography_serialization ) {
140+ if ( $ has_text_decoration_support ) {
150141 $ text_decoration_style = gutenberg_typography_get_css_variable_inline_style ( $ block_attributes , 'textDecoration ' , 'text-decoration ' );
151142 if ( $ text_decoration_style ) {
152143 $ styles [] = $ text_decoration_style ;
153144 }
154145 }
155146
156- // Text Transform.
157- if ( $ has_text_transform_support && ! $ skip_typography_serialization ) {
147+ if ( $ has_text_transform_support ) {
158148 $ text_transform_style = gutenberg_typography_get_css_variable_inline_style ( $ block_attributes , 'textTransform ' , 'text-transform ' );
159149 if ( $ text_transform_style ) {
160150 $ styles [] = $ text_transform_style ;
0 commit comments