Make WordPress Core


Ignore:
Timestamp:
02/07/2023 12:38:01 PM (2 years ago)
Author:
audrasjb
Message:

Revisions: Add a way to filter the revisions considered for deletion.

This changeset introduces a new filter for wp_save_post_revision(). wp_save_post_revision_revisions_before_deletion passes the revisions to be considered for deletion, and the new revision's post ID.

This allows extenders to exclude specific revisions from being considered for deletion.

Props jhned, costdev, audrasjb, adamsilverstein, mukesh27.
Fixes #57320.

File:
1 edited

Legend:

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

    r54870 r55254  
    201201    $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
    202202
     203    /**
     204     * Filters the revisions to be considered for deletion.
     205     *
     206     * @since 6.2.0
     207     *
     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.
     211     */
     212    $filtered_revisions = apply_filters(
     213        'wp_save_post_revision_revisions_before_deletion',
     214        $revisions,
     215        $post_id
     216    );
     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    }
     231
    203232    $delete = count( $revisions ) - $revisions_to_keep;
    204233
Note: See TracChangeset for help on using the changeset viewer.