With the different commands available on WP-CLI, there is nothing that cannot be done via the command line. Find below a list of some actions that can be performed using commands.
- Install and Update WordPress
Downloading and installing WordPress on your site is the most fundamental task you can accomplish with WP-CLI
To download WordPress use this command:
Text
wp core download
To refine the download further to the version you want use this command:
Text
wp core download --locale=en-US
This command will download the English version of WordPress
Proceed to install WordPress using the install command:
Text
wp core install --url=testing.com --title=Example --admin_user=supervisor -admin_password=strongpassword --admin_email=info@testing.com
Note: Replace the default values with your credentials.
Test the installation to confirm WordPress has been successfully installed using this command:
Text
wp core version
Update to the latest version using this command:
Text
wp core update
2 . Manage Themes and Plugins
There are different ways to manage themes and plugins using WP-CLI, let’s take a look at some of the basic options
Managing Themes via WP-CLI
To list installed themes use this command:
Text
wp theme list
To list all inactive themes as a CSV list, use this command:
Text
wp theme list --status=inactive --format=csv
To change an active theme to twenty-twenty, use this command:
Text
wp theme activate twenty twenty
To search for themes with Bootstrap support:
Text
wp theme search bootstrap
Using this command, proceed to install and activate:
Text
wp theme install the-bootstrap-blog --activate
To enable a theme using Twenty twenty theme, use this command:
Text
wp theme enable twenty twenty
To update themes use this command:
Text
wp theme update --all
To list all currently installed plugins, use this command:
Managing Plugins via WP-CLI
To install and activate a plugin use this command:
Text
wp plugin install litespeed-cache --activate
Run this command to update plugins:
Text
wp plugin update --all
Note that the –all parameter is used to update all installed plugins.
This can be changed to a specific plugin by replacing –all with the plugin name.
Using the litespeed-cache plugin, disable and uninstall a plugin:
Text
wp plugin deactivate litespeed-cache –uninstall
To activate any inactive plugin, use this command:
Text
wp plugin activate litespeed-cache
To find WordPress cache plugins use the following command:
Text
wp plugin search cache
To delete plugins use the wp plugin delete command:
Text
wp plugin delete litespeed-cache
- Create a Child Theme
By using the scaffold command, you can generate a child theme that includes the functions.php and style.css files. We recommend that you do this if you want to make changes to an existing theme. When you use a child theme, any customization won’t be lost after new software updates.
To do this, you’ll simply need to specify the slug for the new child theme, and for the theme, you’re using as the ‘parent.’ In this example, we are creating a child based on the Twenty Twenty theme, and we’re giving it the slug twenty-twenty-child:
Text
wp scaffold child-theme twenty-twenty-child --parent_theme=twentytwenty
You will get a successful message that the child theme has been created.
and find the child theme in the specified template.
- Moderate Comments
With WP-CLI, you can quickly create, edit and delete comments making managing comments much easier. There are many comment subcommands you can use, but let’s look at some of the most basic options.
To add a new comment, use this command. This command will add a comment to a post with the post ID of 10, and state the author and contents:
Text
wp comment create --comment_post_ID=10 --comment_content="This is my comment" --comment_author="author-name"
This command will return a table containing the comment ID and author name for all approved comments on the post with an ID of 5:
Text
wp comment list --number=5 --status=approve --fields=ID,comment_author
To delete comments, specify the comment IDs individually, like this:
Text
wp comment delete 46
To delete multiple comments using the force parameter, which permanently deletes comments instead of adding them to the trash bin:
Text
wp comment delete 3 25 46 54 --force
Using WP-CLI commands you can work through your site’s comments
- Update the WP-CLI
You should always make sure that WP-CLI is updated at all times.
To update WP-CLI run the following command:
Text
wp cli update
If your version is updated, you will get a successful message confirming this, however, if you are running a version that is not updated, you will be prompted to accept the installation, selecting yes will get WP-CLI updated
With a simple interface like WP-CLI you can perform functions unavailable in WordPress, complete multiple tasks using a single command and improve productivity,