Make WordPress Core


Ignore:
Timestamp:
08/05/2022 01:00:57 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r53814 r53841  
    20652065
    20662066        if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
    2067             $revision        = wp_get_latest_revision_id_and_total_count( $post->ID );
    2068             $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0;
     2067            $revisions       = wp_get_latest_revision_id_and_total_count( $post->ID );
     2068            $revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
    20692069
    20702070            $links['version-history'] = array(
     
    20742074
    20752075            if ( $revisions_count > 0 ) {
    2076                 $latest_revision = $revision['revision'];
    2077 
    20782076                $links['predecessor-version'] = array(
    2079                     'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $latest_revision ),
    2080                     'id'   => $latest_revision,
     2077                    'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $revisions['latest_id'] ),
     2078                    'id'   => $revisions['latest_id'],
    20812079                );
    20822080            }
Note: See TracChangeset for help on using the changeset viewer.