WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/20/2020 01:33:02 PM (6 months ago)
Author:
youknowriad
Message:

Block Editor: Update the WordPress Packages to the latest version.

This includes the packages that match the Gutenberg 9.2 Release.
It is going to be the last block-editor features update for WordPress 5.6.
It also updates the block-supports code base to the latest APIs.

Props isabel_brison, noisysocks, desrosj.
Fixes #51570.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/typography.php

    r49135 r49226  
    99 * Registers the style and typography block attributes for block types that support it.
    1010 *
     11 * @access private
     12 *
    1113 * @param WP_Block_Type $block_type Block Type.
    1214 */
     
    1517    if ( property_exists( $block_type, 'supports' ) ) {
    1618        $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 );
    2219    }
    2320
     
    3128    }
    3229
    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 ) ) {
    3431        $block_type->attributes['style'] = array(
    3532            'type' => 'object',
     
    4845 * This will be applied to the block markup in the front-end.
    4946 *
    50  * @param  array         $attributes       Comprehensive list of attributes to be applied.
     47 * @access private
     48 *
     49 * @param  WP_Block_Type $block_type       Block type.
    5150 * @param  array         $block_attributes Block attributes.
    52  * @param  WP_Block_Type $block_type       Block type.
    5351 *
    5452 * @return array Font size CSS classes and inline styles.
    5553 */
    56 function wp_apply_typography_support( $attributes, $block_attributes, $block_type ) {
     54function wp_apply_typography_support( $block_type, $block_attributes ) {
    5755    $has_font_size_support = false;
     56    $classes               = array();
     57    $styles                = array();
    5858    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 );
    6560    }
    6661
    6762    $has_line_height_support = false;
    6863    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 );
    7065    }
    7166
     
    7772        // Apply required class or style.
    7873        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'] );
    8075        } 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'] );
    10877        }
    10978    }
     
    11483        // Add the style (no classes for line-height).
    11584        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'] );
    11786        }
     87    }
     88
     89    $attributes = array();
     90    if ( ! empty( $classes ) ) {
     91        $attributes['class'] = implode( ' ', $classes );
     92    }
     93    if ( ! empty( $styles ) ) {
     94        $attributes['style'] = implode( ' ', $styles );
    11895    }
    11996
    12097    return $attributes;
    12198}
     99
     100WP_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.