Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#51550 closed enhancement (fixed)

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

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


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 4 years ago.
51550.2.diff (2.6 KB) - added by dlh 3 years ago.

Download all attachments as: .zip

Change History (9)

4 years ago

#1 @adamsilverstein
3 years 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
3 years ago

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

3 years ago

#3 @dlh
3 years 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
3 years ago

  • Keywords needs-dev-note commit added

#6 @adamsilverstein
3 years 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
3 years ago

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