Make WordPress Core

Changeset 55406


Ignore:
Timestamp:
02/22/2023 08:47:38 PM (12 months ago)
Author:
johnbillion
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/revision.php

    r55398 r55406  
    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    );
    217 
    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     }
    231216
    232217    $delete = count( $revisions ) - $revisions_to_keep;
  • trunk/tests/phpunit/tests/post/revisions.php

    r55254 r55406  
    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}
Note: See TracChangeset for help on using the changeset viewer.