Make WordPress Core

Changeset 53778


Ignore:
Timestamp:
07/25/2022 07:18:41 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Revisions: Rename the function for retrieving the latest revision ID and total count.

The new name is wp_get_latest_revision_id_and_total_count().

This aims to reduce ambiguity about what exactly is the "first" or "last" revision, and bring more consistency with similar wording elsewhere in core, e.g. latest posts, latest comments, etc.

Follow-up to [53759], [53769].

Props peterwilsoncc.
See #55857.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r53769 r53778  
    20272027
    20282028        if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
    2029             $revision        = wp_get_last_revision_id_and_total_count( $post->ID );
     2029            $revision        = wp_get_latest_revision_id_and_total_count( $post->ID );
    20302030            $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0;
    20312031
     
    20362036
    20372037            if ( $revisions_count > 0 ) {
    2038                 $last_revision = $revision['revision'];
     2038                $latest_revision = $revision['revision'];
    20392039
    20402040                $links['predecessor-version'] = array(
    2041                     'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ),
    2042                     'id'   => $last_revision,
     2041                    'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $latest_revision ),
     2042                    'id'   => $latest_revision,
    20432043                );
    20442044            }
  • trunk/src/wp-includes/revision.php

    r53770 r53778  
    535535 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    536536 * @return WP_Error|array {
    537  *     Returns associative array with last revision ID and total count.
    538  *
    539  *     @type int $revision The last revision post ID or 0 if no revisions exist.
     537 *     Returns associative array with latest revision ID and total count.
     538 *
     539 *     @type int $revision The latest revision post ID or 0 if no revisions exist.
    540540 *     @type int $count    The total count of revisions for the given post.
    541541 * }
    542542 */
    543 function wp_get_last_revision_id_and_total_count( $post = 0 ) {
     543function wp_get_latest_revision_id_and_total_count( $post = 0 ) {
    544544    $post = get_post( $post );
    545545
  • trunk/tests/phpunit/tests/post/revisions.php

    r53769 r53778  
    657657
    658658    /**
    659      * Tests that wp_get_last_revision_id_and_total_count() returns the last revision ID and total count.
    660      *
     659     * Tests that wp_get_latest_revision_id_and_total_count() returns the latest revision ID and total count.
     660     *
     661     * @covers ::wp_get_latest_revision_id_and_total_count
    661662     * @ticket 55857
    662663     * @dataProvider data_wp_get_post_revisions_url
    663664     */
    664     public function test_wp_get_last_revision_id_and_total_count( $revisions ) {
     665    public function test_wp_get_latest_revision_id_and_total_count( $revisions ) {
    665666        $post_id = self::factory()->post->create();
    666667        for ( $i = 0; $i < $revisions; ++$i ) {
     
    673674        }
    674675
    675         $post_revisions     = wp_get_post_revisions( $post_id );
    676         $last_post_revision = current( $post_revisions );
    677         $revision           = wp_get_last_revision_id_and_total_count( $post_id );
     676        $post_revisions       = wp_get_post_revisions( $post_id );
     677        $latest_post_revision = current( $post_revisions );
     678        $revision             = wp_get_latest_revision_id_and_total_count( $post_id );
    678679
    679680        $this->assertSame(
    680             $last_post_revision->ID,
     681            $latest_post_revision->ID,
    681682            $revision['revision'],
    682             'The last revision ID does not match.'
     683            'The latest revision ID does not match.'
    683684        );
    684685
     
    691692
    692693    /**
    693      * Tests that wp_get_last_revision_id_and_total_count() returns a WP_Error when no revisions exist.
    694      *
     694     * Tests that wp_get_latest_revision_id_and_total_count() returns a WP_Error when no revisions exist.
     695     *
     696     * @covers ::wp_get_latest_revision_id_and_total_count
    695697     * @ticket 55857
    696698     */
    697     public function test_wp_get_last_revision_id_and_total_count_no_revisions() {
    698         $revision = wp_get_last_revision_id_and_total_count( null );
     699    public function test_wp_get_latest_revision_id_and_total_count_no_revisions() {
     700        $revision = wp_get_latest_revision_id_and_total_count( null );
    699701
    700702        $this->assertWPError( $revision, 'Invalid post, no revisions should exist.' );
     
    703705        add_filter( 'wp_revisions_to_keep', '__return_zero' );
    704706        $post_id  = self::factory()->post->create();
    705         $revision = wp_get_last_revision_id_and_total_count( $post_id );
     707        $revision = wp_get_latest_revision_id_and_total_count( $post_id );
    706708
    707709        $this->assertWPError( $revision, 'Revisions should not be enabled.' );
Note: See TracChangeset for help on using the changeset viewer.