Revisions: Use `latest_id` as the array key for the latest revision ID.
This updates `wp_get_latest_revision_id_and_total_count()` and its usage to be a bit more descriptive and a bit less repetitive, e.g. `$revisions['latest_id']` instead of `$revision['revision']`. Includes updating the `@return` tag to explain when the function returns a `WP_Error`. Follow-up to [53759], [53769], [53778], [53779]. See #55857. Built from https://develop.svn.wordpress.org/trunk@53841 git-svn-id: http://core.svn.wordpress.org/trunk@53400 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
233089c138
commit
b6198f330f
|
@ -2064,8 +2064,8 @@ 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' ) ) {
|
||||||
$revision = wp_get_latest_revision_id_and_total_count( $post->ID );
|
$revisions = wp_get_latest_revision_id_and_total_count( $post->ID );
|
||||||
$revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0;
|
$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
|
||||||
|
|
||||||
$links['version-history'] = array(
|
$links['version-history'] = array(
|
||||||
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
|
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
|
||||||
|
@ -2073,11 +2073,9 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $revisions_count > 0 ) {
|
if ( $revisions_count > 0 ) {
|
||||||
$latest_revision = $revision['revision'];
|
|
||||||
|
|
||||||
$links['predecessor-version'] = array(
|
$links['predecessor-version'] = array(
|
||||||
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $latest_revision ),
|
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $revisions['latest_id'] ),
|
||||||
'id' => $latest_revision,
|
'id' => $revisions['latest_id'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -533,11 +533,12 @@ function wp_get_post_revisions( $post = 0, $args = null ) {
|
||||||
* @since 6.1.0
|
* @since 6.1.0
|
||||||
*
|
*
|
||||||
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
|
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
|
||||||
* @return WP_Error|array {
|
* @return array|WP_Error {
|
||||||
* Returns associative array with latest revision ID and total count.
|
* Returns associative array with latest revision ID and total count,
|
||||||
|
* or a WP_Error if the post does not exist or revisions are not enabled.
|
||||||
*
|
*
|
||||||
* @type int $revision The latest revision post ID or 0 if no revisions exist.
|
* @type int $latest_id The latest revision post ID or 0 if no revisions exist.
|
||||||
* @type int $count The total count of revisions for the given post.
|
* @type int $count The total count of revisions for the given post.
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
function wp_get_latest_revision_id_and_total_count( $post = 0 ) {
|
function wp_get_latest_revision_id_and_total_count( $post = 0 ) {
|
||||||
|
@ -567,14 +568,14 @@ function wp_get_latest_revision_id_and_total_count( $post = 0 ) {
|
||||||
|
|
||||||
if ( ! $revisions ) {
|
if ( ! $revisions ) {
|
||||||
return array(
|
return array(
|
||||||
'revision' => 0,
|
'latest_id' => 0,
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'revision' => $revisions[0],
|
'latest_id' => $revisions[0],
|
||||||
'count' => $revision_query->found_posts,
|
'count' => $revision_query->found_posts,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-alpha-53840';
|
$wp_version = '6.1-alpha-53841';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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