Skip to content

Commit

Permalink
Incorporate PHP changes from WordPress/gutenberg#58337
Browse files Browse the repository at this point in the history
  • Loading branch information
michalczaplinski committed Jan 30, 2024
1 parent 2a20dee commit 2b4cf33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/wp-includes/block-bindings/sources/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @package WordPress
*/
function post_meta_source_callback( $source_attrs ) {
if ( ! isset( $source_attrs['key'] ) ) {
return null;
}

// Use the postId attribute if available
if ( isset( $source_attrs['postId'] ) ) {
$post_id = $source_attrs['postId'];
Expand All @@ -21,7 +25,7 @@ function post_meta_source_callback( $source_attrs ) {
return null;
}

return get_post_meta( $post_id, $source_attrs['value'], true );
return get_post_meta( $post_id, $source_attrs['key'], true );
}

register_block_bindings_source(
Expand Down
20 changes: 8 additions & 12 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,12 @@ public function __get( $name ) {
* "metadata": {
* "bindings": {
* "title": {
* "source": {
* "name": "post_meta",
* "attributes": { "value": "text_custom_field" }
* }
* "source": "post_meta",
* "args": { "key": "text_custom_field" }
* },
* "url": {
* "source": {
* "name": "post_meta",
* "attributes": { "value": "url_custom_field" }
* }
* "source": "post_meta",
* "args": { "key": "url_custom_field" }
* }
* }
* }
Expand Down Expand Up @@ -261,16 +257,16 @@ private function process_block_bindings( $block_content ) {
continue;
}
// If no source is provided, or that source is not registered, process next attribute.
if ( ! isset( $binding_source['source'] ) || ! isset( $binding_source['source']['name'] ) || ! isset( $block_bindings_sources[ $binding_source['source']['name'] ] ) ) {
if ( ! isset( $binding_source['source'] ) || ! is_string( $binding_source['source'] ) || ! isset( $block_bindings_sources[ $binding_source['source'] ] ) ) {
continue;
}

$source_callback = $block_bindings_sources[ $binding_source['source']['name'] ]['get_value_callback'];
$source_callback = $block_bindings_sources[ $binding_source['source'] ]['get_value_callback'];
// Get the value based on the source.
if ( ! isset( $binding_source['source']['attributes'] ) ) {
if ( ! isset( $binding_source['source']['args'] ) ) {
$source_args = array();
} else {
$source_args = $binding_source['source']['attributes'];
$source_args = $binding_source['source']['args'];
}
$source_value = $source_callback( $source_args, $this, $binding_attribute );
// If the value is null, process next attribute.
Expand Down

0 comments on commit 2b4cf33

Please sign in to comment.