diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index ed0c4d2dbf..f65ddb6c2e 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -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; +} diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 5002484ed8..93d2f0806f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1521,10 +1521,11 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { if ( in_array( 'content', $fields, true ) ) { $data['content'] = array( - 'raw' => $post->post_content, + 'raw' => $post->post_content, /** 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, + 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), + 'protected' => (bool) $post->post_password, + 'block_version' => block_version( $post->post_content ), ); } @@ -2062,18 +2063,24 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() ), 'properties' => array( - 'raw' => array( + 'raw' => array( 'description' => __( 'Content for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), - 'rendered' => array( + 'rendered' => array( 'description' => __( 'HTML content for the object, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), - 'protected' => array( + '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', 'context' => array( 'view', 'edit', 'embed' ), diff --git a/wp-includes/version.php b/wp-includes/version.php index 089e75457d..6b30e1dbe0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.