函数文档

block_version()

💡 云策文档标注

概述

block_version() 函数用于检测内容字符串中使用的块编辑器格式版本,返回版本号或0表示无块。

关键要点

  • 函数接受一个必需参数 $content(字符串),表示要测试的内容。
  • 如果内容包含一个或多个块,返回版本号1;否则返回0。
  • 内部实现基于 has_blocks() 函数进行判断。
  • 自 WordPress 5.0.0 版本引入。

代码示例

function block_version( $content ) {
	return has_blocks( $content ) ? 1 : 0;
}

注意事项

如果字符串不包含块,函数返回0,这可用于区分块内容与非块内容。


📄 原文内容

Returns the current version of the block format that the content string is using.

Description

If the string doesn’t contain blocks, it returns 0.

Parameters

$contentstringrequired
Content to test.

Return

int The block format version is 1 if the content contains one or more blocks, 0 otherwise.

Source

function block_version( $content ) {
	return has_blocks( $content ) ? 1 : 0;
}

Changelog

Version Description
5.0.0 Introduced.