Make WordPress Core


Ignore:
Timestamp:
09/03/2024 04:31:44 PM (7 months ago)
Author:
cbravobernal
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-bindings-source.php

    r58075 r58972  
    22/**
    33 * Block Bindings API: WP_Block_Bindings_Source class.
    4  *
    54 *
    65 * @package WordPress
     
    6160     * @since 6.5.0
    6261     *
    63      * @param string $name               The name of the source.
    64      * @param array  $source_properties  The properties of the source.
     62     * @param string $name              The name of the source.
     63     * @param array  $source_properties The properties of the source.
    6564     */
    6665    public function __construct( string $name, array $source_properties ) {
     
    7271
    7372    /**
    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.
    7576     *
    7677     * @since 6.5.0
     78     * @since 6.7.0 `block_bindings_source_value` filter was added.
    7779     *
    78      * @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.
    80      * @param string   $attribute_name  The name of the target attribute.
    81      *
     80     * @param array    $source_args    Array containing source arguments used to look up the override value, i.e. {"key": "foo"}.
     81     * @param WP_Block $block_instance The block instance.
     82     * @param string   $attribute_name The name of the target attribute.
    8283     * @return mixed The value of the source.
    8384     */
    8485    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 );
    8699    }
    87100
Note: See TracChangeset for help on using the changeset viewer.