Make WordPress Core


Ignore:
Timestamp:
09/20/2022 03:14:54 PM (3 years ago)
Author:
gziolo
Message:

Editor: Sync changes from the Gutenberg plugin 14.1 release

Updated WordPress packages necessary for releasing WordPress 6.1 Beta 1:

  • @wordpress/a11y@3.17.1
    • @wordpress/annotations@2.17.2
    • @wordpress/api-fetch@6.14.1
    • @wordpress/autop@3.17.1
    • @wordpress/babel-plugin-import-jsx-pragma@4.0.1
    • @wordpress/babel-plugin-makepot@5.1.1
    • @wordpress/babel-preset-default@7.1.1
    • @wordpress/base-styles@4.8.1
    • @wordpress/blob@3.17.1
    • @wordpress/block-directory@3.15.2
    • @wordpress/block-editor@10.0.2
    • @wordpress/block-library@7.14.2
    • @wordpress/block-serialization-default-parser@4.17.1
    • @wordpress/block-serialization-spec-parser@4.17.1
    • @wordpress/blocks@11.16.2
    • @wordpress/browserslist-config@5.0.1
    • @wordpress/components@21.0.2
    • @wordpress/compose@5.15.2
    • @wordpress/core-data@5.0.2
    • @wordpress/create-block-tutorial-template@2.5.1
    • @wordpress/create-block@4.1.1
    • @wordpress/custom-templated-path-webpack-plugin@2.1.3
    • @wordpress/customize-widgets@3.14.2
    • @wordpress/data-controls@2.17.2
    • @wordpress/data@7.1.2
    • @wordpress/date@4.17.1
    • @wordpress/dependency-extraction-webpack-plugin@4.0.2
    • @wordpress/deprecated@3.17.1
    • @wordpress/docgen@1.26.1
    • @wordpress/dom-ready@3.17.1
    • @wordpress/dom@3.17.2
    • @wordpress/e2e-test-utils@8.1.1
    • @wordpress/e2e-tests@5.1.2
    • @wordpress/edit-post@6.14.2
    • @wordpress/edit-site@4.14.2
    • @wordpress/edit-widgets@4.14.2
    • @wordpress/editor@12.16.2
    • @wordpress/element@4.15.1
    • @wordpress/env@5.2.1
    • @wordpress/escape-html@2.17.1
    • @wordpress/eslint-plugin@13.1.1
    • @wordpress/format-library@3.15.2
    • @wordpress/hooks@3.17.1
    • @wordpress/html-entities@3.17.1
    • @wordpress/i18n@4.17.1
    • @wordpress/icons@9.8.1
    • @wordpress/interface@4.16.2
    • @wordpress/is-shallow-equal@4.17.1
    • @wordpress/jest-console@6.0.1
    • @wordpress/jest-preset-default@9.0.1
    • @wordpress/jest-puppeteer-axe@5.0.1
    • @wordpress/keyboard-shortcuts@3.15.2
    • @wordpress/keycodes@3.17.1
    • @wordpress/lazy-import@1.4.3
    • @wordpress/library-export-default-webpack-plugin@2.3.3
    • @wordpress/list-reusable-blocks@3.15.2
    • @wordpress/media-utils@4.8.1
    • @wordpress/notices@3.17.2
    • @wordpress/npm-package-json-lint-config@4.2.1
    • @wordpress/nux@5.15.2
    • @wordpress/plugins@4.15.2
    • @wordpress/postcss-plugins-preset@4.1.1
    • @wordpress/postcss-themes@5.0.1
    • @wordpress/preferences-persistence@1.9.1
    • @wordpress/preferences@2.9.2
    • @wordpress/prettier-config@2.0.1
    • @wordpress/primitives@3.15.1
    • @wordpress/priority-queue@2.17.2
    • @wordpress/project-management-automation@1.16.1
    • @wordpress/react-i18n@3.15.1
    • @wordpress/readable-js-assets-webpack-plugin@2.0.1
    • @wordpress/redux-routine@4.17.1
    • @wordpress/reusable-blocks@3.15.2
    • @wordpress/rich-text@5.15.2
    • @wordpress/scripts@24.1.2
    • @wordpress/server-side-render@3.15.2
    • @wordpress/shortcode@3.17.1
    • @wordpress/style-engine@1.0.1
    • @wordpress/stylelint-config@21.0.1
    • @wordpress/token-list@2.17.1
    • @wordpress/url@3.18.1
    • @wordpress/viewport@4.15.2
    • @wordpress/warning@2.17.1
    • @wordpress/widgets@2.15.2
    • @wordpress/wordcount@3.17.1

Props bernhard-reiter, cbravobernal, czapla, oandregal, isabel_brison, andrewserong, mciampini.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/post-featured-image.php

    r53157 r54257  
    2020    $post_ID = $block->context['postId'];
    2121
     22    $is_link        = isset( $attributes['isLink'] ) && $attributes['isLink'];
    2223    $size_slug      = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail';
    2324    $post_title     = trim( strip_tags( get_the_title( $post_ID ) ) );
    24     $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, array( 'alt' => $post_title ) );
     25    $attr           = get_block_core_post_featured_image_border_attributes( $attributes );
     26    $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes );
     27
     28    if ( $is_link ) {
     29        $attr['alt'] = $post_title;
     30    }
     31
     32    $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr );
    2533    if ( ! $featured_image ) {
    2634        return '';
    2735    }
    2836    $wrapper_attributes = get_block_wrapper_attributes();
    29     if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
    30         $featured_image = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $featured_image );
     37    if ( $is_link ) {
     38        $link_target    = $attributes['linkTarget'];
     39        $rel            = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
     40        $featured_image = sprintf(
     41            '<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>',
     42            get_the_permalink( $post_ID ),
     43            esc_attr( $link_target ),
     44            $rel,
     45            $featured_image,
     46            $overlay_markup
     47        );
     48    } else {
     49        $featured_image = $featured_image . $overlay_markup;
    3150    }
    3251
     
    3453    $has_height = ! empty( $attributes['height'] );
    3554    if ( ! $has_height && ! $has_width ) {
    36         return "<figure $wrapper_attributes>$featured_image</figure>";
     55        return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
    3756    }
    3857
     
    4968    }
    5069
    51     return "<figure $wrapper_attributes>$featured_image</figure>";
     70    return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
     71}
     72
     73/**
     74 * Generate markup for the HTML element that will be used for the overlay.
     75 *
     76 * @param array $attributes Block attributes.
     77 *
     78 * @return string HTML markup in string format.
     79 */
     80function get_block_core_post_featured_image_overlay_element_markup( $attributes ) {
     81    $has_dim_background  = isset( $attributes['dimRatio'] ) && $attributes['dimRatio'];
     82    $has_gradient        = isset( $attributes['gradient'] ) && $attributes['gradient'];
     83    $has_custom_gradient = isset( $attributes['customGradient'] ) && $attributes['customGradient'];
     84    $has_solid_overlay   = isset( $attributes['overlayColor'] ) && $attributes['overlayColor'];
     85    $has_custom_overlay  = isset( $attributes['customOverlayColor'] ) && $attributes['customOverlayColor'];
     86    $class_names         = array(
     87        'wp-block-post-featured-image__overlay',
     88    );
     89    $styles_properties   = array();
     90
     91    if ( ! $has_dim_background ) {
     92        return '';
     93    }
     94
     95    // Generate required classes for the element.
     96    if ( $has_dim_background ) {
     97        $class_names[] = 'has-background-dim';
     98        $class_names[] = "has-background-dim-{$attributes['dimRatio']}";
     99    }
     100
     101    if ( $has_solid_overlay ) {
     102        $class_names[] = "has-{$attributes['overlayColor']}-background-color";
     103    }
     104
     105    if ( $has_gradient || $has_custom_gradient ) {
     106        $class_names[] = 'has-background-gradient';
     107    }
     108
     109    if ( $has_gradient ) {
     110        $class_names[] = "has-{$attributes['gradient']}-gradient-background";
     111    }
     112
     113    // Generate required CSS properties and their values.
     114    if ( ! empty( $attributes['style']['border']['radius'] ) ) {
     115        $styles_properties['border-radius'] = $attributes['style']['border']['radius'];
     116    }
     117
     118    if ( ! empty( $attributes['style']['border']['width'] ) ) {
     119        $styles_properties['border-width'] = $attributes['style']['border']['width'];
     120    }
     121
     122    if ( $has_custom_gradient ) {
     123        $styles_properties['background-image'] = $attributes['customGradient'];
     124    }
     125
     126    if ( $has_custom_overlay ) {
     127        $styles_properties['background-color'] = $attributes['customOverlayColor'];
     128    }
     129
     130    $styles = '';
     131
     132    foreach ( $styles_properties as $style_attribute => $style_attribute_value ) {
     133        $styles .= "{$style_attribute}: $style_attribute_value; ";
     134    }
     135
     136    return sprintf(
     137        '<span class="%s" style="%s" aria-hidden="true"></span>',
     138        esc_attr( implode( ' ', $class_names ) ),
     139        esc_attr( trim( $styles ) )
     140    );
     141
     142}
     143
     144/**
     145 * Generates class names and styles to apply the border support styles for
     146 * the Post Featured Image block.
     147 *
     148 * @param array $attributes The block attributes.
     149 * @return array The border-related classnames and styles for the block.
     150 */
     151function get_block_core_post_featured_image_border_attributes( $attributes ) {
     152    $border_styles = array();
     153    $sides         = array( 'top', 'right', 'bottom', 'left' );
     154
     155    // Border radius.
     156    if ( isset( $attributes['style']['border']['radius'] ) ) {
     157        $border_styles['radius'] = $attributes['style']['border']['radius'];
     158    }
     159
     160    // Border style.
     161    if ( isset( $attributes['style']['border']['style'] ) ) {
     162        $border_styles['style'] = $attributes['style']['border']['style'];
     163    }
     164
     165    // Border width.
     166    if ( isset( $attributes['style']['border']['width'] ) ) {
     167        $border_styles['width'] = $attributes['style']['border']['width'];
     168    }
     169
     170    // Border color.
     171    $preset_color           = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null;
     172    $custom_color           = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null );
     173    $border_styles['color'] = $preset_color ? $preset_color : $custom_color;
     174
     175    // Individual border styles e.g. top, left etc.
     176    foreach ( $sides as $side ) {
     177        $border                 = _wp_array_get( $attributes, array( 'style', 'border', $side ), null );
     178        $border_styles[ $side ] = array(
     179            'color' => isset( $border['color'] ) ? $border['color'] : null,
     180            'style' => isset( $border['style'] ) ? $border['style'] : null,
     181            'width' => isset( $border['width'] ) ? $border['width'] : null,
     182        );
     183    }
     184
     185    $styles     = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
     186    $attributes = array();
     187    if ( ! empty( $styles['classnames'] ) ) {
     188        $attributes['class'] = $styles['classnames'];
     189    }
     190    if ( ! empty( $styles['css'] ) ) {
     191        $attributes['style'] = $styles['css'];
     192    }
     193    return $attributes;
    52194}
    53195
Note: See TracChangeset for help on using the changeset viewer.