Changeset 43439
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43437 r43439 1676 1676 1677 1677 if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) { 1678 $revisions = wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) ); 1679 $revisions_count = count( $revisions ); 1680 1678 1681 $links['version-history'] = array( 1679 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ), 1680 ); 1682 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions' ), 1683 'count' => $revisions_count, 1684 ); 1685 1686 if ( $revisions_count > 0 ) { 1687 $last_revision = array_shift( $revisions ); 1688 1689 $links['predecessor-version'] = array( 1690 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ), 1691 'id' => $last_revision, 1692 ); 1693 } 1694 1681 1695 } 1682 1696 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43437 r43439 1284 1284 1285 1285 $this->assertEquals( rest_url( '/wp/v2/posts/' . self::$post_id . '/revisions' ), $links['version-history'][0]['href'] ); 1286 $this->assertEquals( 0, $links['version-history'][0]['attributes']['count'] ); 1287 $this->assertFalse( isset( $links['predecessor-version'] ) ); 1286 1288 1287 1289 $attachments_url = rest_url( '/wp/v2/media' ); … … 1309 1311 $category_url = add_query_arg( 'post', self::$post_id, rest_url( '/wp/v2/categories' ) ); 1310 1312 $this->assertEquals( $category_url, $cat_link['href'] ); 1313 } 1314 1315 public function test_get_item_links_predecessor() { 1316 wp_update_post( 1317 array( 1318 'post_content' => 'This content is marvelous.', 1319 'ID' => self::$post_id, 1320 ) 1321 ); 1322 $revisions = wp_get_post_revisions( self::$post_id ); 1323 $revision_1 = array_pop( $revisions ); 1324 1325 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1326 $response = rest_get_server()->dispatch( $request ); 1327 1328 $links = $response->get_links(); 1329 1330 $this->assertEquals( rest_url( '/wp/v2/posts/' . self::$post_id . '/revisions' ), $links['version-history'][0]['href'] ); 1331 $this->assertEquals( 1, $links['version-history'][0]['attributes']['count'] ); 1332 1333 $this->assertEquals( rest_url( '/wp/v2/posts/' . self::$post_id . '/revisions/' . $revision_1->ID ), $links['predecessor-version'][0]['href'] ); 1334 $this->assertEquals( $revision_1->ID, $links['predecessor-version'][0]['attributes']['id'] ); 1311 1335 } 1312 1336 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r43359 r43439 3604 3604 "version-history": [ 3605 3605 { 3606 "count": 1, 3606 3607 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3/revisions" 3608 } 3609 ], 3610 "predecessor-version": [ 3611 { 3612 "id": 3123, 3613 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3122/revisions/3123" 3607 3614 } 3608 3615 ], … … 3789 3796 "version-history": [ 3790 3797 { 3798 "count": 1, 3791 3799 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/5/revisions" 3800 } 3801 ], 3802 "predecessor-version": [ 3803 { 3804 "id": 3125, 3805 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3124/revisions/3125" 3792 3806 } 3793 3807 ], … … 3938 3952 "self": [ 3939 3953 { 3954 "attributes": [], 3940 3955 "href": "http://example.org/index.php?rest_route=/wp/v2/media/7" 3941 3956 } … … 3943 3958 "collection": [ 3944 3959 { 3960 "attributes": [], 3945 3961 "href": "http://example.org/index.php?rest_route=/wp/v2/media" 3946 3962 } … … 3948 3964 "about": [ 3949 3965 { 3966 "attributes": [], 3950 3967 "href": "http://example.org/index.php?rest_route=/wp/v2/types/attachment" 3951 3968 } … … 3953 3970 "replies": [ 3954 3971 { 3955 "embeddable": true, 3972 "attributes": { 3973 "embeddable": true 3974 }, 3956 3975 "href": "http://example.org/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7" 3957 3976 }
Note: See TracChangeset
for help on using the changeset viewer.