First, what is WP-CLI?

WP-CLI (maintain by Alain Schlesser) is the command-line interface for WordPress.

It provides a command-line interface for many actions you might perform in the WordPress admin.

With WP-CLI, you can update plugins, configure multisite installs and much more, without using a web browser.

Recommended Method To Install WP-CLI

The recommended way to install WP-CLI is by downloading the Phar build (archives similar to Java JAR files, marking it executable, and placing it on your PATH.

PHP CLI is already installed and you can proceed with the next step.

  1. Ensure that your web hosting package has SSH/SFTP access enabled.
  2. Download wp-cli.phar using either wget or curl.
    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

    You might be interested in Everything curl, a detailed and totally free book available in several formats, that explains basically everything there is to know about curl, libcurl and the associated project.

  3. Check if it works:
    php wp-cli.phar --info
  4. Make the file executable:
    chmod +x wp-cli.phar

    If you are a VPS or dedicated server customer, you can achieve the same result by moving it to /usr/local/bin:

    sudo mv wp-cli.phar /usr/local/bin/wp

WP-CLI is now ready and you can use it by typing

wp

before any command to initialize WP-CLI. That is not so cool, so let's make it snappy.

You can do this by telling bash by using next command that the command 'wp' will call to the wp-cli.phar executable in your home directory.

  1. echo "alias wp='~/wp-cli.phar'" >> .bashrc

    Or

    vi .bashrc
    add to the file:
    alias wp='~/wp-cli.phar'

    You can also use your .bash_profile and then source .bashrc from the file:

    
    		if [ -f ~/.bashrc ]; then
    		   source ~/.bashrc
    		fi
    			
  2. Update your session to new settings:
    source .bashrc

Test Our WP-CLI

To make sure that our wp-cli is working as intended, "cd" to your WordPress install directory and then use either of the following commands:

wp --info

or

wp plugin list

Before using the last one, ensure that you have installed WordPress using the:

wp core install

Run the following command to print a list of available options:

wp

 cache               Manage the object cache.
  cap                 Manage user capabilities.
  checksum            Verify WordPress core checksums.
  cli                 Manage WP-CLI itself.
  comment             Manage comments.
  config              Manage the wp-config.php file
  core                Download, install, update and manage a WordPress install.
  cron                Manage WP-Cron events and schedules.
  db                  Perform basic database operations using credentials stored in wp-config.php
  doctor              Diagnose what ails WordPress.
  eval                Execute arbitrary PHP code.
  eval-file           Load and execute a PHP file.
  export              Export WordPress content to a WXR file.
  find                Find WordPress installs on the filesystem.
  help                Get help on WP-CLI, or on a specific command.
  host-check          Check that the WordPress install is still hosted at its internal domain.
  import              Import content from a WXR file.
  language
  media               Manage attachments.
  menu                List, create, assign, and delete menus.
  network
  option              Manage options.
  package             Manage WP-CLI packages.
  plugin              Manage plugins.
  post                Manage posts.
  post-type           Manage post types.
  profile
  rewrite             Manage rewrite rules.
  role                Manage user roles.
  scaffold            Generate code for post types, taxonomies, plugins, child themes, etc.
  search-replace      Search/replace strings in the database.
  server              Launch PHP's built-in web server for this specific WordPress installation.
  shell               Interactive PHP console.
  sidebar             Manage sidebars.
  site                Perform site-wide operations.
  super-admin         Manage super admins on WordPress multisite.
  taxonomy            Manage taxonomies.
  term                Manage terms.
  theme               Manage themes.
  transient           Manage transients.
  user                Manage users.
  widget              Manage sidebar widgets.
	

Composer and WP-CLI

Add the following line to your projects composer.json file:


"require" : {
    "wp-cli/wp-cli" : "~0.22",
    "psy/psysh" : "~0.6"
}
	

where the psy/psysh package is just a suggestion by the WP CLI package and optional.

WP-CLI & Local Dev.

  • Homebrew:
    brew install wp-cli
  • Docker:
    image: wordpress:cli
Ha estat útil la resposta? 0 Els usuaris han Trobat Això Útil (0 Vots)