Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public function prepare_attributes_for_render( $attributes ) {
* Sets block type properties.
*
* @since 5.0.0
* @since 7.1.0 Added Support for rich-text attribute type, which is normalized to string for server-side rendering.
*
* @param array|string $args Array or string of arguments for registering a block type.
* See WP_Block_Type::__construct() for information on accepted arguments.
Expand All @@ -562,6 +563,16 @@ public function set_props( $args ) {
}
}

// Normalize block attribute types. The 'rich-text' type is used in
// block.json for the editor, but is not a valid JSON Schema type.
// Map it to 'string' since rich text values are always strings on
// the server side.
foreach ( $args['attributes'] as $key => $attribute ) {
if ( isset( $attribute['type'] ) && 'rich-text' === $attribute['type'] ) {
$args['attributes'][ $key ]['type'] = 'string';
}
}

/**
* Filters the arguments for registering a block type.
*
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/tests/blocks/wpBlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function test_prepare_attributes() {
/* missingDefaulted */
'undefined' => 'include',
'intendedNull' => null,
'richtext' => 'rich text content',
);

$block_type = new WP_Block_Type(
Expand All @@ -235,6 +236,9 @@ public function test_prepare_attributes() {
'type' => array( 'string', 'null' ),
'default' => 'wrong',
),
'richtext' => array(
'type' => 'rich-text',
),
),
)
);
Expand All @@ -249,6 +253,7 @@ public function test_prepare_attributes() {
'missingDefaulted' => 'define',
'undefined' => 'include',
'intendedNull' => null,
'richtext' => 'rich text content',
),
$prepared_attributes
);
Expand Down
Loading