WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 5 months ago

Last modified 4 months ago

#51550 closed enhancement (fixed)

Revisions: Add a post type-specific filter to `wp_revisions_to_keep()`

Reported by: dlh Owned by: adamsilverstein
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: Revisions Keywords: has-patch has-unit-tests needs-dev-note commit
Focuses: Cc:

Description

The attached patch proposes a post type-specific filter for wp_revisions_to_keep() to complement the wp_revisions_to_keep filter.

wp_revisions_to_keep is a perfectly capable filter; the one proposed here offers just some added developer convenience for simpler cases. For example:

add_filter( 'wp_post_revisions_to_keep', fn () => 500 );
add_filter( 'wp_page_revisions_to_keep', '__return_zero' );

Attachments (2)

51550.diff (955 bytes) - added by dlh 12 months ago.
51550.2.diff (2.6 KB) - added by dlh 5 months ago.

Download all attachments as: .zip

Change History (9)

@dlh
12 months ago

#1 @adamsilverstein
6 months ago

Thanks for the patch @dlh - looks good. The only think I would add is a note on the doc block indicating that the filter also overrides the existing wp_revisions_to_keep filter when used.

In addition, some basic unit tests to confirm both of these filters works as expected would be a good addition.

#2 @adamsilverstein
6 months ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

@dlh
5 months ago

#3 @dlh
5 months ago

  • Keywords has-unit-tests added

Thanks for the review, @adamsilverstein!

51550.2.diff updates the docs of the new filter to note its relationship to the existing filter, and it adds tests for the behavior of each filter.

#5 @adamsilverstein
5 months ago

  • Keywords needs-dev-note commit added

#6 @adamsilverstein
5 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 50949:

Revisions: add a new filter for revisions to keep by post type.

Add a new wp_{$post_type}_revisions_to_keep filter that makes it convenient to filter the number of revisions created for a specific post type.

Overrides both the value of WP_POST_REVISIONS and the wp_revisions_to_keep filter.

Props dlh.
Fixes #51550.

#7 @desrosj
4 months ago

  • Milestone changed from Awaiting Review to 5.8
Note: See TracTickets for help on using tickets.