REST API: Expose revision count and last revision ID on Post response
So that REST API clients can show appropriate UI for a post's revisions, it needs to know how many revisions the post has, and what the latest revision ID is. Merge of [43439] and [43441] to the 4.9 branch. Props kadamwhite, danielbachhuber, birgire, TimothyBlynJacobs, pento. Fixes #44321. Built from https://develop.svn.wordpress.org/branches/4.9@43442 git-svn-id: http://core.svn.wordpress.org/branches/4.9@43269 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
26f6aeaeea
commit
d802d709c7
|
@ -1667,9 +1667,23 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
|
if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
|
||||||
|
$revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
|
||||||
|
$revisions_count = count( $revisions );
|
||||||
|
|
||||||
$links['version-history'] = array(
|
$links['version-history'] = array(
|
||||||
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
|
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
|
||||||
|
'count' => $revisions_count,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( $revisions_count > 0 ) {
|
||||||
|
$last_revision = array_shift( $revisions );
|
||||||
|
|
||||||
|
$links['predecessor-version'] = array(
|
||||||
|
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ),
|
||||||
|
'id' => $last_revision,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_type_obj = get_post_type_object( $post->post_type );
|
$post_type_obj = get_post_type_object( $post->post_type );
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9.8-alpha-43438';
|
$wp_version = '4.9.8-alpha-43442';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue