From e5fca863166693c52e765e0cf4b59ca4d8fee526 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 23 Jul 2022 15:42:16 +0000 Subject: [PATCH] Revisions: Correct the function name for retrieving the last revision ID and total count. Includes: * Renaming the function to `wp_get_last_revision_id_and_total_count()`. * Making the default value for `$post` consistent with `wp_get_post_revisions()`. * Making `WP_Error` codes more specific and using them in test assertions. * Adjusting the function description per the documentation standards. Follow-up to [53759]. Props JustinSainton, SergeyBiryukov. See #55857. Built from https://develop.svn.wordpress.org/trunk@53769 git-svn-id: http://core.svn.wordpress.org/trunk@53328 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-posts-controller.php | 5 +++-- wp-includes/revision.php | 16 ++++++++-------- wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) 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 946f08eafa..72e938cf83 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 @@ -2026,7 +2026,7 @@ 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_lastest_revision_id_and_total_count( $post->ID ); + $revision = wp_get_last_revision_id_and_total_count( $post->ID ); $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0; $links['version-history'] = array( @@ -2035,7 +2035,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { ); if ( $revisions_count > 0 ) { - $last_revision = $revision['revision']; + $last_revision = $revision['revision']; + $links['predecessor-version'] = array( 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ), 'id' => $last_revision, diff --git a/wp-includes/revision.php b/wp-includes/revision.php index 5f203fb730..a039c706fe 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -528,27 +528,27 @@ function wp_get_post_revisions( $post = 0, $args = null ) { } /** - * Get latest revision and count of revisions for a post. + * Returns the latest revision ID and count of revisions for a post. * * @since 6.1.0 * - * @param int|WP_Post|null $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 { - * Returns associative array with last revision and total count. + * Returns associative array with last revision ID and total count. * - * @type int $revision The last revision post id or 0 if non existing. - * @type int $count The total count of revisions for $post_id. + * @type int $revision The last revision post ID or 0 if no revisions exist. + * @type int $count The total count of revisions for the given post. * } */ -function wp_get_lastest_revision_id_and_total_count( $post = null ) { +function wp_get_last_revision_id_and_total_count( $post = 0 ) { $post = get_post( $post ); if ( ! $post ) { - return new WP_Error( 'revision_error', __( 'Invalid post.' ) ); + return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); } if ( ! wp_revisions_enabled( $post ) ) { - return new WP_Error( 'revision_error', __( 'Revisions not enabled.' ) ); + return new WP_Error( 'revisions_not_enabled', __( 'Revisions not enabled.' ) ); } $args = array( diff --git a/wp-includes/version.php b/wp-includes/version.php index 3d3517c626..6321aef658 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53768'; +$wp_version = '6.1-alpha-53769'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.