
How to manage WordPress, plugins & themes with WP-CLI
There is a command-line interface for WordPress called WP-CLI.
Update plugins, configure multisite installations, and more, without having to open a web browser.
Requirements of WP-CLI
In order to install WP-CLI, you will need SSH access. Most shared hosting providers do not allow SSH access, however, the QuickHostUK web hosting packages do allow this. If you enjoy spinning up your own servers, we also offer Cloud-based VPS.
There are also a few basic requirements:
- PHP 5.3.2 or later.
- WordPress 3.4 or later.
- UNIX like environment such as Linux.
How to Install WP-CLI
Start by connecting to your server’s command line via SSH. Using cURL or wget, you can install the latest version of WP-CLI. The latest version of the WP-CLI installation file can be found at:
https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Download the file using the cURL command:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Our next step is to make it executable by setting the permissions. Type the following command:
chmod +x wp-cli.phar
For those who use their own server, they can move wp-cli.phar into their bin folder and rename it to wp. You can then use the WP-CLI commands just by typing ‘wp’ at the beginning of the command.
mv wp-cli.phar /usr/local/bin/wp
That’s it! You can now use many of the WP-CLI commands.
Basic WP-CLI Commands
We’ll cover the basic WP-CLI commands very briefly. More commands can be found here.
Using the WP-CLI Help System
By typing “wp help”, you will be able to access a comprehensive help system for WP-CLI.
php wp-cli.phar help
Or, if you moved the file to the bin directory as above:
wp help
NAME
wp
DESCRIPTION
Manage WordPress through the command-line.
SYNOPSIS
wp <command>
SUBCOMMANDS
cache Adds, removes, fetches, and flushes the WP Object Cache object.
cap Adds, removes, and lists capabilities of a user role.
cli Reviews current WP-CLI info, checks for updates, or views defined aliases.
comment Creates, updates, deletes, and moderates comments.
config Generates and reads the wp-config.php file.
core Downloads, installs, updates, and manages a WordPress installation.
cron Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
db Performs basic database operations using credentials stored in wp-config.php.
embed Inspects oEmbed providers, clears embed cache, and more.
eval Executes arbitrary PHP code.
eval-file Loads and executes a PHP file.
export Exports WordPress content to a WXR file.
help Gets help on WP-CLI, or on a specific command.
i18n Provides internationalization tools for WordPress projects.
import Imports content from a given WXR file.
language Installs, activates, and manages language packs.
maintenance-mode Activates, deactivates or checks the status of the maintenance mode of a site.
media Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
menu Lists, creates, assigns, and deletes the active theme's navigation menus.
network Perform network-wide operations.
option Retrieves and sets site options, including plugin and WordPress settings.
package Lists, installs, and removes WP-CLI packages.
plugin Manages plugins, including installs, activations, and updates.
post Manages posts, content, and meta.
post-type Retrieves details on the site's registered post types.
rewrite Lists or flushes the site's rewrite rules, updates the permalink structure.
role Manages user roles, including creating new roles and resetting to defaults.
scaffold Generates code for post types, taxonomies, plugins, child themes, etc.
search-replace Searches/replaces strings in the database.
server Launches PHP's built-in web server for a specific WordPress installation.
shell Opens an interactive PHP console for running and testing PHP code.
Installing WordPress with WP-CLI
It is easy to install WordPress using the WP-CLI command wp core install on your server if you haven’t already done so. This command requires parameters, such as URL, Title, Administrator Username, Password, and Administrator Email.
wp core install --url="your_domain" --title="Blog Title" --admin_user="admin username" --admin_password="enter_your_password" --admin_email="enter_your_email"
Installing Themes with WP-CLI
Using WP-CLI makes it much faster to import and install themes than going into WordPress admin, searching, and then activating.
Using it, you can import a theme directly from the WordPress theme repository. The following command, for example, will install a theme like TwentyTen:
wp theme install twentyten
It is necessary to use the following command in order to activate the theme on your WordPress website:
wp theme activate twentyten
Installing Plugins with WP-CLI
Plugins can also be installed directly from the official repository, just like themes. The process is simple and takes very little time.
For example, we can install WooCommerce like so:
wp plugin install woocommerce
Your website will now have the WooCommerce plugin after running the above command. We will activate it using the following command:
wp plugin activate woocommerce
To deactivate any plugin, the command becomes:
wp plugin deactivate woocommerce
Updating WordPress Core, Themes and Plugins with WP-CLI
You can easily update the WordPress core, themes, and plugins through the command line.
You can update the WordPress core to the latest stable release by running the following command:
wp core update
Using the following command, you can update WordPress to a specific version, for example, WordPress 5.7, instead of WordPress 5.8.
wp core update --version=5.7
In the event that you want to revert back the WordPress version, the command is:
wp core update --version=5.6 --force
Update plugins either by defining one plugin to update or by updating all of them in one go.
wp plugin update woocommerce
- or -
wp plugin update --all
The same applies to the themes. The following command updates WordPress themes through WP-CLI:
wp theme update twentyten
- or -
wp theme update --all
You can manage your WordPress sites using WP-CLI via the command line, and it is a powerful tool. You can also manage your database, take backups, manage posts, comments, and manage multiple WordPress sites. It definitely speeds up your tasks and makes managing multiple sites easier. WP-CLI is included by default with QucikHostUK’s web hosting packages.