Skip to main content

How to use WP-Optimize from the command line

We’ve added WP-CLI support to our WP-Optimize Premium plugin.

WP-CLI is the command-line interface for WordPress that allows you to do all kinds of things, such as updating plugins and configuring multisite installs, without using a web browser.

Including it in WP-Optimize Premium means that you will now be able to run optimization commands directly on command-line. During this operation, WP-Oprtimize will perform in exactly the same way, but it will produce a detailed output on screen to show you what’s happening.

This feature is mainly for the experienced user, but it’s easy enough for anyone to set up and run.

Here’s how it works

  1. Before running an optimization, you will need to gather a list of optimizations available to you on command-line. To do this, you will need to run the following:
wp optimize optimizations

This will bring out the list of optimizations, as below:

CommandFunction
optimizetablesOptimise database tables
revisionsClean all post revisions
trashClean all trashed posts
spamRemove spam and binned comments
unapprovedRemove unapproved comments
attachmentsRemove orphaned attachments
transientRemove expired transient options
pingbacksRemove pingbacks
trackbacksRemove trackbacks
postmetaClean post meta data
commentmetaClean comment meta data
orphandataClean orphaned relationship data
CommandFunction
versionTo return the current WP-Optimize version
optimizationDisplays a full list of commands (as seen up above) to optimize
do-optimization --optimization-id=Running the selected optimization
--path=Add this just after wp to specify the WordPress install e.g. wp --path=/var/www/html/work/multisite optimize do-optimization --optimization-id=orphandata