WP-Cli is a command line interface which allows the users to manage their WordPress web sites from the command prompt. Upgrades can be performed, backups can be generated, new posts can be published and most of the regular admin actions can be performed with a set of commands.
In this tutorial we will explain how to use the WP command line interface in order to complete regular administrative tasks like upgrades, database backup creation, plugins and themes installations and removals, publishing and deleting posts, changing site's URL settings and getting help on chosen commands. Note that WP-Cli requires an SSH access.
List the Available WP-Cli Commands
First, we will start with the instructions on how to list the available commands and get detailed help for each one of them.
To list all the commands write wp help or just wp.
The following list will be shown:
See 'wp help ' for more information on a specific command.
If you want to get detailed documentation, for example, for the wp db export command, enter the code listed below:
The result will be as follows:
Now we will proceed with the regular management tasks.
Update WordPress via WP-Cli
First, we will show how to update the core files of your web site. We will check the current version which we have:
Obviously it is outdated. In order to use the latest scripts features and have all the vulnerabilities in the older versions patched we should always use the latest stable releases for our web site applications. Using WP-Cli we will complete the upgrade with a single command:
Update WordPress Plugins using WP-Cli
The update of the core files and the database are not always enough. If we have integrated external plugins and/or themes we should take care of their upgrade. We need to check the status of the installed extensions:
We have 5 plugins integrated in our sample installation. There are upgrades for two of them. We will complete the upgrades through the following commands:
Install and Activate WordPress Plugins & Themes via WP-Cli
To install and activate a new plugin run the commands listed below:
- wp plugin install Plugin_Name
- wp plugin activate Plugin_Name
You should replace the "Plugin_Name" string with the exact plugin name.
If you do not need a plugin you can remove it through the following action:
Next, we will check the themes:
To update all the themes the following command should be executed:
The themes can be installed, activated and uninstalled in a similar way to the plugins:
- wp theme install Theme_Name
- wp theme activate Theme_Name
- wp theme delete Theme_Name
The "Theme_Name" string should be replaced with the actual theme name.
The activation will make the chosen theme the default one for your WordPress installation.
Other Tasks you Can do With WP-Cli
We can even write posts directly from the command line. The creation of a sample post on a new page is illustrated below:
If we do not need a certain post we can easily delete it:
Once we have our script upgraded and the content set we can generate a database backup:
If the web master decides to change the primary domain for the WordPress web site he/she can easily update the corresponding URL options:
More details on WP cli can be found through the help command and the project's home page.
No comments :
Write comments