Block bindings: Adds a filter to customize the output of a block bindings source.
Introduces a filter to the `block_bindings_source_value` to allow developers to modify the value returned by any block binding source. Props snehapatil02, cbravobernal, gziolo, santosguillamot, bacoords, codersantosh. Fixes #61181. Built from https://develop.svn.wordpress.org/trunk@58972 git-svn-id: http://core.svn.wordpress.org/trunk@58368 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ec9fa01846
commit
b734476509
|
@ -2,7 +2,6 @@
|
||||||
/**
|
/**
|
||||||
* Block Bindings API: WP_Block_Bindings_Source class.
|
* Block Bindings API: WP_Block_Bindings_Source class.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @package WordPress
|
* @package WordPress
|
||||||
* @subpackage Block Bindings
|
* @subpackage Block Bindings
|
||||||
* @since 6.5.0
|
* @since 6.5.0
|
||||||
|
@ -60,8 +59,8 @@ final class WP_Block_Bindings_Source {
|
||||||
*
|
*
|
||||||
* @since 6.5.0
|
* @since 6.5.0
|
||||||
*
|
*
|
||||||
* @param string $name The name of the source.
|
* @param string $name The name of the source.
|
||||||
* @param array $source_properties The properties of the source.
|
* @param array $source_properties The properties of the source.
|
||||||
*/
|
*/
|
||||||
public function __construct( string $name, array $source_properties ) {
|
public function __construct( string $name, array $source_properties ) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
@ -71,18 +70,32 @@ final class WP_Block_Bindings_Source {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the value from the source.
|
* Calls the callback function specified in the `$get_value_callback` property
|
||||||
|
* with the given arguments and returns the result. It can be modified with
|
||||||
|
* `block_bindings_source_value` filter.
|
||||||
*
|
*
|
||||||
* @since 6.5.0
|
* @since 6.5.0
|
||||||
|
* @since 6.7.0 `block_bindings_source_value` filter was added.
|
||||||
*
|
*
|
||||||
* @param array $source_args Array containing source arguments used to look up the override value, i.e. {"key": "foo"}.
|
* @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 WP_Block $block_instance The block instance.
|
||||||
* @param string $attribute_name The name of the target attribute.
|
* @param string $attribute_name The name of the target attribute.
|
||||||
*
|
|
||||||
* @return mixed The value of the source.
|
* @return mixed The value of the source.
|
||||||
*/
|
*/
|
||||||
public function get_value( array $source_args, $block_instance, string $attribute_name ) {
|
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 ) );
|
$value = 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 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.7-alpha-58971';
|
$wp_version = '6.7-alpha-58972';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue