26 |
26 |
27 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false ); |
27 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false ); |
28 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false ); |
28 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false ); |
29 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); |
29 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); |
30 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); |
30 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); |
|
31 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); |
31 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); |
32 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); |
32 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); |
33 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); |
33 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); |
34 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); |
34 |
35 |
35 $has_typography_support = $has_font_family_support |
36 $has_typography_support = $has_font_family_support |
36 || $has_font_size_support |
37 || $has_font_size_support |
37 || $has_font_style_support |
38 || $has_font_style_support |
38 || $has_font_weight_support |
39 || $has_font_weight_support |
|
40 || $has_letter_spacing_support |
39 || $has_line_height_support |
41 || $has_line_height_support |
40 || $has_text_decoration_support |
42 || $has_text_decoration_support |
41 || $has_text_transform_support; |
43 || $has_text_transform_support; |
42 |
44 |
43 if ( ! $block_type->attributes ) { |
45 if ( ! $block_type->attributes ) { |
91 |
91 |
92 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false ); |
92 $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false ); |
93 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false ); |
93 $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false ); |
94 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); |
94 $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false ); |
95 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); |
95 $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false ); |
|
96 $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false ); |
96 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); |
97 $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false ); |
97 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); |
98 $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false ); |
98 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); |
99 $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false ); |
99 |
100 |
100 if ( $has_font_size_support ) { |
101 if ( $has_font_size_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' ) ) { |
101 $has_named_font_size = array_key_exists( 'fontSize', $block_attributes ); |
102 $has_named_font_size = array_key_exists( 'fontSize', $block_attributes ); |
102 $has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] ); |
103 $has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] ); |
103 |
104 |
104 if ( $has_named_font_size ) { |
105 if ( $has_named_font_size ) { |
105 $classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] ); |
106 $classes[] = sprintf( 'has-%s-font-size', _wp_to_kebab_case( $block_attributes['fontSize'] ) ); |
106 } elseif ( $has_custom_font_size ) { |
107 } elseif ( $has_custom_font_size ) { |
107 $styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] ); |
108 $styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] ); |
108 } |
109 } |
109 } |
110 } |
110 |
111 |
111 if ( $has_font_family_support ) { |
112 if ( $has_font_family_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontFamily' ) ) { |
112 $has_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ); |
113 $has_named_font_family = array_key_exists( 'fontFamily', $block_attributes ); |
113 if ( $has_font_family ) { |
114 $has_custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] ); |
114 $font_family = $block_attributes['style']['typography']['fontFamily']; |
115 |
115 if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) { |
116 if ( $has_named_font_family ) { |
116 // Get the name from the string and add proper styles. |
117 $classes[] = sprintf( 'has-%s-font-family', _wp_to_kebab_case( $block_attributes['fontFamily'] ) ); |
117 $index_to_splice = strrpos( $font_family, '|' ) + 1; |
118 } elseif ( $has_custom_font_family ) { |
118 $font_family_name = substr( $font_family, $index_to_splice ); |
119 // Before using classes, the value was serialized as a CSS Custom Property. |
119 $styles[] = sprintf( 'font-family: var(--wp--preset--font-family--%s);', $font_family_name ); |
120 // We don't need this code path when it lands in core. |
120 } else { |
121 $font_family_custom = $block_attributes['style']['typography']['fontFamily']; |
121 $styles[] = sprintf( 'font-family: %s;', $block_attributes['style']['typography']['fontFamily'] ); |
122 if ( strpos( $font_family_custom, 'var:preset|font-family' ) !== false ) { |
|
123 $index_to_splice = strrpos( $font_family_custom, '|' ) + 1; |
|
124 $font_family_slug = _wp_to_kebab_case( substr( $font_family_custom, $index_to_splice ) ); |
|
125 $font_family_custom = sprintf( 'var(--wp--preset--font-family--%s)', $font_family_slug ); |
122 } |
126 } |
123 } |
127 $styles[] = sprintf( 'font-family: %s;', $font_family_custom ); |
124 } |
128 } |
125 |
129 } |
126 if ( $has_font_style_support ) { |
130 |
|
131 if ( $has_font_style_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontStyle' ) ) { |
127 $font_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' ); |
132 $font_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' ); |
128 if ( $font_style ) { |
133 if ( $font_style ) { |
129 $styles[] = $font_style; |
134 $styles[] = $font_style; |
130 } |
135 } |
131 } |
136 } |
132 |
137 |
133 if ( $has_font_weight_support ) { |
138 if ( $has_font_weight_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontWeight' ) ) { |
134 $font_weight = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' ); |
139 $font_weight = wp_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' ); |
135 if ( $font_weight ) { |
140 if ( $font_weight ) { |
136 $styles[] = $font_weight; |
141 $styles[] = $font_weight; |
137 } |
142 } |
138 } |
143 } |
139 |
144 |
140 if ( $has_line_height_support ) { |
145 if ( $has_line_height_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'lineHeight' ) ) { |
141 $has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] ); |
146 $has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] ); |
142 if ( $has_line_height ) { |
147 if ( $has_line_height ) { |
143 $styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] ); |
148 $styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] ); |
144 } |
149 } |
145 } |
150 } |
146 |
151 |
147 if ( $has_text_decoration_support ) { |
152 if ( $has_text_decoration_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' ) ) { |
148 $text_decoration_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' ); |
153 $text_decoration_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' ); |
149 if ( $text_decoration_style ) { |
154 if ( $text_decoration_style ) { |
150 $styles[] = $text_decoration_style; |
155 $styles[] = $text_decoration_style; |
151 } |
156 } |
152 } |
157 } |
153 |
158 |
154 if ( $has_text_transform_support ) { |
159 if ( $has_text_transform_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' ) ) { |
155 $text_transform_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' ); |
160 $text_transform_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' ); |
156 if ( $text_transform_style ) { |
161 if ( $text_transform_style ) { |
157 $styles[] = $text_transform_style; |
162 $styles[] = $text_transform_style; |
158 } |
163 } |
159 } |
164 } |
160 |
165 |
|
166 if ( $has_letter_spacing_support && ! wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' ) ) { |
|
167 $letter_spacing_style = wp_typography_get_css_variable_inline_style( $block_attributes, 'letterSpacing', 'letter-spacing' ); |
|
168 if ( $letter_spacing_style ) { |
|
169 $styles[] = $letter_spacing_style; |
|
170 } |
|
171 } |
|
172 |
161 if ( ! empty( $classes ) ) { |
173 if ( ! empty( $classes ) ) { |
162 $attributes['class'] = implode( ' ', $classes ); |
174 $attributes['class'] = implode( ' ', $classes ); |
163 } |
175 } |
164 if ( ! empty( $styles ) ) { |
176 if ( ! empty( $styles ) ) { |
165 $attributes['style'] = implode( ' ', $styles ); |
177 $attributes['style'] = implode( ' ', $styles ); |