Skip to content

Commit

Permalink
Breaking Update: Handle rich-text field for WordPress >= v6.5 (#229)
Browse files Browse the repository at this point in the history
* Update: Handle  field for WordPress >= v6.5

* PHPCS: Fix

* Code Review: Passthrough case
  • Loading branch information
theodesp authored Apr 8, 2024
1 parent e348494 commit ed23a32
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .changeset/famous-hats-deliver.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions includes/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ] : [];
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 0 additions & 6 deletions includes/Blocks/CoreCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@ class CoreCode extends Block {
'source' => 'attribute',
'attribute' => 'class',
],
'content' => [
'type' => 'string',
'selector' => 'code',
'source' => 'html',
'default' => '',
],
];
}
6 changes: 0 additions & 6 deletions includes/Blocks/CoreParagraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@ class CoreParagraph extends Block {
'source' => 'attribute',
'attribute' => 'class',
],
'content' => [
'type' => 'string',
'selector' => 'p',
'source' => 'html',
'default' => '',
],
];
}

0 comments on commit ed23a32

Please sign in to comment.