Make WordPress Core


Ignore:
Timestamp:
06/27/2023 02:20:18 PM (3 years ago)
Author:
Bernhard Reiter
Message:

Editor: update Wordpress npm packages.

Updates the wordpress npm packages and their dependencies to the latest versions, as well as auto-updates to relevant core PHP files.

Props youknowriad, joemcgill, spacedmonkey, ramonopoly, peterwilsoncc, bernhard-reiter, tyxla, dmsnell.
Fixes #58623.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/avatar.php

    r55246 r56065  
    1717    $size               = isset( $attributes['size'] ) ? $attributes['size'] : 96;
    1818    $wrapper_attributes = get_block_wrapper_attributes();
     19    $border_attributes  = get_block_core_avatar_border_attributes( $attributes );
    1920
    20     $image_styles = array();
     21    // Class gets passed through `esc_attr` via `get_avatar`.
     22    $image_classes = ! empty( $border_attributes['class'] )
     23        ? "wp-block-avatar__image {$border_attributes['class']}"
     24        : 'wp-block-avatar__image';
    2125
    22     // Add border width styles.
    23     $has_border_width = ! empty( $attributes['style']['border']['width'] );
    24 
    25     if ( $has_border_width ) {
    26         $border_width   = $attributes['style']['border']['width'];
    27         $image_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
    28     }
    29 
    30     // Add border radius styles.
    31     $has_border_radius = ! empty( $attributes['style']['border']['radius'] );
    32 
    33     if ( $has_border_radius ) {
    34         $border_radius = $attributes['style']['border']['radius'];
    35 
    36         if ( is_array( $border_radius ) ) {
    37             // Apply styles for individual corner border radii.
    38             foreach ( $border_radius as $key => $value ) {
    39                 if ( null !== $value ) {
    40                     $name = _wp_to_kebab_case( $key );
    41                     // Add shared styles for individual border radii.
    42                     $border_style   = sprintf(
    43                         'border-%s-radius: %s;',
    44                         esc_attr( $name ),
    45                         esc_attr( $value )
    46                     );
    47                     $image_styles[] = $border_style;
    48                 }
    49             }
    50         } else {
    51             $border_style   = sprintf( 'border-radius: %s;', esc_attr( $border_radius ) );
    52             $image_styles[] = $border_style;
    53         }
    54     }
    55 
    56     // Add border color styles.
    57     $has_border_color = ! empty( $attributes['style']['border']['color'] );
    58 
    59     if ( $has_border_color ) {
    60         $border_color   = $attributes['style']['border']['color'];
    61         $image_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
    62     }
    63 
    64     // Add border style (solid, dashed, dotted ).
    65     $has_border_style = ! empty( $attributes['style']['border']['style'] );
    66 
    67     if ( $has_border_style ) {
    68         $border_style   = $attributes['style']['border']['style'];
    69         $image_styles[] = sprintf( 'border-style: %s;', esc_attr( $border_style ) );
    70     }
    71 
    72     // Add border classes to the avatar image for both custom colors and palette colors.
    73     $image_classes = '';
    74     if ( $has_border_color || isset( $attributes['borderColor'] ) ) {
    75         $image_classes .= 'has-border-color';
    76     }
    77     if ( isset( $attributes['borderColor'] ) ) {
    78         $image_classes .= ' has-' . $attributes['borderColor'] . '-border-color';
    79     }
     26    // Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`.
     27    // The style engine does pass the border styles through
     28    // `safecss_filter_attr` however.
     29    $image_styles = ! empty( $border_attributes['style'] )
     30        ? sprintf( ' style="%s"', esc_attr( $border_attributes['style'] ) )
     31        : '';
    8032
    8133    if ( ! isset( $block->context['commentId'] ) ) {
     
    9042            $alt,
    9143            array(
    92                 'extra_attr' => isset( $image_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $image_styles ) ) ) : '',
    93                 'class'      => "wp-block-avatar__image $image_classes ",
     44                'extra_attr' => $image_styles,
     45                'class'      => $image_classes,
    9446            )
    9547        );
     
    11769        $alt,
    11870        array(
    119             'extra_attr' => isset( $image_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $image_styles ) ) ) : '',
    120             'class'      => "wp-block-avatar__image $image_classes",
     71            'extra_attr' => $image_styles,
     72            'class'      => $image_classes,
    12173        )
    12274    );
     
    13486
    13587/**
     88 * Generates class names and styles to apply the border support styles for
     89 * the Avatar block.
     90 *
     91 * @param array $attributes The block attributes.
     92 * @return array The border-related classnames and styles for the block.
     93 */
     94function get_block_core_avatar_border_attributes( $attributes ) {
     95    $border_styles = array();
     96    $sides         = array( 'top', 'right', 'bottom', 'left' );
     97
     98    // Border radius.
     99    if ( isset( $attributes['style']['border']['radius'] ) ) {
     100        $border_styles['radius'] = $attributes['style']['border']['radius'];
     101    }
     102
     103    // Border style.
     104    if ( isset( $attributes['style']['border']['style'] ) ) {
     105        $border_styles['style'] = $attributes['style']['border']['style'];
     106    }
     107
     108    // Border width.
     109    if ( isset( $attributes['style']['border']['width'] ) ) {
     110        $border_styles['width'] = $attributes['style']['border']['width'];
     111    }
     112
     113    // Border color.
     114    $preset_color           = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
     115    $custom_color           = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null );
     116    $border_styles['color'] = $preset_color ? $preset_color : $custom_color;
     117
     118    // Individual border styles e.g. top, left etc.
     119    foreach ( $sides as $side ) {
     120        $border                 = _wp_array_get( $attributes, array( 'style', 'border', $side ), null );
     121        $border_styles[ $side ] = array(
     122            'color' => isset( $border['color'] ) ? $border['color'] : null,
     123            'style' => isset( $border['style'] ) ? $border['style'] : null,
     124            'width' => isset( $border['width'] ) ? $border['width'] : null,
     125        );
     126    }
     127
     128    $styles     = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
     129    $attributes = array();
     130    if ( ! empty( $styles['classnames'] ) ) {
     131        $attributes['class'] = $styles['classnames'];
     132    }
     133    if ( ! empty( $styles['css'] ) ) {
     134        $attributes['style'] = $styles['css'];
     135    }
     136    return $attributes;
     137}
     138
     139/**
    136140 * Registers the `core/avatar` block on the server.
    137141 */
Note: See TracChangeset for help on using the changeset viewer.