has_blocks
函数
has_blocks ( $post = null )
- 参数
-
-
(int|string|WP_Post|null)
$post
Optional. Post content, post ID, or post object. Defaults to global $post.- Required: 否
- Default: null
-
(int|string|WP_Post|null)
- 返回值
-
- (bool) Whether the post has blocks.
- 相关
-
- parse_blocks()
- 定义位置
-
-
wp-includes/blocks.php
, line 567
-
wp-includes/blocks.php
- 引入
- 5.0.0
- 弃用
- –
判断一个文章或内容字符串是否有区块。
这个测试优化了性能,而不是严格的准确性,检测区块的模式,但不验证其结构。对于严格的准确性,你应该在文章内容上使用区块分析器。
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, '
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。