REST API: Include block_version on Post content object.

The `block_version` denotes which version of Blocks the `post_content` contains. Introduces new `block_version()` function for versioning Blocks.

Merges [43770] from the 5.0 branch to trunk.

Props danielbachhuber, birgire.
Fixes #43887.


git-svn-id: https://develop.svn.wordpress.org/trunk@44127 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2018-12-14 00:54:51 +00:00
parent 225f191f32
commit 63d9540fd8
5 changed files with 157 additions and 34 deletions

View File

@@ -262,3 +262,17 @@ function _recurse_do_blocks( $blocks, $all_blocks ) {
return $rendered_content;
}
/**
* Returns the current version of the block format that the content string is using.
*
* If the string doesn't contain blocks, it returns 0.
*
* @since 5.0.0
*
* @param string $content Content to test.
* @return int The block format version.
*/
function block_version( $content ) {
return has_blocks( $content ) ? 1 : 0;
}