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
This commit is contained in:
audrasjb 2022-08-08 08:22:12 +00:00
parent 51346d566a
commit ba7b41113c
2 changed files with 6 additions and 3 deletions

View File

@ -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, '<!-- wp:' );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53857';
$wp_version = '6.1-alpha-53858';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.