WP site management using WP-CLI from scratch

Submitted by galactus on Sun, 07/28/2019 - 20:33

This is a sneak view of my presentation on the upcoming WordCamp Iloilo.

WP-CLI might sound a bit scary for others that haven't tried to use CLI or heard it before. It is not really scary it is actually fun to use!

You might have been thinking what CLI stands for and what WP means?

CLI stands for Command Line InterfaceWiki says:

command-line interface (CLI) is a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). The program which handles the interface is called a command-line interpreter or command-line processor, or shell.

In my own interpretation, CLI is a set of command that is used to manage a site and make less interaction in the browser. It eliminates the number of clicks in the site configuration. The number of clicks can be equivalent to one single WP-CLI command.

Enough for introduction let's get started.

System Requirements

  • UNIX-like environment (OS X, Linux, FreeBSD, Cygwin)
  • PHP 5.4 or greater
  • WordPress 3.7 or greater

Installing

  1. Download wp-cli.phar using wget or curl

    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

     

  2. Verify if wp-cli.phar is working.

    php wp-cli.phar --info

     

  3. Make wp-cli executable globally.

    chmod +x wp-cli.phar
    sudo mv wp-cli.phar /usr/local/bin/wp

Updating

To update WP-CLI:

wp cli update

Basic WP-CLI commands

  1. Check WP-CLI version: 

    wp --version

     

  2. Check WordPress version:

    wp core version

     

  3. Flush the object cache:

    wp cache flush

     

  4. Tests the WP Cron spawning system and reports back its status.

    wp cron test

     

  5. Installing plugin 

    wp plugin install <plugin-name>

     

  6. Updating plugin

    wp plugin update <plugin-name>

     

  7. Activating plugin

    wp plugin activate <plugin-name>

     

  8. Deactivating plugin

    wp plugin deactivate <plugin-name>

     

  9. List plugins

    wp plugin list

     

  10. List users

    wp user list [--role=administrator,editor]

These are just a few examples of command that you can use in managing your WordPress site, there's a lot of commands out there that you can use. Follow me at WordCamp Iloilo to learn more: https://2019.iloilo.wordcamp.org/speakers/#wcorg-speaker-roald-umandal

Presentation link: https://www.slideshare.net/umandalroald/session-wp-site-management-using-wpcli-from-scratch

Tags