函数原型
has_blocks( int|string|WP_Post|null $post = null ): bool
函数描述
Determines whether a post or content string has blocks.
是否弃用
未弃用
函数参数
-
$post
int|string|WP_Post|null
Optional - Post content, post ID, or post object.
Defaults to global $post.Default:
null
函数返回值
bool Whether the post has blocks.
函数位置
File: wp-includes/blocks.php.
函数源码
function has_blocks( $post = null ) {
if ( ! is_string( $post ) ) {
$wp_post = get_post( $post );
if ( ! $wp_post instanceof WP_Post ) {
return false;
}
$post = $wp_post->post_content;
}
return false !== strpos( (string) $post, '<!-- wp:' );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 5.0.0 | Introduced. |

