WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 4 days ago

#51550 assigned enhancement

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

Reported by: dlh Owned by: adamsilverstein
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Revisions Keywords: has-patch has-unit-tests
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 7 months ago.
51550.2.diff (2.6 KB) - added by dlh 4 days ago.

Download all attachments as: .zip

Change History (5)

@dlh
7 months ago

#1 @adamsilverstein
2 weeks 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
2 weeks ago

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

@dlh
4 days ago

#3 @dlh
4 days 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.

Note: See TracTickets for help on using tickets.