From b0754798c61e8df3b2b5f033c5808e3e17f56d9e Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 22 Feb 2023 20:47:38 +0000 Subject: [PATCH] Revisions: Remove an unnecessary call to `_doing_it_wrong()` and corresponding new text string from the implementation of the new `wp_save_post_revision_revisions_before_deletion` filter. While the guard condition was technically correct, it's not practical or necessary to provide this protection for every use of every filter, and it adds unnecessary burden to translators to provide translations for strings that will likely not be seen. Follow up to [55254]. Fixes #57320 git-svn-id: https://develop.svn.wordpress.org/trunk@55406 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/revision.php | 21 ++--------- tests/phpunit/tests/post/revisions.php | 49 -------------------------- 2 files changed, 3 insertions(+), 67 deletions(-) diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index 783bd06e15..b4ecf0c863 100644 --- a/src/wp-includes/revision.php +++ b/src/wp-includes/revision.php @@ -205,30 +205,15 @@ function wp_save_post_revision( $post_id ) { * * @since 6.2.0 * - * @param WP_Post[]|int[] $revisions Array of revision objects or IDs, - * or an empty array if none. - * @param int $post_id The ID of the post to save as a revision. + * @param WP_Post[] $revisions Array of revisions, or an empty array if none. + * @param int $post_id The ID of the post to save as a revision. */ - $filtered_revisions = apply_filters( + $revisions = apply_filters( 'wp_save_post_revision_revisions_before_deletion', $revisions, $post_id ); - if ( is_array( $filtered_revisions ) ) { - $revisions = $filtered_revisions; - } else { - _doing_it_wrong( - __FUNCTION__, - sprintf( - /* translators: %s: The filter name. */ - __( 'The "%s" filter should return an array.' ), - 'wp_save_post_revision_revisions_before_deletion' - ), - '6.2.0' - ); - } - $delete = count( $revisions ) - $revisions_to_keep; if ( $delete < 1 ) { diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index 62e3bbef04..cc17ccd60d 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -928,53 +928,4 @@ class Tests_Post_Revisions extends WP_UnitTestCase { 'The title of the second revision was incorrect.' ); } - - /** - * Tests that wp_save_post_revision() ignores an invalid return value - * from the 'wp_save_post_revision_revisions_before_deletion' filter - * and throws _doing_it_wrong(). - * - * @ticket 57320 - * - * @covers ::wp_save_post_revision - * - * @expectedIncorrectUsage wp_save_post_revision - */ - public function test_wp_save_post_revision_should_ignore_invalid_revisions_before_deletion_filter() { - $post_id = self::factory()->post->create( array( 'post_title' => 'Test 57320' ) ); - - add_filter( - 'wp_revisions_to_keep', - static function() { - return 1; - } - ); - - add_filter( 'wp_save_post_revision_revisions_before_deletion', '__return_null' ); - - for ( $update = 1; $update < 4; ++$update ) { - wp_update_post( - array( - 'ID' => $post_id, - 'post_title' => 'Test 57320 Update ' . $update, - ) - ); - } - - $actual = wp_get_post_revisions( $post_id ); - - $this->assertCount( - 1, - $actual, - 'There should only be one revision.' - ); - - $first = reset( $actual ); - - $this->assertSame( - 'Test 57320 Update 3', - $first->post_title, - 'The title of the first revision was incorrect.' - ); - } }