Skip to content

Commit

Permalink
fix: ensure valid WP_Block_Type before applying Anchor interfaces. (
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine authored Apr 3, 2024
1 parent bdff4fb commit 9b0a63e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-walls-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

fix: Ensure valid `WP_Block_Type` before applying `Anchor` interfaces.
16 changes: 14 additions & 2 deletions includes/Registry/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ public function get_block_interfaces( string $block_name ): array {
* @return string[]
*/
public function get_block_additional_interfaces( string $block_name ): array {
$block_spec = $this->block_type_registry->get_registered( $block_name );
$block_spec = $this->block_type_registry->get_registered( $block_name );

// Bail if no block type is found.
if ( ! $block_spec instanceof \WP_Block_Type ) {
return [];
}

$block_interfaces = [];
// NOTE: Using add_filter here creates a performance penalty.
$block_interfaces = Anchor::get_block_interfaces( $block_interfaces, $block_spec );
Expand All @@ -185,7 +191,13 @@ public function get_block_additional_interfaces( string $block_name ): array {
* @return string[]
*/
public function get_block_attributes_interfaces( string $block_name ): array {
$block_spec = $this->block_type_registry->get_registered( $block_name );
$block_spec = $this->block_type_registry->get_registered( $block_name );

// Bail if no block type is found.
if ( ! $block_spec instanceof \WP_Block_Type ) {
return [];
}

$block_interfaces = [];
// NOTE: Using add_filter here creates a performance penalty.
$block_interfaces = Anchor::get_block_attributes_interfaces( $block_interfaces, $block_spec );
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ parameters:
count: 1
path: includes/Blocks/Block.php

-
message: "#^Parameter \\#2 \\$block_spec of static method WPGraphQL\\\\ContentBlocks\\\\Field\\\\BlockSupports\\\\Anchor\\:\\:get_block_attributes_interfaces\\(\\) expects WP_Block_Type, WP_Block_Type\\|null given\\.$#"
count: 1
path: includes/Registry/Registry.php

-
message: "#^Parameter \\#2 \\$block_spec of static method WPGraphQL\\\\ContentBlocks\\\\Field\\\\BlockSupports\\\\Anchor\\:\\:get_block_interfaces\\(\\) expects WP_Block_Type, WP_Block_Type\\|null given\\.$#"
count: 1
path: includes/Registry/Registry.php

-
message: "#^Call to an undefined method DiDom\\\\Element\\|DOMElement\\:\\:html\\(\\)\\.$#"
count: 1
Expand Down

0 comments on commit 9b0a63e

Please sign in to comment.