Make WordPress Core


Ignore:
Timestamp:
10/17/2025 03:05:55 PM (12 months ago)
Author:
cbravobernal
Message:

Block Bindings: Use field instead of key in post-data source.

After the UI refactor, source args can contain anything, and using whatever fits better for each source is encouraged.
Instead of using a post-meta based key argument. post-data will use field as an argument, which fits better to post related use cases.

Props cbravobernal, bernhard-reiter.
Fixes #64112.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-bindings/post-data.php

    r60946 r60955  
    1515 *
    1616 * @param array    $source_args    Array containing arguments used to look up the source value.
    17  *                                 Example: array( "key" => "foo" ).
     17 *                                 Example: array( "field" => "foo" ).
    1818 * @param WP_Block $block_instance The block instance.
    1919 * @return mixed The value computed for the source.
    2020 */
    2121function _block_bindings_post_data_get_value( array $source_args, $block_instance ) {
    22         if ( empty( $source_args['key'] ) ) {
    23                 return null;
     22        if ( empty( $source_args['field'] ) ) {
     23                // Backward compatibility for when the source argument was called `key` in Gutenberg plugin.
     24                if ( empty( $source_args['key'] ) ) {
     25                        return null;
     26                }
     27                $field = $source_args['key'];
     28        } else {
     29                $field = $source_args['field'];
    2430        }
    2531
    … …  
    5460        }
    5561
    56         if ( 'date' === $source_args['key'] ) {
     62        if ( 'date' === $field ) {
    5763                return esc_attr( get_the_date( 'c', $post_id ) );
    5864        }
    5965
    60         if ( 'modified' === $source_args['key'] ) {
     66        if ( 'modified' === $field ) {
    6167                // Only return the modified date if it is later than the publishing date.
    6268                if ( get_the_modified_date( 'U', $post_id ) > get_the_date( 'U', $post_id ) ) {
Note: See TracChangeset for help on using the changeset viewer.