Skip to content

Commit

Permalink
fix: check post_content before parsing it for blocks (#211)
Browse files Browse the repository at this point in the history
* chore: stub WP_Post_Type and boostrap main plugin file during phpstan

* fix: check for `$post->post_content` before parsing for blocks
  • Loading branch information
justlevine authored Mar 27, 2024
1 parent 66f74fb commit 0c8e2c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-maps-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

fix: check for `post_content` before attempting to parse them.
4 changes: 3 additions & 1 deletion includes/Data/ContentBlocksResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public static function resolve_content_blocks( $node, $args, $allowed_block_name
$new_parsed_blocks = [];
foreach ( $parsed_blocks as $block ) {
if ( 'core/block' === $block['blockName'] && $block['attrs']['ref'] ) {
$reusable_blocks = parse_blocks( get_post( $block['attrs']['ref'] )->post_content );
$post = get_post( $block['attrs']['ref'] );
$reusable_blocks = ! empty( $post->post_content ) ? parse_blocks( $post->post_content ) : null;

if ( ! empty( $reusable_blocks ) ) {
array_push( $new_parsed_blocks, ...$reusable_blocks );
}
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ parameters:
count: 1
path: includes/Blocks/Block.php

-
message: "#^Cannot access property \\$post_content on WP_Post\\|null\\.$#"
count: 1
path: includes/Data/ContentBlocksResolver.php

-
message: "#^Variable \\$block_spec in isset\\(\\) always exists and is not nullable\\.$#"
count: 1
Expand Down

0 comments on commit 0c8e2c7

Please sign in to comment.