How to Use WP-CLI for Better WordPress Site Management

After installing the theme, you can activate it through WP-CLI using the following command:wp core version

Once you’ve downloaded the .phar file, you need to make it an executable file. To do that, run the following command:

Some Preliminary Steps

Let’s get right to it!

Access to SSH

wp theme install themename

Installing themes with WP-CLI is very simple and less time consuming than going to the WordPress admin panel. WP-CLI connects your server directly to the WordPress theme repository and imports themes in just a few seconds. You can install any theme by using this command:

Installing WP-CLI

Before we move on to the tutorial, we need to make sure some things are in place for the command line interface for advanced WordPress management to install successfully.
wp theme update themename

wp –info

wp core config –dbname=databasename –dbuser=databaseuser –dbpass=databasepassword –dbhost=localhost –dbprefix=prfx_

wp search-replace ‘www.old-site.com’ ‘www.new-site.com’

Have you used WP-CLI? We’d love to hear about your experience with it so let us know in the comments section below!

Basic WP-CLI Commands and Tasks

wp plugin update –all

As you can probably already guess, updating WordPress themes with WP-CLI is just as easy as installing and activating them. The update command will save you a bunch of clicks and remembering how you’re supposed to update themes in the first place:
chmod +x wp-cli.phar

#!/bin/bash
declare -a sites=(‘/var/www/wp1’ ‘/var/www/wp2’ ‘/var/www/wp3’)
for site in “${sites[@]}”;
do
wp –path=$site core update
done

wp plugin install pluginname

wp plugin deactivate pluginname

Updating Plugins

To activate the plugin, use the command:

Updating WordPress

First, we need to download WordPress in order to install it.  Navigate to the directory you’d like to download the WordPress CMS to and run the following command:
Installing a clean, fresh copy of WordPress is one thing but updating WordPress is another. And just like installing WordPress, updating it is also very simple using WP-CLI. Using sub-commands, we are going to update our WordPress. The WP-CLI sub-commands enable users to update core files and database files if they aren’t updated. Here’s how:
Installing plugins with WP-CLI is an effortless task, as well. WP-CLI installs all of the plugins from the official WordPress plugin repository. You can use this command to install plugins:
sudo mv wp-cli.phar /usr/local/bin/wp

WP-CLI has a one-liner WordPress backup command, the db export command:
This command will download the latest version of WordPress and after the download is complete, you can create the wp-config.php file using the core config command as follows:

Installing Themes

wp core download
When you want to deactivate the plugin simply run the following command:

Activating Themes

Other management issues when administrating a WordPress site usually occur when handling media or images. Using WP-CLI, you won’t have to worry about a thing when it comes to media. The media tool of WP-CLI enables users to import all of their images and media onto their site with the following command:
WP-CLI helps web developers overcome the most head-scratching tasks in developing a WordPress website. In this article, we’ll walk you through a tutorial on how to setup WP-CLI and use its different commands to develop even faster and more efficient website.
wp db export backup.sql

Installing WP-CLI is quite simple. All you have to do is download a PHP file and put it somewhere on your drive so that you can run it from anywhere – which should be your main objective while setting up the command line interface. First, you’ll need to download the WP-CLI script from the GitHub repository to get the latest version available.
wp theme update –all

Activating themes through WP-CLI is easy to do and you’ll see the changes take effects in seconds.

Installing Plugins

[/php]wp core install –url=example.com  –title=”WordPress Website Title” –admin_user=admin_user –admin_password=admin_password –admin_email=admin@example.com[/php]
wp media import images_folder/*

wp plugin activate pluginname

wp plugin update pluginname

Let’s start with the basics. You can easily install WordPress using WP-CLI’s core command. By using this command, you can make use of a set of powerful tools for managing WordPress installations.
A common practice employed by most developers is that they build a site on a local or development server and after completing the site, they move it to another server. In this process, copying and moving the database files is simple and easy to do. The tricky part is when you have to replace the old URLs with the new ones in the database. This tricky part won’t be so tricky if you are using WP-CLI. Using the search and replace command you can easily replace URLs in the database entries.
Check your credentials and make sure everything is in place. That’s all there is to it! You’ve installed WordPress on your server using WP-CLI.
PHP binary: /usr/bin/php
PHP version: 5.5.24
php.ini used: /etc/php.ini
WP-CLI root dir:  phar://wp-cli.phar
WP-CLI global config: /Users/kouratoras/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 0.19.2

First of all, you need to make sure you have Secure Shell (SSH) access to your hosting service as most hosting services don’t provide SSH access by default. If you don’t have access, contact your hosting service’s customer support center for assistance.

Bulk Import Images

WordPress stores every revision of a post in your database which means that your site’s database contains a ton of information that you won’t ever have to use. Now that’s a really big issue. Unfortunately, WP-CLI does not manage post revisions with a simple command. That said, the wp-revisions-cli plugin, which is an extension of WP-CLI, helps in managing post revisions. This useful plugin can be found on the GitHub repository and you can install it just as you would install an ordinary WordPress plugin.
After you’ve crossed SSH access off your list, you want to make sure you have WordPress 3.4 (or above) activated, PHP 5.3.2 (or above), and a UNIX-like environment. If you are a Windows user, you will need a command-line tool like Cygwin or a virtual machine setup. Once you have all the required resources to run WP-CLI, you can proceed to install it on your WordPress website.

Search and Replace Functionality

WP-CLI is a must-have for all WordPress developers who want to speed up the development process without compromising on accuracy. There are endless possibilities with WP-CLI and it’s wide-range of features provide a good result to its users.
wp theme activate themename

Wrapping It Up

The command line interface has always been popular in the world of developers, as it provides much more productivity and speed when developing a site.
wp core update
wp core update-db

But if you are not sure about your current version of WordPress then you can check it by using this command:

Posted by WordPress Guru