has_blocks()
云策文档标注
概述
has_blocks() 函数用于检测文章或内容字符串是否包含区块,它优先考虑性能而非严格准确性,通过模式匹配而非结构验证来快速判断。对于需要精确解析的场景,建议使用 parse_blocks() 函数。
关键要点
- 函数接受可选参数 $post,可以是内容字符串、文章 ID、WP_Post 对象或 null(默认使用全局 $post),返回布尔值表示是否包含区块。
- 内部实现中,如果 $post 不是字符串,会通过 get_post() 获取文章对象并提取 post_content 进行检测。
- 检测基于字符串包含特定模式(如 '
-
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Ankit Gade