From fedbeb2f3c9e61cc66ba6cb61186d1cf6df23786 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 29 May 2021 18:43:00 +0000 Subject: [PATCH] Docs: Document that `has_block()` does not check reusable blocks. Since the function only checks the raw, non-parsed post content, reusable blocks are just a `core/block` type and nothing more at that point. In order to also check reusable blocks, the content needs to be parsed using `parse_blocks()` first. Props vyskoczilova, peterwilsoncc. Fixes #53140. Built from https://develop.svn.wordpress.org/trunk@51046 git-svn-id: http://core.svn.wordpress.org/trunk@50655 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 12 +++++++----- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 26f82f8624..1e7113e1d2 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -374,7 +374,8 @@ function unregister_block_type( $name ) { * * @see parse_blocks() * - * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post. + * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. + * Defaults to global $post. * @return bool Whether the post has blocks. */ function has_blocks( $post = null ) { @@ -392,15 +393,16 @@ function has_blocks( $post = null ) { * Determine whether a $post or a string contains a specific block type. * * This test optimizes for performance rather than strict accuracy, detecting - * the block type exists but not validating its structure. For strict accuracy, - * you should use the block parser on post content. + * whether the block type exists but not validating its structure and not checking + * reusable blocks. For strict accuracy, you should use the block parser on post content. * * @since 5.0.0 * * @see parse_blocks() * - * @param string $block_name Full Block type to look for. - * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post. + * @param string $block_name Full block type to look for. + * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. + * Defaults to global $post. * @return bool Whether the post content contains the specified block. */ function has_block( $block_name, $post = null ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index ecd7551e36..4bd6e18eee 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51045'; +$wp_version = '5.8-alpha-51046'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.