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. Built from https://develop.svn.wordpress.org/trunk@44127 git-svn-id: http://core.svn.wordpress.org/trunk@43957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d4d16ec083
commit
423c828330
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1525,6 +1525,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
/** This filter is documented in wp-includes/post-template.php */
|
||||
'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ),
|
||||
'protected' => (bool) $post->post_password,
|
||||
'block_version' => block_version( $post->post_content ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2073,6 +2074,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'block_version' => array(
|
||||
'description' => __( 'Version of the content block format used by the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether the content is protected with a password.' ),
|
||||
'type' => 'boolean',
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.1-alpha-44126';
|
||||
$wp_version = '5.1-alpha-44127';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue