diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 656d1174bc..2c9bf40f19 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -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' ) ) { - $revision = wp_get_latest_revision_id_and_total_count( $post->ID ); - $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0; + $revisions = wp_get_latest_revision_id_and_total_count( $post->ID ); + $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0; $links['version-history'] = array( '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 ) { - $latest_revision = $revision['revision']; - $links['predecessor-version'] = array( - 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $latest_revision ), - 'id' => $latest_revision, + 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $revisions['latest_id'] ), + 'id' => $revisions['latest_id'], ); } } diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index 0870b837c2..95a7c507fa 100644 --- a/src/wp-includes/revision.php +++ b/src/wp-includes/revision.php @@ -533,11 +533,12 @@ function wp_get_post_revisions( $post = 0, $args = null ) { * @since 6.1.0 * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. - * @return WP_Error|array { - * Returns associative array with latest revision ID and total count. + * @return array|WP_Error { + * 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 $count The total count of revisions for the given post. + * @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. * } */ 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 ) { return array( - 'revision' => 0, - 'count' => 0, + 'latest_id' => 0, + 'count' => 0, ); } return array( - 'revision' => $revisions[0], - 'count' => $revision_query->found_posts, + 'latest_id' => $revisions[0], + 'count' => $revision_query->found_posts, ); } diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index e95f08f927..e4e0c500d5 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -675,17 +675,17 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $post_revisions = wp_get_post_revisions( $post_id ); $latest_post_revision = current( $post_revisions ); - $revision = wp_get_latest_revision_id_and_total_count( $post_id ); + $revisions = wp_get_latest_revision_id_and_total_count( $post_id ); $this->assertSame( $latest_post_revision->ID, - $revision['revision'], + $revisions['latest_id'], 'The latest revision ID does not match.' ); $this->assertSame( count( $post_revisions ), - $revision['count'], + $revisions['count'], 'The total count of revisions does not match.' ); }