Search by

bloom-ux / revision-policy

felipelavinz

Must-use WordPress plugin to enforce a configurable revision retention policy.

Package info

github.com/bloom-ux/wp-revision-policy

Type:wordpress-muplugin

pkg:composer/bloom-ux/revision-policy

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-11-26 20:49 UTC

This package is auto-updated.

Last update: 2026-11-26 20:54:35 UTC


README

A must-use WordPress plugin that enforces a configurable revision retention policy for posts and pages (and any other post type supporting revisions).

Features

  • Keep a configurable number of recent revisions (default: 99).
  • Optionally keep one revision per month for a configurable number of past months (default: 12).
  • Zero admin UI — all interaction is via WP-CLI.
  • Deferred cleanup — lightweight save_post hook cleans up the edited post automatically.
  • Multisite-aware — WP-CLI commands support targeting specific blogs or every active site in the network.

Requirements

  • PHP >= 8.2
  • WordPress >= 6.0
  • WP-CLI (for CLI commands)

Installation

  1. Copy (or symlink) the plugin directory into your Bedrock web/app/mu-plugins/ folder:

    cp -r bloom-ux-revision-policy /var/www/wordpress/web/app/mu-plugins/
  2. Because it is a must-use plugin, it activates automatically — no WordPress admin activation required.

Configuration

Configuration is done via PHP constants. You can define them in your wp-config.php, config/application.php (Bedrock), or any file loaded before plugins.

Constant Type Default Description
BLOOM_UX_REVISION_KEEP_RECENT int 99 Number of most recent revisions to preserve.
BLOOM_UX_REVISION_KEEP_MONTHLY bool true Enable monthly retention (one revision per month).
BLOOM_UX_REVISION_MONTHLY_MONTHS int 12 How many months back the monthly retention applies.
BLOOM_UX_REVISION_POST_TYPES array or comma-separated string null (all revision-supporting post types) Limit the policy to specific post types.

Examples

// Keep 50 recent revisions and disable monthly retention.
define( 'BLOOM_UX_REVISION_KEEP_RECENT', 50 );
define( 'BLOOM_UX_REVISION_KEEP_MONTHLY', false );

// Keep 99 recent + 24 months of monthly snapshots.
define( 'BLOOM_UX_REVISION_KEEP_RECENT', 99 );
define( 'BLOOM_UX_REVISION_KEEP_MONTHLY', true );
define( 'BLOOM_UX_REVISION_MONTHLY_MONTHS', 24 );

// Apply only to posts and pages.
define( 'BLOOM_UX_REVISION_POST_TYPES', [ 'post', 'page' ] );
// or as a comma-separated string:
define( 'BLOOM_UX_REVISION_POST_TYPES', 'post,page' );

Note: If no constants are defined, the plugin works out-of-the-box with the hardcoded defaults above.

WP-CLI Commands

All commands live under wp revision-policy.

clean

Apply the retention policy and delete excess revisions.

# Clean all eligible posts.
wp revision-policy clean

# Preview what would be deleted without actually deleting.
wp revision-policy clean --dry-run

# Limit to a specific post type.
wp revision-policy clean --post-type=page

# Target a specific site in a multisite network.
wp revision-policy clean --blog-id=5

# Run against all active sites in the network.
wp revision-policy clean --network

# Preview a network-wide cleanup.
wp revision-policy clean --network --dry-run

stats

Show current revision counts.

# Stats for all eligible post types.
wp revision-policy stats

# Stats for a single post type.
wp revision-policy stats --post-type=page

# Stats for a specific site in a multisite network.
wp revision-policy stats --blog-id=5

# Stats for every active site in the network.
wp revision-policy stats --network

How It Works

  1. Recent revisions — The plugin always preserves the N most recent revisions (where N is configurable, default 99).
  2. Monthly snapshots — If enabled, for each of the last M months (default 12), the plugin keeps the last revision created in that month.
  3. Everything else is deleted — Any revision that does not fall into the categories above is removed.
  4. Deferred cleanup — Every time a post is saved, the plugin schedules a lightweight cleanup for that specific post so the database does not grow unbounded between manual CLI runs.

Architecture

web/app/mu-plugins/bloom-ux-revision-policy/
├── bloom-ux-revision-policy.php   # Bootstrap & autoloader
├── composer.json
├── README.md
└── src/
    ├── Config.php                 # Reads constants & resolves post types
    ├── Cleaner.php                # Retention logic & database queries
    └── CLI_Command.php            # WP-CLI command registration

License

GPL-2.0-or-later