Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Register 'lock' attribute for every block on the server
  • Loading branch information
Mamaduka committed Apr 21, 2022
commit b472ad3d750d5d82f12e1a61344146f16a10ecac
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ LOCAL_PHP_MEMCACHED=false
#
# Supported values are `mysql` and `mariadb`.
##
LOCAL_DB_TYPE=mysql
LOCAL_DB_TYPE=mariadb

##
# The database version to use.
Expand All @@ -38,7 +38,7 @@ LOCAL_DB_TYPE=mysql
# When using `mysql`, see https://hub.docker.com/_/mysql/ for valid versions.
# When using `mariadb`, see https://hub.docker.com/_/mariadb for valid versions.
##
LOCAL_DB_VERSION=5.7
LOCAL_DB_VERSION=10

# The debug settings to add to `wp-config.php`.
LOCAL_WP_DEBUG=true
Expand Down
22 changes: 22 additions & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ class WP_Block_Type {
*/
public $style = null;

/**
* Attributes supported by every block.
*
* @since 6.0.0
* @var array
*/
const CORE_ATTRIBUTES = array(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't decide between CORE_ATTRIBUTES and BUILTIN_ATTRIBUTES. I'm open to name suggestions :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't decide between CORE_ATTRIBUTES and BUILTIN_ATTRIBUTES.

How about GLOBAL_ATTRIBUTES or GLOBAL_BLOCK_ATTRIBUTES?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GLOBAL_ATTRIBUTES reads nice 👍🏻

'lock' => array( 'type' => 'object' ),
);

/**
* Constructor.
*
Expand Down Expand Up @@ -368,6 +378,18 @@ public function set_props( $args ) {
foreach ( $args as $property_name => $property_value ) {
$this->$property_name = $property_value;
}

// Setup attributes if needed.
if ( ! $this->attributes ) {
$this->attributes = array();
}

// Register core attributes.
foreach ( static::CORE_ATTRIBUTES as $attr_key => $attr_schema ) {
if ( ! array_key_exists( $attr_key, $this->attributes ) ) {
$this->attributes[ $attr_key ] = $attr_schema;
}
}
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/blocks/wpBlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@ public function test_set_props() {
$this->assertSame( $args['foo'], $block_type->foo );
}

public function test_core_attributes() {
$block_type = new WP_Block_Type( 'core/fake', array() );

$this->assertEquals(
array(
'lock' => array( 'type' => 'object' ),
),
$block_type->attributes
);
}

public function test_core_attributes_matches_custom() {
$block_type = new WP_Block_Type(
'core/fake',
array(
'attributes' => array(
'lock' => array(
'type' => 'string',
),
),
)
);

// Backward compatibility: Don't override attributes with the same name.
$this->assertEquals(
array(
'lock' => array( 'type' => 'string' ),
),
$block_type->attributes
);
}

/**
* @ticket 45097
*/
Expand Down