58 * Do not use this constructor directly. Instead, use the |
57 * Do not use this constructor directly. Instead, use the |
59 * `WP_Block_Bindings_Registry::register` method or the `register_block_bindings_source` function. |
58 * `WP_Block_Bindings_Registry::register` method or the `register_block_bindings_source` function. |
60 * |
59 * |
61 * @since 6.5.0 |
60 * @since 6.5.0 |
62 * |
61 * |
63 * @param string $name The name of the source. |
62 * @param string $name The name of the source. |
64 * @param array $source_properties The properties of the source. |
63 * @param array $source_properties The properties of the source. |
65 */ |
64 */ |
66 public function __construct( string $name, array $source_properties ) { |
65 public function __construct( string $name, array $source_properties ) { |
67 $this->name = $name; |
66 $this->name = $name; |
68 foreach ( $source_properties as $property_name => $property_value ) { |
67 foreach ( $source_properties as $property_name => $property_value ) { |
69 $this->$property_name = $property_value; |
68 $this->$property_name = $property_value; |
70 } |
69 } |
71 } |
70 } |
72 |
71 |
73 /** |
72 /** |
74 * Retrieves the value from the source. |
73 * Calls the callback function specified in the `$get_value_callback` property |
|
74 * with the given arguments and returns the result. It can be modified with |
|
75 * `block_bindings_source_value` filter. |
75 * |
76 * |
76 * @since 6.5.0 |
77 * @since 6.5.0 |
|
78 * @since 6.7.0 `block_bindings_source_value` filter was added. |
77 * |
79 * |
78 * @param array $source_args Array containing source arguments used to look up the override value, i.e. {"key": "foo"}. |
80 * @param array $source_args Array containing source arguments used to look up the override value, i.e. {"key": "foo"}. |
79 * @param WP_Block $block_instance The block instance. |
81 * @param WP_Block $block_instance The block instance. |
80 * @param string $attribute_name The name of the target attribute. |
82 * @param string $attribute_name The name of the target attribute. |
81 * |
|
82 * @return mixed The value of the source. |
83 * @return mixed The value of the source. |
83 */ |
84 */ |
84 public function get_value( array $source_args, $block_instance, string $attribute_name ) { |
85 public function get_value( array $source_args, $block_instance, string $attribute_name ) { |
85 return call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) ); |
86 $value = call_user_func_array( $this->get_value_callback, array( $source_args, $block_instance, $attribute_name ) ); |
|
87 /** |
|
88 * Filters the output of a block bindings source. |
|
89 * |
|
90 * @since 6.7.0 |
|
91 * |
|
92 * @param mixed $value The computed value for the source. |
|
93 * @param string $name The name of the source. |
|
94 * @param array $source_args Array containing source arguments used to look up the override value, i.e. { "key": "foo" }. |
|
95 * @param WP_Block $block_instance The block instance. |
|
96 * @param string $attribute_name The name of an attribute. |
|
97 */ |
|
98 return apply_filters( 'block_bindings_source_value', $value, $this->name, $source_args, $block_instance, $attribute_name ); |
86 } |
99 } |
87 |
100 |
88 /** |
101 /** |
89 * Wakeup magic method. |
102 * Wakeup magic method. |
90 * |
103 * |