All Projects → stevegrunwell → revision-strike

stevegrunwell / revision-strike

Licence: MIT license
Periodically purge old post revisions via WP Cron.

Programming Languages

PHP
23972 projects - #3 most used programming language
Gherkin
971 projects

Projects that are alternatives of or similar to revision-strike

ds-cli
DS-CLI is now a core runtime component of DesktopServer (https://serverpress.com). This project is an ensemble of the latest command line interface tools such as Composer, PHPUnit, WP-CLI, and other cross-platform components that are important to professional WordPress developers.
Stars: ✭ 19 (+0%)
Mutual labels:  wp-cli
wordpress-project
Generic project structure for WordPress website industrialisation.
Stars: ✭ 28 (+47.37%)
Mutual labels:  wp-cli
wp-cli-dev
🛠 WP-CLI development environment that allows for easy development across all packages
Stars: ✭ 29 (+52.63%)
Mutual labels:  wp-cli
server-command
Launches PHP's built-in web server for a specific WordPress installation.
Stars: ✭ 69 (+263.16%)
Mutual labels:  wp-cli
wp-cli-seed-command
WP CLI Seed Command is extension for WP-CLI to seed database with sample data
Stars: ✭ 20 (+5.26%)
Mutual labels:  wp-cli
checksum-command
Verifies file integrity by comparing to published checksums.
Stars: ✭ 29 (+52.63%)
Mutual labels:  wp-cli
Wp Cli Login Command
Log in to WordPress with secure passwordless magic links.
Stars: ✭ 200 (+952.63%)
Mutual labels:  wp-cli
jw-wpcli-random-posts
A robust random post generator for WP CLI which supports multisite, post types, post counts, taxonomies, terms, term counts and featured images. Complete with a cleanup command to undo it all!
Stars: ✭ 58 (+205.26%)
Mutual labels:  wp-cli
WordPress-Distribution
This repository helps you to get a local new and fresh WordPress for everything you want (e.g. Developing, Testing, etc.).
Stars: ✭ 16 (-15.79%)
Mutual labels:  wp-cli
import-command
Imports content from a given WXR file.
Stars: ✭ 19 (+0%)
Mutual labels:  wp-cli
pine
pine - A CLI installer for timber
Stars: ✭ 29 (+52.63%)
Mutual labels:  wp-cli
scaffold-command
Generates code for post types, taxonomies, blocks, plugins, child themes, etc.
Stars: ✭ 149 (+684.21%)
Mutual labels:  wp-cli
wp-cli-build
Fetch specific versions of plugins/themes from wordpress.org using a build file
Stars: ✭ 45 (+136.84%)
Mutual labels:  wp-cli
regolith
A WordPress installation template that's a little bit looser than Bedrock
Stars: ✭ 24 (+26.32%)
Mutual labels:  wp-cli
trellis-sync
Trellis Database and Uploads Folder Synchronisation scripts and example WP CLI Aliases
Stars: ✭ 27 (+42.11%)
Mutual labels:  wp-cli
Wplib Box
The Best Local Dev Server for WordPress Developers
Stars: ✭ 204 (+973.68%)
Mutual labels:  wp-cli
bedrock-wordpress-docker
Dockerized Wordpress using Bedrock
Stars: ✭ 36 (+89.47%)
Mutual labels:  wp-cli
export-command
Exports WordPress content to a WXR file.
Stars: ✭ 12 (-36.84%)
Mutual labels:  wp-cli
i18n-command
Provides internationalization tools for WordPress projects.
Stars: ✭ 76 (+300%)
Mutual labels:  wp-cli
media-command
Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
Stars: ✭ 40 (+110.53%)
Mutual labels:  wp-cli

Revision Strike

Build Status Code Climate Test Coverage

Unless post revisions are explicitly limited, WordPress will build up a hefty sum of revisions over time. While it's great to have revision history for some recent content, the chances that old revisions will be necessary diminish the longer a post has been published. Revision Strike is designed to automatically remove these unneeded revisions on older, published posts.

How does it work?

First, a threshold is set, with a default of 30 days. Once a day, Revision Strike will run and find any post revisions in the database attached to published posts with a post date of at least 30 (or your custom threshold) days ago, and "strike" (tear-down and remove) them from the WordPress database.

Usage

There are a number of ways to interact with Revision Strike:

WP Cron

Upon plugin activation, a hook is registered to trigger the revisionstrike_strike_old_revisions action daily, which kicks off the striking process. This hook is then automatically removed upon plugin deactivation.

The WP Cron method is great for ongoing maintenance, but when you manually need to purge larger amounts of revisions…

Tools › Revision Strike

The Tools > Revision Strike page

You can manually trigger a revision strike by logging into WordPress and visiting the Tools › Revision Strike page.

Note: You must have the "edit_others_posts" capability (typically "Editor"-level and above) in order to see this page.

WP-CLI

If you make use of WP-CLI on your site you may trigger Revision Strike with the following commands:

$ wp revision-strike <command>

clean

Manually runs an instance of Revision Strike, removing revisions matching the passed arguments or defaulting to the values declared on the Settings › Writing page.

Arguments
--days=<days>
Remove revisions on posts published at least <days> day(s) ago. This is determined by the value set on Settings › Writing or a default of 30.
--limit=<limit>
The maximum number of revisions to remove. This is determined by the value set on Settings › Writing or a default value of 50.
--post_type=<post_type>
One or more post types (comma-separated) for which revisions should be struck. Default value is 'post'.
--verbose
Enable verbose logging of deleted revisions.

clean-all

If you have a large number of revisions, it can take Revision Strike some time to work its way through your post history to clean up revisions on a daily basis. The clean-all command is like spring cleaning, systematically removing eligible post revisions all at once, giving you a nice, clean revision history to start from, making it easy for the daily cron runner to maintain.

Under the hood, this command just determines how many eligible revisions are in the database, then calls the clean command with your arguments and a limit equal to the number of revisions in the database. Thanks to the revision chunking (#17), no more than 50 post revisions are being handled in memory at any given time, ensuring minimal performance impact on your site.

Arguments
--days=<days>
Remove revisions on posts published at least <days> day(s) ago. This is determined by the value set on Settings › Writing or a default of 30.
--post_type=<post_type>
One or more post types (comma-separated) for which revisions should be struck. Default value is 'post'.
--verbose
Enable verbose logging of deleted revisions.

Hooks

Revision Strike leverages the WordPress Plugin API to let you customize its behavior without editing the codebase directly.

Filter: revisionstrike_post_types

Controls the post types for which revisions should be automatically be purged.

(string) $post_types
A comma-separated list of post types.

Example

By default, Revision Strike only works against posts of the "Post" post type. If you'd like to include other post types (pages, custom post types, etc.), this filter will allow you do so.

/**
 * Include the "page" and "book" custom post type in Revision Strike.
 *
 * @param string $post_type A comma-separated list of post types.
 */
function theme_set_post_types( $post_types ) {
	return 'post,page,book';
}
add_filter( 'revisionstrike_post_types', 'theme_set_post_types' );

Filter: revisionstrike_get_revision_ids

Filter the list of eligible revision IDs.

(array) $revision_ids
Revision IDs to be struck.
(int) $days
The number of days since a post's publish date that must pass before we can purge the post revisions.
(int) $limit
The maximum number of revision IDs to retrieve.
(array) $post_type
The post types for which revisions should be located.

Filter: revisionstrike_capabilities

Sets capabilities to access Revision Strike managment page.

Example

By default, Revision Strike sets required capabilities to access plugin managment page as edit_others_posts. You can use this filter to change this in order to have more control on who can access it.

/**
 * Sets capabilities to access Revision Strike settings page.
 */
function rs_capabilities() {
	return 'manage_options';
}
add_filter( 'revisionstrike_capabilities', 'rs_capabilities' );

Contributing

All development dependencies for the plugin are installed via Composer. After installing Composer on your system, navigate your terminal session to the plugin directory and run:

$ composer install

Pull requests on this plugin are welcome, but I ask that you please follow these guidelines:

Integration tests

There are a few integration tests for the plugin, written using Behat and scaffolded using wp scaffold package-tests. If you'd like to contribute to these tests, please install the WP CLI Testing framework:

$ bin/install-package-tests.sh
$ vendor/bin/behat
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].