PluginProbe
Gutenberg / 10.1.0
Gutenberg v10.1.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | lib/block-supports/typography.php +44 -63 12.6.0 → 10.1.0 View file →
@@ -14,30 +14,21 @@
14 14 if ( ! property_exists( $block_type, 'supports' ) ) {
15 15 return;
16 16 }
17 17
18 - $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
19 - if ( ! $typography_supports ) {
20 - return;
21 - }
18 + $has_font_size_support = gutenberg_experimental_get( $block_type->supports, array( 'fontSize' ), false );
19 + $has_font_style_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
20 + $has_font_weight_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
21 + $has_line_height_support = gutenberg_experimental_get( $block_type->supports, array( 'lineHeight' ), false );
22 + $has_text_decoration_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
23 + $has_text_transform_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalTextTransform' ), false );
22 24
23 - $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
24 - $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
25 - $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
26 - $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
27 - $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
28 - $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
29 - $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
30 - $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
31 -
32 - $has_typography_support = $has_font_family_support
33 - || $has_font_size_support
25 + $has_typography_support = $has_font_size_support
26 + || $has_font_weight_support
34 27 || $has_font_style_support
35 - || $has_font_weight_support
36 - || $has_letter_spacing_support
37 28 || $has_line_height_support
38 - || $has_text_decoration_support
39 - || $has_text_transform_support;
29 + || $has_text_transform_support
30 + || $has_text_decoration_support;
40 31
41 32 if ( ! $block_type->attributes ) {
42 33 $block_type->attributes = array();
43 34 }
@@ -69,62 +60,52 @@
69 60 if ( ! property_exists( $block_type, 'supports' ) ) {
70 61 return array();
71 62 }
72 63
73 - $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
74 - if ( ! $typography_supports ) {
75 - return array();
76 - }
64 + $classes = array();
65 + $styles = array();
77 66
78 - $skip_typography_serialization = _wp_array_get( $typography_supports, array( '__experimentalSkipSerialization' ), false );
79 - if ( $skip_typography_serialization ) {
80 - return array();
81 - }
67 + $has_font_family_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalFontFamily' ), false );
68 + $has_font_style_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
69 + $has_font_weight_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
70 + $has_font_size_support = gutenberg_experimental_get( $block_type->supports, array( 'fontSize' ), false );
71 + $has_line_height_support = gutenberg_experimental_get( $block_type->supports, array( 'lineHeight' ), false );
72 + $has_text_decoration_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
73 + $has_text_transform_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalTextTransform' ), false );
82 74
83 - $attributes = array();
84 - $classes = array();
85 - $styles = array();
86 -
87 - $has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
88 - $has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
89 - $has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
90 - $has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
91 - $has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
92 - $has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
93 - $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
94 - $has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
95 -
75 + // Font Size.
96 76 if ( $has_font_size_support ) {
97 77 $has_named_font_size = array_key_exists( 'fontSize', $block_attributes );
98 78 $has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] );
99 79
80 + // Apply required class or style.
100 81 if ( $has_named_font_size ) {
101 - $classes[] = sprintf( 'has-%s-font-size', _wp_to_kebab_case( $block_attributes['fontSize'] ) );
82 + $classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] );
102 83 } elseif ( $has_custom_font_size ) {
103 84 $styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] );
104 85 }
105 86 }
106 87
88 + // Font Family.
107 89 if ( $has_font_family_support ) {
108 - $has_named_font_family = array_key_exists( 'fontFamily', $block_attributes );
109 - $has_custom_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );
110 -
111 - if ( $has_named_font_family ) {
112 - $classes[] = sprintf( 'has-%s-font-family', _wp_to_kebab_case( $block_attributes['fontFamily'] ) );
113 - } elseif ( $has_custom_font_family ) {
114 - // Before using classes, the value was serialized as a CSS Custom Property.
115 - // We don't need this code path when it lands in core.
116 - $font_family_custom = $block_attributes['style']['typography']['fontFamily'];
117 - if ( strpos( $font_family_custom, 'var:preset|font-family' ) !== false ) {
118 - $index_to_splice = strrpos( $font_family_custom, '|' ) + 1;
119 - $font_family_slug = _wp_to_kebab_case( substr( $font_family_custom, $index_to_splice ) );
120 - $font_family_custom = sprintf( 'var(--wp--preset--font-family--%s)', $font_family_slug );
90 + $has_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );
91 + // Apply required class and style.
92 + if ( $has_font_family ) {
93 + $font_family = $block_attributes['style']['typography']['fontFamily'];
94 + if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) {
95 + // Get the name from the string and add proper styles.
96 + $index_to_splice = strrpos( $font_family, '|' ) + 1;
97 + $font_family_name = substr( $font_family, $index_to_splice );
98 + $styles[] = sprintf( 'font-family: var(--wp--preset--font-family--%s);', $font_family_name );
99 + } else {
100 + $styles[] = sprintf( 'font-family: %s;', $block_attributes['style']['color']['fontFamily'] );
121 101 }
122 - $styles[] = sprintf( 'font-family: %s;', $font_family_custom );
123 102 }
124 103 }
125 104
105 + // Font style.
126 106 if ( $has_font_style_support ) {
107 + // Apply font style.
127 108 $font_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' );
128 109 if ( $font_style ) {
129 110 $styles[] = $font_style;
130 111 }
@@ -129,9 +110,11 @@
129 110 $styles[] = $font_style;
130 111 }
131 112 }
132 113
114 + // Font weight.
133 115 if ( $has_font_weight_support ) {
116 + // Apply font weight.
134 117 $font_weight = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' );
135 118 if ( $font_weight ) {
136 119 $styles[] = $font_weight;
137 120 }
@@ -136,15 +119,18 @@
136 119 $styles[] = $font_weight;
137 120 }
138 121 }
139 122
123 + // Line Height.
140 124 if ( $has_line_height_support ) {
141 125 $has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] );
126 + // Add the style (no classes for line-height).
142 127 if ( $has_line_height ) {
143 128 $styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] );
144 129 }
145 130 }
146 131
132 + // Text Decoration.
147 133 if ( $has_text_decoration_support ) {
148 134 $text_decoration_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' );
149 135 if ( $text_decoration_style ) {
150 136 $styles[] = $text_decoration_style;
@@ -150,8 +136,9 @@
150 136 $styles[] = $text_decoration_style;
151 137 }
152 138 }
153 139
140 + // Text Transform.
154 141 if ( $has_text_transform_support ) {
155 142 $text_transform_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' );
156 143 if ( $text_transform_style ) {
157 144 $styles[] = $text_transform_style;
@@ -157,15 +144,9 @@
157 144 $styles[] = $text_transform_style;
158 145 }
159 146 }
160 147
161 - if ( $has_letter_spacing_support ) {
162 - $letter_spacing_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'letterSpacing', 'letter-spacing' );
163 - if ( $letter_spacing_style ) {
164 - $styles[] = $letter_spacing_style;
165 - }
166 - }
167 -
148 + $attributes = array();
168 149 if ( ! empty( $classes ) ) {
169 150 $attributes['class'] = implode( ' ', $classes );
170 151 }
171 152 if ( ! empty( $styles ) ) {
@@ -186,9 +167,9 @@
186 167 * @return string CSS inline style.
187 168 */
188 169 function gutenberg_typography_get_css_variable_inline_style( $attributes, $feature, $css_property ) {
189 170 // Retrieve current attribute value or skip if not found.
190 - $style_value = _wp_array_get( $attributes, array( 'style', 'typography', $feature ), false );
171 + $style_value = gutenberg_experimental_get( $attributes, array( 'style', 'typography', $feature ), false );
191 172 if ( ! $style_value ) {
192 173 return;
193 174 }
194 175