跳到内容

Revision Retention

v1.8.0

Acato · 2026年9月24日 上架

Keep the newest revisions of every post and drop the ones older than a threshold you set. Per post type, on a schedule or from WP-CLI.

正在使用
10 以下
评分
暂无
累计下载
1,334
最近更新
2026年11月18日
需要 WordPress 6.7+已测试到 7.1.5PHP 8.2+

截图

The settings screen, with the policy in force and the time until the next sweep at the top, and every post type's rule and stored revisions below it.
The settings screen, with the policy in force and the time until the next sweep at the top, and every post type's rule and stored revisions below it.
Preview reporting what the policy would take from each post, and what each post keeps, before anything is deleted.
Preview reporting what the policy would take from each post, and what each post keeps, before anything is deleted.
The schedule: on which days and at what time the sweep runs, whether WP-Cron is running, how many posts it looks at per batch, and the most it may delete in one.
The schedule: on which days and at what time the sweep runs, whether WP-Cron is running, how many posts it looks at per batch, and the most it may delete in one.
The log as a timeline: a bar per day for the last month, and every sweep with who ran it, what it removed per post type, and whether it finished.
The log as a timeline: a bar per day for the last month, and every sweep with who ran it, what it removed per post type, and whether it finished.
The network's Logs tab, which shows every site's log together and names the site each sweep ran on.
The network's Logs tab, which shows every site's log together and names the site each sweep ran on.
The Dashboard widget: the sweeps of the last days, weeks or months, for this site or the whole network, and when the next one is due.
The Dashboard widget: the sweeps of the last days, weeks or months, for this site or the whole network, and when the next one is due.

WordPress keeps post revisions forever unless you set WP_POST_REVISIONS, and even then the only thing you can set is a count that applies to the whole site and only takes effect while a post is being saved. A site that has been running for a few years ends up with tens of thousands of revisions nobody will ever open, slowing down queries and padding out every backup.

This plugin gives revisions a retention policy instead:

  • Always keep the newest few. A floor that is never crossed, however old those revisions are.
  • Remove what is older than a threshold. Anything past the floor and past the age you pick, from a week up to five years.
  • Set both per post type. Long history for posts, a short leash on pages, nothing at all for a custom post type that churns.
  • Clean up what is already there. A scheduled sweep works through the site in batches, so an old site with a large wp_posts table is cleaned up over several quiet runs rather than one heavy one.

The two numbers work together

This is the part worth understanding, because it is what keeps the plugin safe to switch on:

  • Always keep is a floor. The newest N revisions of a post are never deleted, whatever their age.
  • Remove older than is a ceiling, and it only applies to what is left above the floor.

So a page that was last edited three years ago, with forty revisions and a policy of keep 5, remove older than 365 days, keeps its five most recent revisions and loses the other thirty-five. It does not lose its whole history just because all of it is old.

Setting Always keep to -1 means every revision is retained and that post type is never swept, whatever the age threshold says.

Autosaves are never touched. An autosave is somebody’s unsaved work rather than a point in the history.

Enable revisions where WordPress does not

Some post types ship without revision support, so nothing is recorded at all. The settings screen lists every eligible post type with a checkbox to switch revisions on for it. It applies from the next time such a post is saved.

On a schedule

The sweep runs in the background at an interval you choose, from every hour to once a month, or on the days of the week you tick: once at the hour you pick, say Monday and Wednesday at 03:00 in the site’s timezone, or every hour or every few hours from that hour until midnight. Every run books the next one itself: another batch in a minute while there is work left, or the next full run at your interval once the site is clean. A sweep that gets interrupted continues where it stopped instead of starting over.

There are also Preview and Run one batch now buttons on the settings screen. Preview reports what the policy would remove without deleting anything.

A log of every sweep

The log is on from the start, and every sweep that removes revisions gets an entry on the Logs tab: whether the schedule, somebody on the settings screen, WP-CLI or the plugin’s run-sweep ability ran it, who that was, how many revisions it removed from how many posts, and per post type. A sweep spread over many batches is one entry. The tab shows them on a timeline, with a bar per day for the last month. Entries are kept for as long as you choose, from a week to a year, and older ones are deleted daily. Previews are never logged, and the log can be switched off on the Logs tab.

Each site keeps its own log, next to its own revisions. On multisite the network screen’s Logs tab shows every site’s log together on one timeline, with each entry naming the site it ran on and linking to that site’s own log.

A walkthrough of the settings

A short walkthrough shows you around the settings screen: the numbers at the top, the policy, the post types, the schedule, sweeping now, the log, with an example of a log entry, and the Dashboard widget. It never starts by itself. Start it from the Start walkthrough link beside Settings on the Plugins screen, tagged New while there is something you have not seen, or from the link at the foot of the settings screen. After an update that adds to the screen, the link on the Plugins screen shows only what is new.

Don’t want it? Switch off Walkthrough on the Advanced tab, for a site or for the whole network, and both links go. In code, define( 'RVRT_DISABLE_WALKTHROUGH', true ); or the revision_retention_walkthrough filter does the same.

Light, dark and high contrast

The settings screen, the Dashboard widget and the walkthrough follow the contrast setting of the system: more contrast, less contrast, or Windows High Contrast and other forced colours. On its own settings screen the plugin also follows the system’s dark mode, the whole page included. Text meets WCAG 2.2 AA contrast in every one of them, on every admin colour scheme.

From WP-CLI

# What is the policy, and what has it still got to do?
wp revision-retention status

# The rule and the stored revisions of every post type.
wp revision-retention post-types

# See what would go, without deleting anything.
wp revision-retention run --dry-run

# Apply the policy to pages only.
wp revision-retention run --post-type=page --yes

On multisite

The network admin sets the defaults for every site, under Network Admin Settings Revision Retention. A switch there decides whether sites may override them. When they may, each site’s own screen inherits every field it leaves empty and shows the network value behind it; when they may not, that screen reports the policy and nothing more.

Settings travel the other way too. Once you have a policy on one site that you want everywhere, Save as network default on that site’s screen makes it the default for the whole network and drops the site’s own copy, so the site simply inherits what it already had. Sites with settings of their own keep them; only the defaults underneath move. The button only appears for a network administrator, since it decides what every other site starts from.

When the network keeps the policy to itself, a site’s screen can still Preview — reading what the policy would take away costs nothing — but only a network administrator can actually sweep that site. Otherwise a network could switch the scheduled sweep off and a site administrator could still delete by hand, which is the opposite of what locking the policy is for.

The network screen can Preview every site, walking the whole network and reporting what the policy would remove without deleting anything, Sweep every site now, which does the same and deletes as it goes, site after site, with a progress bar and an entry in each site’s log, and Schedule a sweep on every site, which leaves the work to WP-Cron on each site instead. Both pass over the sites that have switched the sweep off. The sweep itself always runs per site, under whatever policy that site ends up with.

Its Logs tab brings the log of every site together, so you can see what was removed across the network, where, and by whom, without opening each site in turn.

For developers

// Never touch these posts, whatever the policy says.
add_filter( 'revision_retention_excluded_posts', fn( $ids ) => [ ...$ids, 42, 108 ] );

// Decide the rule for a post type in code.
add_filter( 'revision_retention_rule', function ( $rule, $post_type ) {
    return 'page' === $post_type ? new Retention_Rule( 20, 90 ) : $rule;
}, 10, 2 );

// Change which post types can have a policy at all.
add_filter( 'revision_retention_eligible_post_types', $callback );

Abilities (WordPress 7.1)

On WordPress 7.1 and later the plugin registers its work with the Abilities API, in the revision-retention category:

  • revision-retention/get-status: revisions stored, the policy, the next sweep, whether WP-Cron runs, and where the current sweep stands.
  • revision-retention/get-post-types: per post type, the revisions it stores and the rule that applies to it.
  • revision-retention/preview-sweep: what a sweep would remove, per post type, without deleting anything.
  • revision-retention/get-sweep-log: the most recent sweeps, where each came from and what it removed.
  • revision-retention/run-sweep: removes one batch of revisions now, under the same rules as Run one batch now, and is logged as such.

They work on the current site and ask for manage_options, the capability that also opens the settings screen; on a network that keeps the policy to itself, run-sweep is for network administrators only. They are not public and not on the REST API, so only code running on the site can call them, and none of them returns who ran a sweep, user IDs or post titles.

$status = wp_get_ability( 'revision-retention/get-status' )->execute();

Deletion goes through wp_delete_post_revision() rather than a bulk query, so post meta and term relationships are cleaned up the way WordPress expects and other plugins see the hooks they are listening for.

Development happens at github.com/acato-plugins/revision-retention.

Plums

按场景查找 WordPress 插件。安装量、评分和兼容版本来自官方目录。

导航

说明

WordPress 是 WordPress Foundation 的商标。本站与 WordPress Foundation、Automattic 没有隶属关系。这里不托管插件文件,下载和安装以 WordPress.org 上的页面为准。

© 2026 Plums