Advanced WordPress Management Using WP-CLI on Alibaba Cloud ECS — Part 2

1. Manage Plugins & Themes with WP-CLI

WP-CLI contains a wealth of commands to manage the plugins and themes on your site. If you manage many sites, these can be provide a real boost to your productivity.

$ wp theme update twentyseventeen
$ wp theme search <word to search by>
$ wp theme install <theme>
$ wp theme activate <theme>
$ wp theme deactivate <theme>
$ wp theme delete <theme>
$ wp theme update --all

2. Perform Database operations

As mentioned previously, WP-CLI allows us to perform operations on our WordPress database from the command line.

$ wp db export backup.sql
$ wp db import backup.sql
$ wp db optimize
$ wp db repair

3. Manage your WordPress Media

I don’t think I’ve every heard any WordPress developer profess their love for the WordPress media manager. In general, the administrative tasks involving images and media are considered the least efficient, and the Media Manager is generally regarded as poorly devised.

$ media import --title=“Image Title” --caption=“Image Caption” --alt=“Image alt text” --post_id=7 --featured_image

4. Use WP Eval to combine WP-CLI with PHP

The real power of WP-CLI comes in when you combine commands together. An example of this is using the ‘wp media regenerate’ command in combination with the ‘wp eval’ command. WP eval allows us to run any PHP code within our WP-CLI commands, that means we can combine WP-CLI commands with WordPress and other PHP functions.

5. Manage WordPress Users & Roles

Manage WordPress Users

6. Manage User Roles and Capabilities

Why don’t we create a new Teacher role? That is also very easy, but first it’s a good idea to check to make sure the Role doesn’t already exist.

7. The WP-CLI Configuration File

WP-CLI allows you to set configure default parameters either on a global level or on a per project directory level.

# Global Parameter Defaults
- db drop
# Subcommand Defaults
config create:
dbuser: new_user
dbprefix: nu_

8. Using Aliases for convenience

At the moment, when we want to work on a WordPress site on our instance, we need to login to the server and change into the site’s root directory to issue the WP-CLI commands. This process severely lessens any efficiencies gained from using WP-CLI.

# Aliases
path: /var/www/
path: /var/www/
$ cd ~
$ wp @example plugin list
$ wp @another plugin list

9. Automate tasks with WP-CLI & Cron Jobs

When managing WordPress sites, there are often tasks which need to be schedule to run regularly. One such task, mentioned earlier, is the automated backup of your WordPress database on a schedule.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website: