{"id":375141,"date":"2026-09-24T11:18:48","date_gmt":"2026-09-24T11:18:48","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/revision-retention\/"},"modified":"2026-09-24T12:44:04","modified_gmt":"2026-09-24T12:44:04","slug":"revision-retention","status":"publish","type":"plugin","link":"https:\/\/am.wordpress.org\/plugins\/revision-retention\/","author":16835804,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.1.0","stable_tag":"1.1.0","tested":"7.1.2","requires":"6.7","requires_php":"8.2","requires_plugins":null,"header_name":"Revision Retention","header_author":"Acato","header_description":"Give post revisions a retention policy: keep the newest few, drop the ones older than a threshold, per post type, on a schedule or from WP-CLI.","assets_banners_color":"362a0d","last_updated":"2026-09-24 12:44:04","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/github.com\/acato-plugins\/revision-retention","header_author_uri":"https:\/\/acato.nl","rating":0,"author_block_rating":0,"active_installs":0,"downloads":46,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"1.0.0":{"tag":"1.0.0","author":"acato","date":"2026-09-24 11:18:19","revision":3711158},"1.1.0":{"tag":"1.1.0","author":"acato","date":"2026-09-24 12:44:04","revision":3711295}},"upgrade_notice":[],"ratings":[],"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":3711158,"resolution":"128x128","location":"assets","locale":"","width":128,"height":128},"icon-256x256.png":{"filename":"icon-256x256.png","revision":3711158,"resolution":"256x256","location":"assets","locale":"","width":256,"height":256}},"assets_banners":{"banner-1544x500.png":{"filename":"banner-1544x500.png","revision":3711158,"resolution":"1544x500","location":"assets","locale":"","width":1544,"height":500},"banner-772x250.png":{"filename":"banner-772x250.png","revision":3711158,"resolution":"772x250","location":"assets","locale":"","width":772,"height":250}},"assets_blueprints":{"blueprint.json":{"filename":"blueprint.json","revision":3711297,"resolution":false,"location":"assets","locale":"","contents":"{\"$schema\":\"https:\\\/\\\/playground.wordpress.net\\\/blueprint-schema.json\",\"landingPage\":\"\\\/wp-admin\\\/options-general.php?page=revision-retention\",\"preferredVersions\":{\"php\":\"8.2\",\"wp\":\"latest\"},\"phpExtensionBundles\":[\"kitchen-sink\"],\"steps\":[{\"step\":\"login\",\"username\":\"admin\",\"password\":\"password\"},{\"step\":\"installPlugin\",\"pluginData\":{\"resource\":\"wordpress.org\\\/plugins\",\"slug\":\"revision-retention\"},\"options\":{\"activate\":true}},{\"step\":\"runPHP\",\"code\":\"<?php\\nrequire_once '\\\/wordpress\\\/wp-load.php';\\n\\n\\\/\\\/ A policy that has something to do the moment the screen opens.\\nupdate_option(\\n\\t'rvrt_settings',\\n\\tarray(\\n\\t\\t'keep'                     => 5,\\n\\t\\t'max_age_days'             => 365,\\n\\t\\t'post_types'               => array( 'page' => array( 'max_age_days' => 90 ) ),\\n\\t\\t'enable_revisions'         => array(),\\n\\t\\t'cron_enabled'             => true,\\n\\t\\t'cron_interval'            => 'weekly',\\n\\t\\t'batch_size'               => 200,\\n\\t\\t'remove_data_on_uninstall' => false,\\n\\t)\\n);\\n\\n\\\/\\\/ A history worth looking at: forty revisions of the sample post spread over\\n\\\/\\\/ roughly three years, so the keep floor and the age threshold both bite.\\nforeach ( array( 1 => 40, 2 => 12 ) as $parent => $total ) {\\n\\tif ( ! get_post( $parent ) ) {\\n\\t\\tcontinue;\\n\\t}\\n\\n\\tfor ( $i = 1; $i <= $total; $i++ ) {\\n\\t\\t$days = ( $total - $i ) * 30;\\n\\t\\t$date = gmdate( 'Y-m-d H:i:s', time() - ( $days * DAY_IN_SECONDS ) );\\n\\n\\t\\twp_insert_post(\\n\\t\\t\\tarray(\\n\\t\\t\\t\\t'post_type'         => 'revision',\\n\\t\\t\\t\\t'post_status'       => 'inherit',\\n\\t\\t\\t\\t'post_parent'       => $parent,\\n\\t\\t\\t\\t'post_name'         => $parent . '-revision-v' . $i,\\n\\t\\t\\t\\t'post_title'        => get_the_title( $parent ),\\n\\t\\t\\t\\t'post_content'      => 'Revision ' . $i . ', saved ' . $days . ' days ago.',\\n\\t\\t\\t\\t'post_date'         => $date,\\n\\t\\t\\t\\t'post_date_gmt'     => $date,\\n\\t\\t\\t\\t'post_modified'     => $date,\\n\\t\\t\\t\\t'post_modified_gmt' => $date,\\n\\t\\t\\t)\\n\\t\\t);\\n\\t}\\n}\\n\"}]}"}},"all_blocks":[],"tagged_versions":["1.0.0","1.1.0"],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":3711158,"resolution":"1","location":"assets","locale":"","width":1512,"height":738},"screenshot-2.png":{"filename":"screenshot-2.png","revision":3711158,"resolution":"2","location":"assets","locale":"","width":1568,"height":765},"screenshot-3.png":{"filename":"screenshot-3.png","revision":3711158,"resolution":"3","location":"assets","locale":"","width":1568,"height":765},"screenshot-4.png":{"filename":"screenshot-4.png","revision":3711295,"resolution":"4","location":"assets","locale":"","width":1487,"height":800},"screenshot-5.png":{"filename":"screenshot-5.png","revision":3711295,"resolution":"5","location":"assets","locale":"","width":1487,"height":750}},"screenshots":{"1":"The settings screen, with the policy in force at the top and every post type's rule and stored revisions below it.","2":"Preview reporting what the policy would take from each post, and what each post keeps, before anything is deleted.","3":"The schedule: how often the sweep runs, how many posts it looks at per batch, and the most it may delete in one.","4":"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.","5":"The network's Logs tab, which shows every site's log together and names the site each sweep ran on."}},"plugin_section":[],"plugin_tags":[3786,153,247,2278,6243],"plugin_category":[54,59],"plugin_contributors":[169381,273608],"plugin_business_model":[],"class_list":["post-375141","plugin","type-plugin","status-publish","hentry","plugin_tags-cleanup","plugin_tags-database","plugin_tags-performance","plugin_tags-post-types","plugin_tags-revisions","plugin_category-security-and-spam-protection","plugin_category-utilities-and-tools","plugin_contributors-acato","plugin_contributors-paulacato","plugin_committers-acato"],"banners":{"banner":"https:\/\/ps.w.org\/revision-retention\/assets\/banner-772x250.png?rev=3711158","banner_2x":"https:\/\/ps.w.org\/revision-retention\/assets\/banner-1544x500.png?rev=3711158","banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/revision-retention\/assets\/icon-128x128.png?rev=3711158","icon_2x":"https:\/\/ps.w.org\/revision-retention\/assets\/icon-256x256.png?rev=3711158","generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/revision-retention\/assets\/screenshot-1.png?rev=3711158","caption":"The settings screen, with the policy in force at the top and every post type's rule and stored revisions below it."},{"src":"https:\/\/ps.w.org\/revision-retention\/assets\/screenshot-2.png?rev=3711158","caption":"Preview reporting what the policy would take from each post, and what each post keeps, before anything is deleted."},{"src":"https:\/\/ps.w.org\/revision-retention\/assets\/screenshot-3.png?rev=3711158","caption":"The schedule: how often the sweep runs, how many posts it looks at per batch, and the most it may delete in one."},{"src":"https:\/\/ps.w.org\/revision-retention\/assets\/screenshot-4.png?rev=3711295","caption":"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."},{"src":"https:\/\/ps.w.org\/revision-retention\/assets\/screenshot-5.png?rev=3711295","caption":"The network's Logs tab, which shows every site's log together and names the site each sweep ran on."}],"raw_content":"<!--section=description-->\n<p>WordPress keeps post revisions forever unless you set <code>WP_POST_REVISIONS<\/code>, 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.<\/p>\n\n<p>This plugin gives revisions a retention policy instead:<\/p>\n\n<ul>\n<li><strong>Always keep the newest few.<\/strong> A floor that is never crossed, however old those revisions are.<\/li>\n<li><strong>Remove what is older than a threshold.<\/strong> Anything past the floor and past the age you pick, from a week up to five years.<\/li>\n<li><strong>Set both per post type.<\/strong> Long history for posts, a short leash on pages, nothing at all for a custom post type that churns.<\/li>\n<li><strong>Clean up what is already there.<\/strong> A scheduled sweep works through the site in batches, so an old site with a large <code>wp_posts<\/code> table is cleaned up over several quiet runs rather than one heavy one.<\/li>\n<\/ul>\n\n<h4>The two numbers work together<\/h4>\n\n<p>This is the part worth understanding, because it is what keeps the plugin safe to switch on:<\/p>\n\n<ul>\n<li><strong>Always keep<\/strong> is a floor. The newest N revisions of a post are never deleted, whatever their age.<\/li>\n<li><strong>Remove older than<\/strong> is a ceiling, and it only applies to what is left above the floor.<\/li>\n<\/ul>\n\n<p>So a page that was last edited three years ago, with forty revisions and a policy of <em>keep 5, remove older than 365 days<\/em>, 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.<\/p>\n\n<p>Setting <strong>Always keep<\/strong> to -1 means every revision is retained and that post type is never swept, whatever the age threshold says.<\/p>\n\n<p>Autosaves are never touched. An autosave is somebody's unsaved work rather than a point in the history.<\/p>\n\n<h4>Enable revisions where WordPress does not<\/h4>\n\n<p>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.<\/p>\n\n<h4>On a schedule<\/h4>\n\n<p>The sweep runs in the background at an interval you choose. 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.<\/p>\n\n<p>There are also <strong>Preview<\/strong> and <strong>Run one batch now<\/strong> buttons on the settings screen. Preview reports what the policy would remove without deleting anything.<\/p>\n\n<h4>A log of every sweep<\/h4>\n\n<p>Switch on the log and every sweep that removes revisions gets an entry on the <strong>Logs<\/strong> tab: whether the schedule, somebody on the settings screen, or WP-CLI 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.<\/p>\n\n<p>Each site keeps its own log, next to its own revisions. On multisite the network screen's <strong>Logs<\/strong> 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.<\/p>\n\n<h4>From WP-CLI<\/h4>\n\n<pre><code># What is the policy, and what has it still got to do?\nwp revision-retention status\n\n# The rule and the stored revisions of every post type.\nwp revision-retention post-types\n\n# See what would go, without deleting anything.\nwp revision-retention run --dry-run\n\n# Apply the policy to pages only.\nwp revision-retention run --post-type=page --yes\n<\/code><\/pre>\n\n<h4>On multisite<\/h4>\n\n<p>The network admin sets the defaults for every site, under <strong>Network Admin \u2192 Settings \u2192 Revision Retention<\/strong>. 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.<\/p>\n\n<p>Settings travel the other way too. Once you have a policy on one site that you want everywhere, <strong>Save as network default<\/strong> 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.<\/p>\n\n<p>When the network keeps the policy to itself, a site's screen can still <strong>Preview<\/strong> \u2014 reading what the policy would take away costs nothing \u2014 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.<\/p>\n\n<p>The network screen can <strong>Preview every site<\/strong>, walking the whole network and reporting what the policy would remove without deleting anything, and <strong>Sweep every site now<\/strong>, which books a run on each site that has the scheduled sweep switched on. The sweep itself always runs per site, under whatever policy that site ends up with.<\/p>\n\n<p>Its <strong>Logs<\/strong> 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.<\/p>\n\n<h4>For developers<\/h4>\n\n<pre><code>\/\/ Never touch these posts, whatever the policy says.\nadd_filter( 'revision_retention_excluded_posts', fn( $ids ) =&gt; [ ...$ids, 42, 108 ] );\n\n\/\/ Decide the rule for a post type in code.\nadd_filter( 'revision_retention_rule', function ( $rule, $post_type ) {\n    return 'page' === $post_type ? new Retention_Rule( 20, 90 ) : $rule;\n}, 10, 2 );\n\n\/\/ Change which post types can have a policy at all.\nadd_filter( 'revision_retention_eligible_post_types', $callback );\n<\/code><\/pre>\n\n<p>Deletion goes through <code>wp_delete_post_revision()<\/code> 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.<\/p>\n\n<p>Development happens at <a href=\"https:\/\/github.com\/acato-plugins\/revision-retention\">github.com\/acato-plugins\/revision-retention<\/a>.<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Upload the plugin folder to <code>\/wp-content\/plugins\/<\/code>, or install it through <strong>Plugins \u2192 Add New<\/strong>.<\/li>\n<li>Activate the plugin through the <strong>Plugins<\/strong> screen. On multisite you can network activate it.<\/li>\n<li>Set the policy under <strong>Settings \u2192 Revision Retention<\/strong>, or <strong>Network Admin \u2192 Settings \u2192 Revision Retention<\/strong> on multisite.<\/li>\n<li>Press <strong>Preview<\/strong> to see what the policy would remove before letting it run.<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id=\"will%20this%20delete%20the%20revision%20i%20am%20about%20to%20restore%3F\"><h3>Will this delete the revision I am about to restore?<\/h3><\/dt>\n<dd><p>Not if it is one of the newest ones you asked to keep. The <strong>Always keep<\/strong> floor is applied per post and is never crossed on age. Press <strong>Preview<\/strong> first if you want to see the exact number before anything is deleted.<\/p><\/dd>\n<dt id=\"can%20i%20get%20deleted%20revisions%20back%3F\"><h3>Can I get deleted revisions back?<\/h3><\/dt>\n<dd><p>No. Revisions are deleted the same way WordPress deletes them, permanently. That is why Preview and the <code>--dry-run<\/code> flag exist, and why the plugin ships with a conservative default of keeping the newest five.<\/p><\/dd>\n<dt id=\"does%20it%20touch%20autosaves%3F\"><h3>Does it touch autosaves?<\/h3><\/dt>\n<dd><p>No. Autosaves are excluded from every query the sweep makes.<\/p><\/dd>\n<dt id=\"why%20has%20nothing%20been%20removed%20yet%3F\"><h3>Why has nothing been removed yet?<\/h3><\/dt>\n<dd><p>A sweep only has work to do for a post type with an age threshold. With <strong>Remove older than<\/strong> set to Never the plugin only caps the count on save, which is WordPress's own behaviour, and there is nothing to clean up afterwards. <code>wp revision-retention post-types<\/code> shows the rule in effect for each one.<\/p><\/dd>\n<dt id=\"my%20site%20is%20huge.%20will%20the%20sweep%20time%20out%3F\"><h3>My site is huge. Will the sweep time out?<\/h3><\/dt>\n<dd><p>It works through a configurable number of posts per batch and books the next batch itself, so each run stays short. Lower <strong>Posts per batch<\/strong> if the runs are still too heavy.<\/p><\/dd>\n<dt id=\"i%20enabled%20revisions%20for%20a%20post%20type%20but%20see%20nothing.\"><h3>I enabled revisions for a post type but see nothing.<\/h3><\/dt>\n<dd><p>Revisions start being recorded from the next time such a post is saved. Nothing can recover a history that was never stored.<\/p><\/dd>\n<dt id=\"does%20the%20count%20limit%20work%20without%20the%20sweep%3F\"><h3>Does the count limit work without the sweep?<\/h3><\/dt>\n<dd><p>Yes. The <strong>Always keep<\/strong> number is handed to WordPress through <code>wp_revisions_to_keep<\/code>, so it caps revisions as posts are saved whether or not a sweep ever runs.<\/p><\/dd>\n<dt id=\"where%20are%20the%20translations%3F\"><h3>Where are the translations?<\/h3><\/dt>\n<dd><p>Translations are managed on <a href=\"https:\/\/translate.wordpress.org\/projects\/wp-plugins\/revision-retention\/\">translate.wordpress.org<\/a> and are downloaded by WordPress automatically. The plugin ships a <code>.pot<\/code> template for translators, but no locale files of its own.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>1.1.0<\/h4>\n\n<ul>\n<li>An optional log of every sweep, who ran it and what it removed, shown as a timeline on its own tab.<\/li>\n<li>Log entries are kept for a period you choose, from a week to a year, and older ones are deleted daily.<\/li>\n<li>On multisite, the network screen shows the logs of every site together.<\/li>\n<\/ul>\n\n<h4>1.0.0<\/h4>\n\n<ul>\n<li>Initial release.<\/li>\n<li>Keep the newest N revisions per post, and remove what is older than a threshold.<\/li>\n<li>Per post type overrides for both numbers.<\/li>\n<li>Switch revision support on for post types that ship without it.<\/li>\n<li>Background sweep that works in batches and books its own next run.<\/li>\n<li>WP-CLI commands <code>status<\/code>, <code>post-types<\/code> and <code>run<\/code>, with <code>--dry-run<\/code>.<\/li>\n<li>Network wide defaults with optional per site overrides on multisite, and a way to promote one site's settings to the network.<\/li>\n<\/ul>","raw_excerpt":"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.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/375141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=375141"}],"author":[{"embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/acato"}],"wp:attachment":[{"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=375141"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=375141"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=375141"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=375141"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=375141"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/am.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=375141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}