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
This commit is contained in:
Sergey Biryukov
2021-05-29 18:41:09 +00:00
parent 24a70204db
commit 59e55af520

View File

@@ -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 ) {