Changeset 53841
- Timestamp:
- 08/05/2022 01:00:57 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r53814 r53841 2065 2065 2066 2066 if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) { 2067 $revision 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; 2069 2069 2070 2070 $links['version-history'] = array( … … 2074 2074 2075 2075 if ( $revisions_count > 0 ) { 2076 $latest_revision = $revision['revision'];2077 2078 2076 $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'], 2081 2079 ); 2082 2080 } -
trunk/src/wp-includes/revision.php
r53779 r53841 534 534 * 535 535 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 536 * @return WP_Error|array { 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. 540 * @type int $count The total count of revisions for the given post. 536 * @return array|WP_Error { 537 * Returns associative array with latest revision ID and total count, 538 * or a WP_Error if the post does not exist or revisions are not enabled. 539 * 540 * @type int $latest_id The latest revision post ID or 0 if no revisions exist. 541 * @type int $count The total count of revisions for the given post. 541 542 * } 542 543 */ … … 568 569 if ( ! $revisions ) { 569 570 return array( 570 ' revision' => 0,571 'count' => 0,571 'latest_id' => 0, 572 'count' => 0, 572 573 ); 573 574 } 574 575 575 576 return array( 576 ' revision' => $revisions[0],577 'count' => $revision_query->found_posts,577 'latest_id' => $revisions[0], 578 'count' => $revision_query->found_posts, 578 579 ); 579 580 } -
trunk/tests/phpunit/tests/post/revisions.php
r53778 r53841 676 676 $post_revisions = wp_get_post_revisions( $post_id ); 677 677 $latest_post_revision = current( $post_revisions ); 678 $revision 678 $revisions = wp_get_latest_revision_id_and_total_count( $post_id ); 679 679 680 680 $this->assertSame( 681 681 $latest_post_revision->ID, 682 $revision ['revision'],682 $revisions['latest_id'], 683 683 'The latest revision ID does not match.' 684 684 ); … … 686 686 $this->assertSame( 687 687 count( $post_revisions ), 688 $revision ['count'],688 $revisions['count'], 689 689 'The total count of revisions does not match.' 690 690 );
Note: See TracChangeset
for help on using the changeset viewer.