Cleanup with the WP-CLI

Developer Knowledge Level

This content is intended for WordPress developers, and it may require coding knowledge of WordPress, PHP, and JavaScript. Code examples provided here may contain errors or needs some additional coding. Make sure to test the code before using it on a live website!

SweepPress, both Lite/Free and Pro versions, includes support for running sweeping tasks via WP-CLI. The plugin registers one main CLI command sweeppress and several subcommands. For the main command and all subcommands, you can use the WP-CLI help command to get more information and usage examples.

SweepPress command and subcommands all support various global parameters WP-CLI implements, and these are listed in WP-CLI documentation and via help command WP-CLI uses.

WP-CLI

To learn more about WP-CLI, check out the official website of the WP-CLI project, including information about installing the WP-CLI, using it and more. If you are not sure what CLI is, or how to use it, this article is not for you!

Getting started with the command

wp sweeppress

And you will get the list of available subcommands.

WP-CLI: Commands List

WP-CLI has additional helpful notes about the usage, so check out some of the responses to get more information. Make sure to also use the help command to get more information.

Subcommands

List

Subcommand list will show all available sweepers (sweepers that don’t have anything to sweep are not listed), with the number of tasks and estimated number of records for removal, and the total estimated size for removal.

WP-CLI: Subcommand List

This command has one more use: list individual tasks for each sweeper by adding the sweeper’s name to the list command sequence. You should use task names from the first list results table.

WP-CLI: Subcommand List Task

So, if you get results for a task that has post types, like the example above, you will see in individual post types as tasks.

Auto

This subcommand will run all available sweepers and will return sweeping results. This subcommand will not run every available sweeper! Some sweepers must be run only manually to avoid running them too often (some sweepers can be demanding). Here are the typical results returned by this subcommand.

WP-CLI: Subcommand Auto Results

The results are displayed with the same format for all other sweeper subcommands, showing basic status information, records removed, space recovered, sweepers and tasks, and a quick overview of all run sweepers’ status. Again, the records removed and space recovered are estimated values because it is impossible to actually get the exact state of the database due to the caching and other optimizations done by the database server.

Sweep

This subcommand allows you to run one or more sweepers listed in the command sequence, and it will run all available tasks for listed sweepers. Each sweeper is listed with the space separation like this:

wp sweeppress sweep <sweeper-name> <sweeper-name> <sweeper-name> ...

WP-CLI: Subcommand Sweeper

Sweeper

This final sweeping subcommand allows you to run a single sweeper with one or more tasks as arguments. The sweeper is a required argument, and you need to specify one or more tasks by task name (again, consult the results from the list subcommand).

wp sweeppress sweeper sweeper-name <task-name> <task-name> ...

WP-CLI: Subcommand Sweeper Tasks

In the future, it is possible that more settings and subcommands will be added to enhance the process further.

Rate this article
0
0
19

You are not allowed to rate this post.

Leave a Comment