Skip to content

Commit

Permalink
Move supported blocks to private variables
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Feb 13, 2024
1 parent 42575c4 commit e41ba30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/wp-includes/class-wp-block-bindings-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ final class WP_Block_Bindings_Registry {
private static $instance = null;

/**
* Allowed block that can use the block bindings API.
* Supported blocks that can use the block bindings API.
*
* @since 6.5.0
* @var WP_Block_Bindings_Registry[]
*/
public $allowed_blocks = array(
private $supported_blocks = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'url', 'title', 'alt' ),
Expand Down Expand Up @@ -162,8 +162,7 @@ public function register( string $source_name, array $source_properties ) {
add_filter(
'get_block_type_uses_context',
function ( $uses_context, $block_type ) use ( $source ) {
$allowed_blocks = $this->allowed_blocks;
if ( empty( $allowed_blocks[ $block_type->name ] ) || empty( $source->uses_context ) ) {
if ( empty( $this->supported_blocks[ $block_type->name ] ) || empty( $source->uses_context ) ) {
return $uses_context;
}
// Use array_values to reset the array keys.
Expand Down
15 changes: 10 additions & 5 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,26 @@ private function process_block_bindings() {

$computed_attributes = array();

$allowed_blocks = WP_Block_Bindings_Registry::get_instance()->allowed_blocks;
$supported_blocks = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'url', 'title', 'alt' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
);

// If the block doesn't have the bindings property, isn't one of the allowed
// If the block doesn't have the bindings property, isn't one of the supported
// block types, or the bindings property is not an array, return the block content.
if (
! isset( $allowed_blocks[ $this->name ] ) ||
! isset( $supported_blocks[ $this->name ] ) ||
empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
! is_array( $parsed_block['attrs']['metadata']['bindings'] )
) {
return $computed_attributes;
}

foreach ( $parsed_block['attrs']['metadata']['bindings'] as $attribute_name => $block_binding ) {
// If the attribute is not in the allowed list, process next attribute.
if ( ! in_array( $attribute_name, $allowed_blocks[ $this->name ], true ) ) {
// If the attribute is not in the supported list, process next attribute.
if ( ! in_array( $attribute_name, $supported_blocks[ $this->name ], true ) ) {
continue;
}
// If no source is provided, or that source is not registered, process next attribute.
Expand Down

0 comments on commit e41ba30

Please sign in to comment.