Changeset 54497 for trunk/src/wp-includes/block-supports/typography.php
- Timestamp:
- 10/11/2022 06:42:20 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/typography.php
r54387 r54497 120 120 ? $block_attributes['style']['typography']['fontSize'] 121 121 : null; 122 $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : $custom_font_size; 122 $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : wp_get_typography_font_size_value( 123 array( 124 'size' => $custom_font_size, 125 ) 126 ); 123 127 } 124 128 … … 246 250 247 251 /** 252 * Renders typography styles/content to the block wrapper. 253 * 254 * @since 6.1.0 255 * 256 * @param string $block_content Rendered block content. 257 * @param array $block Block object. 258 * @return string Filtered block content. 259 */ 260 function wp_render_typography_support( $block_content, $block ) { 261 if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) { 262 return $block_content; 263 } 264 265 $custom_font_size = $block['attrs']['style']['typography']['fontSize']; 266 $fluid_font_size = wp_get_typography_font_size_value( array( 'size' => $custom_font_size ) ); 267 268 /* 269 * Checks that $fluid_font_size does not match $custom_font_size, 270 * which means it's been mutated by the fluid font size functions. 271 */ 272 if ( ! empty( $fluid_font_size ) && $fluid_font_size !== $custom_font_size ) { 273 // Replaces the first instance of `font-size:$custom_font_size` with `font-size:$fluid_font_size`. 274 return preg_replace( '/font-size\s*:\s*' . preg_quote( $custom_font_size, '/' ) . '\s*;?/', 'font-size:' . esc_attr( $fluid_font_size ) . ';', $block_content, 1 ); 275 } 276 277 return $block_content; 278 } 279 280 /** 248 281 * Checks a string for a unit and value and returns an array 249 * consisting of `'value'` and `'unit'`, e.g. , [ '42', 'rem' ].282 * consisting of `'value'` and `'unit'`, e.g. array( '42', 'rem' ). 250 283 * 251 284 * @since 6.1.0 252 * @access private 253 * 254 * @param string $raw_value Raw size value from theme.json. 255 * @param array $options { 285 * 286 * @param string|int|float $raw_value Raw size value from theme.json. 287 * @param array $options { 256 288 * Optional. An associative array of options. Default is empty array. 257 289 * 258 290 * @type string $coerce_to Coerce the value to rem or px. Default `'rem'`. 259 291 * @type int $root_size_value Value of root font size for rem|em <-> px conversion. Default `16`. 260 * @type string[] $acceptable_units An array of font size units. Default ` [ 'rem', 'px', 'em' ]`;292 * @type string[] $acceptable_units An array of font size units. Default `array( 'rem', 'px', 'em' )`; 261 293 * } 262 294 * @return array|null An array consisting of `'value'` and `'unit'` properties on success. … … 264 296 */ 265 297 function wp_get_typography_value_and_unit( $raw_value, $options = array() ) { 298 if ( ! is_string( $raw_value ) && ! is_int( $raw_value ) && ! is_float( $raw_value ) ) { 299 _doing_it_wrong( 300 __FUNCTION__, 301 __( 'Raw size value must be a string, integer, or float.' ), 302 '6.1.0' 303 ); 304 return null; 305 } 306 266 307 if ( empty( $raw_value ) ) { 267 308 return null; 309 } 310 311 // Converts numbers to pixel values by default. 312 if ( is_numeric( $raw_value ) ) { 313 $raw_value = $raw_value . 'px'; 268 314 } 269 315 … … 289 335 $unit = $matches[2]; 290 336 291 // Default browser font size. Later, possibly could inject some JS to 292 // compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`. 337 /* 338 * Default browser font size. Later, possibly could inject some JS to 339 * compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`. 340 */ 293 341 if ( 'px' === $options['coerce_to'] && ( 'em' === $unit || 'rem' === $unit ) ) { 294 342 $value = $value * $options['root_size_value']; … … 324 372 * @type int $scale_factor A scale factor to determine how fast a font scales within boundaries. 325 373 * } 326 * @return string|null A font-size value using clamp() on success . Else,null.374 * @return string|null A font-size value using clamp() on success, otherwise null. 327 375 */ 328 376 function wp_get_computed_fluid_typography_value( $args = array() ) { … … 396 444 * Required. fontSizes preset value as seen in theme.json. 397 445 * 398 * @type string $name Name of the font size preset.399 * @type string $slug Kebab-caseunique identifier for the font size preset.400 * @type string $size CSS font-size value, including units whereapplicable.446 * @type string $name Name of the font size preset. 447 * @type string $slug Kebab-case, unique identifier for the font size preset. 448 * @type string|int|float $size CSS font-size value, including units if applicable. 401 449 * } 402 450 * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing. 403 * Default is `false`.404 * @return string Font-size value.451 * Default is false. 452 * @return string|null Font-size value or null if a size is not passed in $preset. 405 453 */ 406 454 function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) { 455 if ( ! isset( $preset['size'] ) ) { 456 return null; 457 } 458 459 /* 460 * Catches empty values and 0/'0'. 461 * Fluid calculations cannot be performed on 0. 462 */ 463 if ( empty( $preset['size'] ) ) { 464 return $preset['size']; 465 } 466 407 467 // Checks if fluid font sizes are activated. 408 468 $typography_settings = wp_get_global_settings( array( 'typography' ) );
Note: See TracChangeset
for help on using the changeset viewer.