Make WordPress Core


Ignore:
Timestamp:
10/21/2025 07:11:53 AM (3 months ago)
Author:
ellatrix
Message:

Editor: update packages.

Updates the packages to match Gutenberg version 21.9.0 RC2.

Also updates the sync script to work with the new package-lock.json format.
Some reusable block tests were adjusted to work with more render arguments.
Added core-data to the ignore list for verify:source-maps because Yjs has been bundled by accident. To be removed in a follow-up. See https://core.trac.wordpress.org/ticket/64120. See https://github.com/WordPress/gutenberg/pull/72503.

See: https://github.com/WordPress/wordpress-develop/pull/10355.
See: https://core.trac.wordpress.org/ticket/64117.

Props ellatrix, dmsnell.
Fixes #64117.

File:
1 edited

Legend:

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

    r59072 r61009  
    1010 *
    1111 * @since 5.8.0
     12 * @since 6.9.0 Added `datetime` attribute and Block Bindings support.
    1213 *
    1314 * @param array    $attributes Block attributes.
     
    1718 */
    1819function render_block_core_post_date( $attributes, $content, $block ) {
    19     if ( ! isset( $block->context['postId'] ) ) {
     20    $classes = array();
     21
     22    if (
     23        ! isset( $attributes['datetime'] ) && ! (
     24            isset( $attributes['metadata']['bindings']['datetime']['source'] ) &&
     25            isset( $attributes['metadata']['bindings']['datetime']['args'] )
     26        )
     27    ) {
     28        /*
     29         * This is the legacy version of the block that didn't have the `datetime` attribute.
     30         * This branch needs to be kept for backward compatibility.
     31         */
     32        $source = get_block_bindings_source( 'core/post-data' );
     33        if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
     34            $source_args = array(
     35                'field' => 'modified',
     36            );
     37        } else {
     38            $source_args = array(
     39                'field' => 'date',
     40            );
     41        }
     42        $attributes['datetime'] = $source->get_value( $source_args, $block, 'datetime' );
     43    }
     44
     45    if ( isset( $source_args['field'] ) && 'modified' === $source_args['field'] ) {
     46        $classes[] = 'wp-block-post-date__modified-date';
     47    }
     48
     49    if ( empty( $attributes['datetime'] ) ) {
     50        // If the `datetime` attribute is set but empty, it could be because Block Bindings
     51        // set it that way. This can happen e.g. if the block is bound to the
     52        // post's last modified date, and the latter lies before the publish date.
     53        // (See https://github.com/WordPress/gutenberg/pull/46839 where this logic was originally
     54        // implemented.)
     55        // In this case, we have to respect and return the empty value.
    2056        return '';
    2157    }
    2258
    23     $post_ID = $block->context['postId'];
     59    $unformatted_date = $attributes['datetime'];
     60    $post_timestamp   = strtotime( $unformatted_date );
    2461
    2562    if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
    26         $post_timestamp = get_post_timestamp( $post_ID );
    2763        if ( $post_timestamp > time() ) {
    2864            // translators: %s: human-readable time difference.
     
    3369        }
    3470    } else {
    35         $formatted_date = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
     71        $format         = empty( $attributes['format'] ) ? get_option( 'date_format' ) : $attributes['format'];
     72        $formatted_date = wp_date( $format, $post_timestamp );
    3673    }
    37     $unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
    38     $classes          = array();
    3974
    4075    if ( isset( $attributes['textAlign'] ) ) {
     
    4580    }
    4681
    47     /*
    48      * If the "Display last modified date" setting is enabled,
    49      * only display the modified date if it is later than the publishing date.
    50      */
    51     if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
    52         if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {
    53             if ( isset( $attributes['format'] ) && 'human-diff' === $attributes['format'] ) {
    54                 // translators: %s: human-readable time difference.
    55                 $formatted_date = sprintf( __( '%s ago' ), human_time_diff( get_post_timestamp( $post_ID, 'modified' ) ) );
    56             } else {
    57                 $formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
    58             }
    59             $unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
    60             $classes[]        = 'wp-block-post-date__modified-date';
    61         } else {
    62             return '';
    63         }
    64     }
    65 
    6682    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
    6783
    68     if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
    69         $formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
     84    if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $block->context['postId'] ) ) {
     85        $formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $block->context['postId'] ), $formatted_date );
    7086    }
    7187
Note: See TracChangeset for help on using the changeset viewer.