equal
deleted
inserted
replaced
516 * @since 6.1.1 Adjusted rules for min and max font sizes. |
516 * @since 6.1.1 Adjusted rules for min and max font sizes. |
517 * @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support. |
517 * @since 6.2.0 Added 'settings.typography.fluid.minFontSize' support. |
518 * @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale. |
518 * @since 6.3.0 Using layout.wideSize as max viewport width, and logarithmic scale factor to calculate minimum font scale. |
519 * @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema. |
519 * @since 6.4.0 Added configurable min and max viewport width values to the typography.fluid theme.json schema. |
520 * @since 6.6.0 Deprecated bool argument $should_use_fluid_typography. |
520 * @since 6.6.0 Deprecated bool argument $should_use_fluid_typography. |
|
521 * @since 6.7.0 Font size presets can enable fluid typography individually, even if it’s disabled globally. |
521 * |
522 * |
522 * @param array $preset { |
523 * @param array $preset { |
523 * Required. fontSizes preset value as seen in theme.json. |
524 * Required. fontSizes preset value as seen in theme.json. |
524 * |
525 * |
525 * @type string $name Name of the font size preset. |
526 * @type string $name Name of the font size preset. |
536 if ( ! isset( $preset['size'] ) ) { |
537 if ( ! isset( $preset['size'] ) ) { |
537 return null; |
538 return null; |
538 } |
539 } |
539 |
540 |
540 /* |
541 /* |
541 * Catches empty values and 0/'0'. |
542 * Catches falsy values and 0/'0'. Fluid calculations cannot be performed on `0`. |
542 * Fluid calculations cannot be performed on 0. |
543 * Also returns early when a preset font size explicitly disables fluid typography with `false`. |
543 */ |
544 */ |
544 if ( empty( $preset['size'] ) ) { |
545 $fluid_font_size_settings = $preset['fluid'] ?? null; |
|
546 if ( false === $fluid_font_size_settings || empty( $preset['size'] ) ) { |
545 return $preset['size']; |
547 return $preset['size']; |
546 } |
548 } |
547 |
549 |
548 /* |
550 /* |
549 * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`). |
551 * As a boolean (deprecated since 6.6), $settings acts as an override to switch fluid typography "on" (`true`) or "off" (`false`). |
562 $settings = wp_parse_args( |
564 $settings = wp_parse_args( |
563 $settings, |
565 $settings, |
564 $global_settings |
566 $global_settings |
565 ); |
567 ); |
566 |
568 |
567 $typography_settings = isset( $settings['typography'] ) ? $settings['typography'] : array(); |
569 $typography_settings = $settings['typography'] ?? array(); |
568 $should_use_fluid_typography = ! empty( $typography_settings['fluid'] ); |
570 |
569 |
571 /* |
570 if ( ! $should_use_fluid_typography ) { |
572 * Return early when fluid typography is disabled in the settings, and there |
|
573 * are no local settings to enable it for the individual preset. |
|
574 * |
|
575 * If this condition isn't met, either the settings or individual preset settings |
|
576 * have enabled fluid typography. |
|
577 */ |
|
578 if ( empty( $typography_settings['fluid'] ) && empty( $fluid_font_size_settings ) ) { |
571 return $preset['size']; |
579 return $preset['size']; |
572 } |
580 } |
573 |
581 |
574 // $typography_settings['fluid'] can be a bool or an array. Normalize to array. |
582 $fluid_settings = isset( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array(); |
575 $fluid_settings = is_array( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array(); |
|
576 $layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array(); |
583 $layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array(); |
577 |
584 |
578 // Defaults. |
585 // Defaults. |
579 $default_maximum_viewport_width = '1600px'; |
586 $default_maximum_viewport_width = '1600px'; |
580 $default_minimum_viewport_width = '320px'; |
587 $default_minimum_viewport_width = '320px'; |
589 if ( isset( $fluid_settings['maxViewportWidth'] ) ) { |
596 if ( isset( $fluid_settings['maxViewportWidth'] ) ) { |
590 $maximum_viewport_width = $fluid_settings['maxViewportWidth']; |
597 $maximum_viewport_width = $fluid_settings['maxViewportWidth']; |
591 } |
598 } |
592 $has_min_font_size = isset( $fluid_settings['minFontSize'] ) && ! empty( wp_get_typography_value_and_unit( $fluid_settings['minFontSize'] ) ); |
599 $has_min_font_size = isset( $fluid_settings['minFontSize'] ) && ! empty( wp_get_typography_value_and_unit( $fluid_settings['minFontSize'] ) ); |
593 $minimum_font_size_limit = $has_min_font_size ? $fluid_settings['minFontSize'] : $default_minimum_font_size_limit; |
600 $minimum_font_size_limit = $has_min_font_size ? $fluid_settings['minFontSize'] : $default_minimum_font_size_limit; |
594 |
|
595 // Font sizes. |
|
596 $fluid_font_size_settings = isset( $preset['fluid'] ) ? $preset['fluid'] : null; |
|
597 |
|
598 // A font size has explicitly bypassed fluid calculations. |
|
599 if ( false === $fluid_font_size_settings ) { |
|
600 return $preset['size']; |
|
601 } |
|
602 |
601 |
603 // Try to grab explicit min and max fluid font sizes. |
602 // Try to grab explicit min and max fluid font sizes. |
604 $minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null; |
603 $minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null; |
605 $maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null; |
604 $maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null; |
606 |
605 |