From 59e55af520fd408d0389b683a073156164393ba6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 29 May 2021 18:41:09 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@51046 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 26f82f8624..1e7113e1d2 100644 --- a/src/wp-includes/blocks.php +++ b/src/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 ) {