Make WordPress Core

Ticket #44321: 44321.1.diff

File 44321.1.diff, 1.2 KB (added by kadamwhite, 6 years ago)

Add a count property to the version-history link specifying the number of available revisions, and a _link using the "predecessor" relation to specify the most recent revision.

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index b7b2dd79f6..901b844189 100644
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    16641664                }
    16651665
    16661666                if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) {
     1667                        $revisions = wp_get_post_revisions( $post->ID );
     1668                        $revisions_count = count( $revisions );
     1669
    16671670                        $links['version-history'] = array(
    1668                                 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
     1671                                'href'  => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ),
     1672                                'count' => $revisions_count,
    16691673                        );
     1674
     1675                        if ( 0 < $revisions_count ) {
     1676                                $last_revision = array_shift( $revisions );
     1677
     1678                                $links['predecessor'] = array(
     1679                                        'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision->ID ),
     1680                                );
     1681                        }
    16701682                }
    16711683
    16721684                $post_type_obj = get_post_type_object( $post->post_type );