Skip to content

Commit 9870028

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60955 602fd350-edb4-49c9-b593-d223f7449a82
1 parent aa5fdef commit 9870028

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/wp-includes/block-bindings/post-data.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
* @access private
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
*/
2121
function _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

2632
/*
@@ -53,11 +59,11 @@ function _block_bindings_post_data_get_value( array $source_args, $block_instanc
5359
return null;
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 ) ) {
6369
return esc_attr( get_the_modified_date( 'c', $post_id ) );

0 commit comments

Comments
 (0)