Changeset 49226 for trunk/src/wp-includes/block-supports/typography.php
- Timestamp:
- 10/20/2020 01:33:02 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/typography.php
r49135 r49226 9 9 * Registers the style and typography block attributes for block types that support it. 10 10 * 11 * @access private 12 * 11 13 * @param WP_Block_Type $block_type Block Type. 12 14 */ … … 15 17 if ( property_exists( $block_type, 'supports' ) ) { 16 18 $has_font_size_support = wp_array_get( $block_type->supports, array( '__experimentalFontSize' ), false ); 17 }18 19 $has_font_style_support = false;20 if ( property_exists( $block_type, 'supports' ) ) {21 $has_font_style_support = wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );22 19 } 23 20 … … 31 28 } 32 29 33 if ( ( $has_font_size_support || $has_ font_style_support || $has_line_height_support ) && ! array_key_exists( 'style', $block_type->attributes ) ) {30 if ( ( $has_font_size_support || $has_line_height_support ) && ! array_key_exists( 'style', $block_type->attributes ) ) { 34 31 $block_type->attributes['style'] = array( 35 32 'type' => 'object', … … 48 45 * This will be applied to the block markup in the front-end. 49 46 * 50 * @param array $attributes Comprehensive list of attributes to be applied. 47 * @access private 48 * 49 * @param WP_Block_Type $block_type Block type. 51 50 * @param array $block_attributes Block attributes. 52 * @param WP_Block_Type $block_type Block type.53 51 * 54 52 * @return array Font size CSS classes and inline styles. 55 53 */ 56 function wp_apply_typography_support( $ attributes, $block_attributes, $block_type) {54 function wp_apply_typography_support( $block_type, $block_attributes ) { 57 55 $has_font_size_support = false; 56 $classes = array(); 57 $styles = array(); 58 58 if ( property_exists( $block_type, 'supports' ) ) { 59 $has_font_size_support = wp_array_get( $block_type->supports, array( '__experimentalFontSize' ), false ); 60 } 61 62 $has_font_style_support = false; 63 if ( property_exists( $block_type, 'supports' ) ) { 64 $has_font_style_support = wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false ); 59 $has_font_size_support = wp_array_get( $block_type->supports, array( 'fontSize' ), false ); 65 60 } 66 61 67 62 $has_line_height_support = false; 68 63 if ( property_exists( $block_type, 'supports' ) ) { 69 $has_line_height_support = wp_array_get( $block_type->supports, array( ' __experimentalLineHeight' ), false );64 $has_line_height_support = wp_array_get( $block_type->supports, array( 'lineHeight' ), false ); 70 65 } 71 66 … … 77 72 // Apply required class or style. 78 73 if ( $has_named_font_size ) { 79 $ attributes['css_classes'][] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] );74 $classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] ); 80 75 } elseif ( $has_custom_font_size ) { 81 $attributes['inline_styles'][] = sprintf( 'font-size: %spx;', $block_attributes['style']['typography']['fontSize'] ); 82 } 83 } 84 85 // Font Styles e.g. bold, italic, underline & strikethrough. 86 if ( $has_font_style_support ) { 87 $has_font_styles = isset( $block_attributes['style']['typography']['fontStyles'] ); 88 89 // Apply required CSS classes. 90 if ( $has_font_styles ) { 91 $attributes['css_classes'][] = 'has-font-style'; 92 93 // CSS class names chosen to be more explicit than generic `has-<something>-font-style`. 94 $font_style_classes = array( 95 'bold' => 'has-bold-font-weight', 96 'italic' => 'has-italic-font-style', 97 'underline' => 'has-underline-text-decoration', 98 'strikethrough' => 'has-strikethrough-text-decoration', 99 ); 100 101 $style_selections = $block_attributes['style']['typography']['fontStyles']; 102 103 foreach ( $style_selections as $style => $turned_on ) { 104 if ( $turned_on ) { 105 $attributes['css_classes'][] = $font_style_classes[ $style ]; 106 } 107 } 76 $styles[] = sprintf( 'font-size: %spx;', $block_attributes['style']['typography']['fontSize'] ); 108 77 } 109 78 } … … 114 83 // Add the style (no classes for line-height). 115 84 if ( $has_line_height ) { 116 $ attributes['inline_styles'][] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] );85 $styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] ); 117 86 } 87 } 88 89 $attributes = array(); 90 if ( ! empty( $classes ) ) { 91 $attributes['class'] = implode( ' ', $classes ); 92 } 93 if ( ! empty( $styles ) ) { 94 $attributes['style'] = implode( ' ', $styles ); 118 95 } 119 96 120 97 return $attributes; 121 98 } 99 100 WP_Block_Supports::get_instance()->register( 101 'typography', 102 array( 103 'register_attribute' => 'wp_register_typography_support', 104 'apply' => 'wp_apply_typography_support', 105 ) 106 );
Note: See TracChangeset
for help on using the changeset viewer.