Make WordPress Core


Ignore:
Timestamp:
09/20/2024 01:53:52 AM (2 years ago)
Author:
noisysocks
Message:

Editor: Update packages for 6.7 Beta 1.

Syncs @wordpress/* packages to the wp-6.7 npm tag.

Fixes #61906.
Props peterwilsoncc, gziolo, kevin940726.

File:
1 edited

Legend:

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

    r58565 r59072  
    3030        }
    3131
     32        $has_media_on_right = isset( $attributes['mediaPosition'] ) && 'right' === $attributes['mediaPosition'];
     33        $image_fill         = isset( $attributes['imageFill'] ) && $attributes['imageFill'];
     34        $focal_point        = isset( $attributes['focalPoint'] ) ? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%' : '50% 50%';
     35        $unique_id          = 'wp-block-media-text__media-' . wp_unique_id();
     36
     37        $block_tag_processor = new WP_HTML_Tag_Processor( $content );
     38        $block_query         = array(
     39                'tag_name'   => 'div',
     40                'class_name' => 'wp-block-media-text',
     41        );
     42
     43        while ( $block_tag_processor->next_tag( $block_query ) ) {
     44                if ( $image_fill ) {
     45                        // The markup below does not work with the deprecated `is-image-fill` class.
     46                        $block_tag_processor->remove_class( 'is-image-fill' );
     47                        $block_tag_processor->add_class( 'is-image-fill-element' );
     48                }
     49        }
     50
     51        $content = $block_tag_processor->get_updated_html();
     52
    3253        $media_tag_processor   = new WP_HTML_Tag_Processor( $content );
    3354        $wrapping_figure_query = array(
    … …  
    3556                'class_name' => 'wp-block-media-text__media',
    3657        );
    37         $has_media_on_right    = isset( $attributes['mediaPosition'] ) && 'right' === $attributes['mediaPosition'];
    38         $image_fill            = isset( $attributes['imageFill'] ) && $attributes['imageFill'];
    39         $focal_point           = isset( $attributes['focalPoint'] ) ? round( $attributes['focalPoint']['x'] * 100 ) . '% ' . round( $attributes['focalPoint']['y'] * 100 ) . '%' : '50% 50%';
    40         $unique_id             = 'wp-block-media-text__media-' . wp_unique_id();
    4158
    4259        if ( $has_media_on_right ) {
    … …  
    4764                if ( $media_tag_processor->has_bookmark( 'last_figure' ) ) {
    4865                        $media_tag_processor->seek( 'last_figure' );
    49                         if ( $image_fill ) {
    50                                 $media_tag_processor->set_attribute( 'style', 'background-image:url(' . esc_url( $current_featured_image ) . ');background-position:' . $focal_point . ';' );
    51                         } else {
    52                                 // Insert a unique ID to identify the figure tag.
    53                                 $media_tag_processor->set_attribute( 'id', $unique_id );
    54                         }
     66                        // Insert a unique ID to identify the figure tag.
     67                        $media_tag_processor->set_attribute( 'id', $unique_id );
    5568                }
    5669        } else {
    5770                if ( $media_tag_processor->next_tag( $wrapping_figure_query ) ) {
    58                         if ( $image_fill ) {
    59                                 $media_tag_processor->set_attribute( 'style', 'background-image:url(' . esc_url( $current_featured_image ) . ');background-position:' . $focal_point . ';' );
    60                         } else {
    61                                 // Insert a unique ID to identify the figure tag.
    62                                 $media_tag_processor->set_attribute( 'id', $unique_id );
    63                         }
     71                        // Insert a unique ID to identify the figure tag.
     72                        $media_tag_processor->set_attribute( 'id', $unique_id );
    6473                }
    6574        }
    … …  
    6776        $content = $media_tag_processor->get_updated_html();
    6877
    69         // If the image is not set to fill, add the image tag inside the figure tag,
    70         // and update the image attributes in order to display the featured image.
    71         if ( ! $image_fill ) {
    72                 $media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full';
    73                 $image_tag       = '<img class="wp-block-media-text__featured_image">';
    74                 $content         = preg_replace(
    75                         '/(<figure\s+id="' . preg_quote( $unique_id, '/' ) . '"\s+class="wp-block-media-text__media"\s*>)/',
    76                         '$1' . $image_tag,
    77                         $content
    78                 );
     78        // Add the image tag inside the figure tag, and update the image attributes
     79        // in order to display the featured image.
     80        $media_size_slug = isset( $attributes['mediaSizeSlug'] ) ? $attributes['mediaSizeSlug'] : 'full';
     81        $image_tag       = '<img class="wp-block-media-text__featured_image">';
     82        $content         = preg_replace(
     83                '/(<figure\s+id="' . preg_quote( $unique_id, '/' ) . '"\s+class="wp-block-media-text__media"\s*>)/',
     84                '$1' . $image_tag,
     85                $content
     86        );
    7987
    80                 $image_tag_processor = new WP_HTML_Tag_Processor( $content );
     88        $image_tag_processor = new WP_HTML_Tag_Processor( $content );
     89        if ( $image_tag_processor->next_tag(
     90                array(
     91                        'tag_name' => 'figure',
     92                        'id'       => $unique_id,
     93                )
     94        ) ) {
     95                // The ID is only used to ensure that the correct figure tag is selected,
     96                // and can now be removed.
     97                $image_tag_processor->remove_attribute( 'id' );
    8198                if ( $image_tag_processor->next_tag(
    8299                        array(
    83                                 'tag_name' => 'figure',
    84                                 'id'       => $unique_id,
     100                                'tag_name'   => 'img',
     101                                'class_name' => 'wp-block-media-text__featured_image',
    85102                        )
    86103                ) ) {
    87                         // The ID is only used to ensure that the correct figure tag is selected,
    88                         // and can now be removed.
    89                         $image_tag_processor->remove_attribute( 'id' );
    90                         if ( $image_tag_processor->next_tag(
    91                                 array(
    92                                         'tag_name'   => 'img',
    93                                         'class_name' => 'wp-block-media-text__featured_image',
    94                                 )
    95                         ) ) {
    96                                 $image_tag_processor->set_attribute( 'src', esc_url( $current_featured_image ) );
    97                                 $image_tag_processor->set_attribute( 'class', 'wp-image-' . get_post_thumbnail_id() . ' size-' . $media_size_slug );
    98                                 $image_tag_processor->set_attribute( 'alt', trim( strip_tags( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) ) );
     104                        $image_tag_processor->set_attribute( 'src', esc_url( $current_featured_image ) );
     105                        $image_tag_processor->set_attribute( 'class', 'wp-image-' . get_post_thumbnail_id() . ' size-' . $media_size_slug );
     106                        $image_tag_processor->set_attribute( 'alt', trim( strip_tags( get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ) ) ) );
     107                        if ( $image_fill ) {
     108                                $image_tag_processor->set_attribute( 'style', 'object-position:' . $focal_point . ';' );
     109                        }
    99110
    100                                 $content = $image_tag_processor->get_updated_html();
    101                         }
     111                        $content = $image_tag_processor->get_updated_html();
    102112                }
    103113        }
Note: See TracChangeset for help on using the changeset viewer.