Changeset 53769
- Timestamp:
- 07/23/2022 03:40:10 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r53760 r53769 2027 2027 2028 2028 if ( in_array( $post->post_type, array( 'post', 'page' ), true ) || post_type_supports( $post->post_type, 'revisions' ) ) { 2029 $revision = wp_get_last est_revision_id_and_total_count( $post->ID );2029 $revision = wp_get_last_revision_id_and_total_count( $post->ID ); 2030 2030 $revisions_count = ! is_wp_error( $revision ) ? $revision['count'] : 0; 2031 2031 … … 2036 2036 2037 2037 if ( $revisions_count > 0 ) { 2038 $last_revision = $revision['revision']; 2038 $last_revision = $revision['revision']; 2039 2039 2040 $links['predecessor-version'] = array( 2040 2041 'href' => rest_url( trailingslashit( $base ) . $post->ID . '/revisions/' . $last_revision ), -
trunk/src/wp-includes/revision.php
r53759 r53769 529 529 530 530 /** 531 * Get latest revisionand count of revisions for a post.531 * Returns the latest revision ID and count of revisions for a post. 532 532 * 533 533 * @since 6.1.0 534 534 * 535 * @param int|WP_Post |null$post Optional. Post ID or WP_Post object. Default is global $post.535 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 536 536 * @return WP_Error|array { 537 * Returns associative array with last revision and total count.538 * 539 * @type int $revision The last revision post id or 0 if non existing.540 * @type int $count The total count of revisions for $post_id.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. 540 * @type int $count The total count of revisions for the given post. 541 541 * } 542 542 */ 543 function wp_get_last est_revision_id_and_total_count( $post = null) {543 function wp_get_last_revision_id_and_total_count( $post = 0 ) { 544 544 $post = get_post( $post ); 545 545 546 546 if ( ! $post ) { 547 return new WP_Error( ' revision_error', __( 'Invalid post.' ) );547 return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); 548 548 } 549 549 550 550 if ( ! wp_revisions_enabled( $post ) ) { 551 return new WP_Error( 'revision _error', __( 'Revisions not enabled.' ) );551 return new WP_Error( 'revisions_not_enabled', __( 'Revisions not enabled.' ) ); 552 552 } 553 553 -
trunk/tests/phpunit/tests/post/revisions.php
r53759 r53769 657 657 658 658 /** 659 * Tests that wp_get_last est_revision_id_and_total_count() returns last revision idand total count.659 * Tests that wp_get_last_revision_id_and_total_count() returns the last revision ID and total count. 660 660 * 661 661 * @ticket 55857 … … 675 675 $post_revisions = wp_get_post_revisions( $post_id ); 676 676 $last_post_revision = current( $post_revisions ); 677 $revision = wp_get_last est_revision_id_and_total_count( $post_id );677 $revision = wp_get_last_revision_id_and_total_count( $post_id ); 678 678 679 679 $this->assertSame( 680 680 $last_post_revision->ID, 681 681 $revision['revision'], 682 ' Failed asserting latest revision id.'682 'The last revision ID does not match.' 683 683 ); 684 684 … … 686 686 count( $post_revisions ), 687 687 $revision['count'], 688 ' Failed asserting total count of revision.'689 ); 690 } 691 692 /** 693 * Tests that wp_get_last est_revision_id_and_total_count() when no revisions.688 'The total count of revisions does not match.' 689 ); 690 } 691 692 /** 693 * Tests that wp_get_last_revision_id_and_total_count() returns a WP_Error when no revisions exist. 694 694 * 695 695 * @ticket 55857 696 696 */ 697 697 public function test_wp_get_last_revision_id_and_total_count_no_revisions() { 698 $revision = wp_get_lastest_revision_id_and_total_count( null ); 699 $this->assertWPError( $revision, 'Invalid Post, non existing revisions.' ); 700 $this->assertSame( $revision->get_error_message(), 'Invalid post.' ); 698 $revision = wp_get_last_revision_id_and_total_count( null ); 699 700 $this->assertWPError( $revision, 'Invalid post, no revisions should exist.' ); 701 $this->assertSame( $revision->get_error_code(), 'invalid_post' ); 701 702 702 703 add_filter( 'wp_revisions_to_keep', '__return_zero' ); 703 704 $post_id = self::factory()->post->create(); 704 $revision = wp_get_lastest_revision_id_and_total_count( $post_id ); 705 $this->assertWPError( $revision, 'Revisions should be not enabled.' ); 706 $this->assertSame( $revision->get_error_message(), 'Revisions not enabled.' ); 705 $revision = wp_get_last_revision_id_and_total_count( $post_id ); 706 707 $this->assertWPError( $revision, 'Revisions should not be enabled.' ); 708 $this->assertSame( $revision->get_error_code(), 'revisions_not_enabled' ); 707 709 } 708 710
Note: See TracChangeset
for help on using the changeset viewer.