Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block bindings: Adds a filter to customize the output of a block bindings source. #6839

Closed
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/wp-includes/class-wp-block-bindings-source.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Block Bindings API: WP_Block_Bindings_Source class.
*
*
* @package WordPress
* @subpackage Block Bindings
* @since 6.5.0
Expand Down Expand Up @@ -75,14 +74,25 @@ public function __construct( string $name, array $source_properties ) {
*
* @since 6.5.0
cbravobernal marked this conversation as resolved.
Show resolved Hide resolved
cbravobernal marked this conversation as resolved.
Show resolved Hide resolved
*
* This function calls the callback function specified in the `$get_value_callback` property
* with the given arguments and returns the result. It then applies the filter
* `block_bindings_source_value` to the value before returning it.
*
* @param array $source_args Array containing source arguments used to look up the override value, i.e. {"key": "foo"}.
* @param WP_Block $block_instance The block instance.
* @param string $attribute_name The name of the target attribute.
*
* @return mixed The value of the source.
*/
public function get_value( array $source_args, $block_instance, string $attribute_name ) {
return call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) );
/**
* Filters the output of a block bindings source.
*
* @since 6.7.0
*
* @param mixed $value Value returned by `get_value_callback` after applying the filter.
*/
$value = call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) );
return apply_filters( 'block_bindings_source_value', $value, $this->name, $source_args, $block_instance, $attribute_name );
gziolo marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still needs some further refinements, so it gets correctly recognized by the parser that generates the documentation for all filters:

Suggested change
/**
* Filters the output of a block bindings source.
*
* @since 6.7.0
*
* @param mixed $value Value returned by `get_value_callback` after applying the filter.
*/
$value = call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) );
return apply_filters( 'block_bindings_source_value', $value, $this->name, $source_args, $block_instance, $attribute_name );
$value = call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) );
/**
* Filters the value of a block bindings source.
*
* @since 6.7.0
*
* @param mixed $value The computed value for the source.
* @param string $name The name of the source.
* @param array $source_args Array containing source arguments used to look up the override value, i.e. { "key": "foo" }.
* @param WP_Block $block_instance The block instance.
* @param string $attribute_name The name of an attribute.
*/
return apply_filters( 'block_bindings_source_value', $value, $this->name, $source_args, $block_instance, $attribute_name );

}

/**
Expand Down
Loading