From ed23a328e0a1ed361a2d81e1991505285130e33e Mon Sep 17 00:00:00 2001 From: Theofanis Despoudis <328805+theodesp@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:39:17 +0100 Subject: [PATCH] Breaking Update: Handle `rich-text` field for WordPress >= v6.5 (#229) * Update: Handle field for WordPress >= v6.5 * PHPCS: Fix * Code Review: Passthrough case --- .changeset/famous-hats-deliver.md | 9 +++++++++ includes/Blocks/Block.php | 3 +++ includes/Blocks/CoreCode.php | 6 ------ includes/Blocks/CoreParagraph.php | 6 ------ 4 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 .changeset/famous-hats-deliver.md diff --git a/.changeset/famous-hats-deliver.md b/.changeset/famous-hats-deliver.md new file mode 100644 index 00000000..0c2061d0 --- /dev/null +++ b/.changeset/famous-hats-deliver.md @@ -0,0 +1,9 @@ +--- +"@wpengine/wp-graphql-content-blocks": major +--- + +MAJOR: Update Schema to reflect latest WordPress 6.5 changes. + +- WHAT the breaking change is: Added new `rich-text` type +- WHY the change was made: WordPress 6.5 replaced some of the attribute types from string to `rich-text` causing breaking changes to the existing block fields. +- HOW a consumer should update their code: If users need to use WordPress >= 6.5 they need to update this plugin to the latest version and update their graphql schemas. diff --git a/includes/Blocks/Block.php b/includes/Blocks/Block.php index f0141068..ccbba68c 100644 --- a/includes/Blocks/Block.php +++ b/includes/Blocks/Block.php @@ -136,6 +136,7 @@ private function get_attribute_type( $name, $attribute, $prefix ) { if ( isset( $attribute['type'] ) ) { switch ( $attribute['type'] ) { + case 'rich-text': case 'string': $type = 'String'; break; @@ -301,6 +302,7 @@ private function normalize_attribute_value( $value, $type ) { } switch ( $type ) { + case 'rich-text': case 'array': // If we're here, we want an array type, even though the value is not an array. return isset( $value ) ? [ $value ] : []; @@ -375,6 +377,7 @@ private function resolve_block_attributes_recursive( $attributes, $html, $config $default = $value['default'] ?? null; $source = $value['source'] ?? null; switch ( $source ) { + case 'rich-text': case 'html': if ( ! isset( $value['selector'] ) ) { $result[ $key ] = $this->parse_single_source( $html, $source ); diff --git a/includes/Blocks/CoreCode.php b/includes/Blocks/CoreCode.php index 4877dfca..cf8659aa 100644 --- a/includes/Blocks/CoreCode.php +++ b/includes/Blocks/CoreCode.php @@ -23,11 +23,5 @@ class CoreCode extends Block { 'source' => 'attribute', 'attribute' => 'class', ], - 'content' => [ - 'type' => 'string', - 'selector' => 'code', - 'source' => 'html', - 'default' => '', - ], ]; } diff --git a/includes/Blocks/CoreParagraph.php b/includes/Blocks/CoreParagraph.php index 4ccf2cd0..5b1fd7ee 100644 --- a/includes/Blocks/CoreParagraph.php +++ b/includes/Blocks/CoreParagraph.php @@ -23,11 +23,5 @@ class CoreParagraph extends Block { 'source' => 'attribute', 'attribute' => 'class', ], - 'content' => [ - 'type' => 'string', - 'selector' => 'p', - 'source' => 'html', - 'default' => '', - ], ]; }