Skip to content

Commit b075479

Browse files
committed
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
1 parent 05648a5 commit b075479

File tree

2 files changed

+3
-67
lines changed

2 files changed

+3
-67
lines changed

src/wp-includes/revision.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,30 +205,15 @@ function wp_save_post_revision( $post_id ) {
205205
*
206206
* @since 6.2.0
207207
*
208-
* @param WP_Post[]|int[] $revisions Array of revision objects or IDs,
209-
* or an empty array if none.
210-
* @param int $post_id The ID of the post to save as a revision.
208+
* @param WP_Post[] $revisions Array of revisions, or an empty array if none.
209+
* @param int $post_id The ID of the post to save as a revision.
211210
*/
212-
$filtered_revisions = apply_filters(
211+
$revisions = apply_filters(
213212
'wp_save_post_revision_revisions_before_deletion',
214213
$revisions,
215214
$post_id
216215
);
217216

218-
if ( is_array( $filtered_revisions ) ) {
219-
$revisions = $filtered_revisions;
220-
} else {
221-
_doing_it_wrong(
222-
__FUNCTION__,
223-
sprintf(
224-
/* translators: %s: The filter name. */
225-
__( 'The "%s" filter should return an array.' ),
226-
'wp_save_post_revision_revisions_before_deletion'
227-
),
228-
'6.2.0'
229-
);
230-
}
231-
232217
$delete = count( $revisions ) - $revisions_to_keep;
233218

234219
if ( $delete < 1 ) {

tests/phpunit/tests/post/revisions.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -928,53 +928,4 @@ static function ( $revisions ) {
928928
'The title of the second revision was incorrect.'
929929
);
930930
}
931-
932-
/**
933-
* Tests that wp_save_post_revision() ignores an invalid return value
934-
* from the 'wp_save_post_revision_revisions_before_deletion' filter
935-
* and throws _doing_it_wrong().
936-
*
937-
* @ticket 57320
938-
*
939-
* @covers ::wp_save_post_revision
940-
*
941-
* @expectedIncorrectUsage wp_save_post_revision
942-
*/
943-
public function test_wp_save_post_revision_should_ignore_invalid_revisions_before_deletion_filter() {
944-
$post_id = self::factory()->post->create( array( 'post_title' => 'Test 57320' ) );
945-
946-
add_filter(
947-
'wp_revisions_to_keep',
948-
static function() {
949-
return 1;
950-
}
951-
);
952-
953-
add_filter( 'wp_save_post_revision_revisions_before_deletion', '__return_null' );
954-
955-
for ( $update = 1; $update < 4; ++$update ) {
956-
wp_update_post(
957-
array(
958-
'ID' => $post_id,
959-
'post_title' => 'Test 57320 Update ' . $update,
960-
)
961-
);
962-
}
963-
964-
$actual = wp_get_post_revisions( $post_id );
965-
966-
$this->assertCount(
967-
1,
968-
$actual,
969-
'There should only be one revision.'
970-
);
971-
972-
$first = reset( $actual );
973-
974-
$this->assertSame(
975-
'Test 57320 Update 3',
976-
$first->post_title,
977-
'The title of the first revision was incorrect.'
978-
);
979-
}
980931
}

0 commit comments

Comments
 (0)