Ticket #51550: 51550.2.diff
File 51550.2.diff, 2.6 KB (added by , 4 years ago) |
---|
-
src/wp-includes/revision.php
diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index a1aad16812..5a090aaf58 100644
a b function wp_revisions_to_keep( $post ) { 564 564 * @param int $num Number of revisions to store. 565 565 * @param WP_Post $post Post object. 566 566 */ 567 return (int) apply_filters( 'wp_revisions_to_keep', $num, $post ); 567 $num = apply_filters( 'wp_revisions_to_keep', $num, $post ); 568 569 /** 570 * Filters the number of revisions to save for the given post by its post type. 571 * 572 * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter. 573 * 574 * The dynamic portion of the hook name, `$post->post_type`, refers to 575 * the post type slug. 576 * 577 * @since 5.8.0 578 * 579 * @param int $num Number of revisions to store. 580 * @param WP_Post $post Post object. 581 */ 582 $num = apply_filters( "wp_{$post->post_type}_revisions_to_keep", $num, $post ); 583 584 return (int) $num; 568 585 } 569 586 570 587 /** -
tests/phpunit/tests/post/revisions.php
diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index 7883483e40..95d5eacc55 100644
a b class Tests_Post_Revisions extends WP_UnitTestCase { 576 576 577 577 $this->assertSame( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 578 578 } 579 580 public function test_wp_revisions_to_keep_filter() { 581 $post = self::factory()->post->create_and_get( 582 array( 583 'post_title' => 'some-post', 584 'post_type' => 'post', 585 'post_content' => 'some_content', 586 ) 587 ); 588 589 $default = wp_revisions_to_keep( $post ); 590 $expected = $default + 1; 591 592 add_filter( 593 'wp_revisions_to_keep', 594 function () use ( $expected ) { 595 return $expected; 596 } 597 ); 598 599 $this->assertSame( $expected, wp_revisions_to_keep( $post ) ); 600 } 601 602 public function test_wp_post_type_revisions_to_keep_filter() { 603 $post = self::factory()->post->create_and_get( 604 array( 605 'post_title' => 'some-post', 606 'post_type' => 'post', 607 'post_content' => 'some_content', 608 ) 609 ); 610 611 $default = wp_revisions_to_keep( $post ); 612 $generic = $default + 1; 613 614 add_filter( 615 'wp_revisions_to_keep', 616 function () use ( $generic ) { 617 return $generic; 618 } 619 ); 620 $this->assertSame( $generic, wp_revisions_to_keep( $post ) ); 621 622 $expected = $generic + 1; 623 624 add_filter( 625 "wp_{$post->post_type}_revisions_to_keep", 626 function () use ( $expected ) { 627 return $expected; 628 } 629 ); 630 $this->assertSame( $expected, wp_revisions_to_keep( $post ) ); 631 } 579 632 }