Make WordPress Core


Ignore:
Timestamp:
07/09/2024 01:43:14 PM (17 months ago)
Author:
ellatrix
Message:

Editor: Update packages for 6.6 RC 3.

Fixes #61603.
Fixes https://github.com/WordPress/wordpress-develop/pull/6998.
See https://make.wordpress.org/core/handbook/about/release-cycle/block-editor-release-process-for-major-releases/#package-updates-and-core-patches.

Props ellatrix, youknowriad.

File:
1 edited

Legend:

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

    r58275 r58693  
    2929    }
    3030
     31    $has_id_binding = isset( $attributes['metadata']['bindings']['id'] ) && isset( $attributes['id'] );
     32
     33    // Ensure the `wp-image-id` classname on the image block supports block bindings.
     34    if ( $has_id_binding ) {
     35        // If there's a mismatch with the 'wp-image-' class and the actual id, the id was
     36        // probably overridden by block bindings. Update it to the correct value.
     37        // See https://github.com/WordPress/gutenberg/issues/62886 for why this is needed.
     38        $id                       = $attributes['id'];
     39        $image_classnames         = $p->get_attribute( 'class' );
     40        $class_with_binding_value = "wp-image-$id";
     41        if ( is_string( $image_classnames ) && ! str_contains( $image_classnames, $class_with_binding_value ) ) {
     42            $image_classnames = preg_replace( '/wp-image-(\d+)/', $class_with_binding_value, $image_classnames );
     43            $p->set_attribute( 'class', $image_classnames );
     44        }
     45    }
     46
     47    // For backwards compatibility, the data-id html attribute is only set for
     48    // image blocks nested in a gallery. Detect if the image is in a gallery by
     49    // checking the data-id attribute.
     50    // See the `block_core_gallery_data_id_backcompatibility` function.
    3151    if ( isset( $attributes['data-id'] ) ) {
    32         // Adds the data-id="$id" attribute to the img element to provide backwards
    33         // compatibility for the Gallery Block, which now wraps Image Blocks within
    34         // innerBlocks. The data-id attribute is added in a core/gallery
    35         // `render_block_data` hook.
    36         $p->set_attribute( 'data-id', $attributes['data-id'] );
     52        // If there's a binding for the `id`, the `id` attribute is used for the
     53        // value, since `data-id` does not support block bindings.
     54        // Else the `data-id` is used for backwards compatibility, since
     55        // third parties may be filtering its value.
     56        $data_id = $has_id_binding ? $attributes['id'] : $attributes['data-id'];
     57        $p->set_attribute( 'data-id', $data_id );
    3758    }
    3859
Note: See TracChangeset for help on using the changeset viewer.