From ba7b41113caf7225042431042e608c0fe777b8ff Mon Sep 17 00:00:00 2001 From: audrasjb Date: Mon, 8 Aug 2022 08:22:12 +0000 Subject: [PATCH] Editor: Safeguard `has_blocks()` against fatal errors. This changeset ensures `has_blocks()` doesn't return a fatal error when `$post` is not a valid post. If the post can't be retrieved, the function now returns `false`. Props Howdy_McGee, costdev, colonelphantom, audrasjb, dlh, peterwilsoncc. Fixes #55705. Built from https://develop.svn.wordpress.org/trunk@53858 git-svn-id: http://core.svn.wordpress.org/trunk@53417 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 7 +++++-- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 62ba1843d7..f6c8f32706 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -425,9 +425,12 @@ function unregister_block_type( $name ) { function has_blocks( $post = null ) { if ( ! is_string( $post ) ) { $wp_post = get_post( $post ); - if ( $wp_post instanceof WP_Post ) { - $post = $wp_post->post_content; + + if ( ! $wp_post instanceof WP_Post ) { + return false; } + + $post = $wp_post->post_content; } return false !== strpos( (string) $post, '