mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@53858 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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:' );
|
||||
|
||||
@@ -552,6 +552,21 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
|
||||
$this->assertFalse( has_blocks( $content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that `has_blocks()` returns `false` with an invalid post.
|
||||
*
|
||||
* @ticket 55705
|
||||
*
|
||||
* @covers ::has_blocks
|
||||
*/
|
||||
public function test_has_blocks_with_invalid_post() {
|
||||
$a_post = (object) array(
|
||||
'ID' => 55705,
|
||||
'filter' => 'display',
|
||||
);
|
||||
$this->assertFalse( has_blocks( $a_post ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 49615
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user