-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Bindings: Update bindings registry with latest changes (#58843)
* Update `WP_Block_Bindings_Registry` * Update `blocks.php` * Add `WP_Block_Bindings_Source` class * Update methods comments Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org>
- Loading branch information
1 parent
e7765a0
commit 7fde6a8
Showing
5 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
lib/compat/wordpress-6.5/block-bindings/class-wp-block-bindings-source.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Block Bindings API: WP_Block_Bindings_Source class. | ||
* | ||
* | ||
* @package WordPress | ||
* @subpackage Block Bindings | ||
* @since 6.5.0 | ||
*/ | ||
|
||
/** | ||
* Class representing block bindings source. | ||
* | ||
* This class is designed for internal use by the Block Bindings registry. | ||
* | ||
* @since 6.5.0 | ||
* @access private | ||
* | ||
* @see WP_Block_Bindings_Registry | ||
*/ | ||
if ( ! class_exists( 'WP_Block_Bindings_Source' ) ) { | ||
final class WP_Block_Bindings_Source { | ||
|
||
/** | ||
* The name of the source. | ||
* | ||
* @since 6.5.0 | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* The label of the source. | ||
* | ||
* @since 6.5.0 | ||
* @var string | ||
*/ | ||
public $label; | ||
|
||
|
||
/** | ||
* The function used to get the value from the source. | ||
* | ||
* @since 6.5.0 | ||
* @var callable | ||
*/ | ||
private $get_value_callback; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* Do not use this constructor directly. Instead, use the | ||
* `WP_Block_Bindings_Registry::register` method or the `register_block_bindings_source` function. | ||
* | ||
* @since 6.5.0 | ||
* | ||
* @param string $name The name of the source. | ||
* @param array $source_properties The properties of the source. | ||
*/ | ||
public function __construct( string $name, array $source_properties ) { | ||
$this->name = $name; | ||
$this->label = $source_properties['label']; | ||
$this->get_value_callback = $source_properties['get_value_callback']; | ||
} | ||
|
||
/** | ||
* Retrieves the value from the source. | ||
* | ||
* @since 6.5.0 | ||
* | ||
* @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 ) ); | ||
} | ||
|
||
/** | ||
* Wakeup magic method. | ||
* | ||
* @since 6.5.0 | ||
*/ | ||
public function __wakeup() { | ||
throw new \LogicException( __CLASS__ . ' should never be unserialized' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters