For WordPress developers, managing a site directly from the command line is both powerful and efficient. WP CLI, a command-line interface for WordPress, makes this possible by offering a broad range of commands that streamline site management.
Whether you’re installing WordPress, managing plugins, troubleshooting issues, or automating tasks, WP CLI commands help you do everything quickly and with precision. In this comprehensive guide, we will explore WP-CLI commands for different actions, such as WordPress management, database handling, and troubleshooting.
Let’s dive deeper into how each of these WP-CLI commands can be useful for developers and how they work.
Must Read: What is WP-CLI? A Guide for Agencies and Developers
Table of Contents
WP CLI Command List to Manage WordPress
Many WordPress site management tasks can be simplified using WP CLI, allowing developers to perform various tasks like installing or updating WordPress, checking for missing files, and more.
Installing WordPress
When setting up a new WordPress site and speeding up WordPress development, WP CLI allows developers to download the core files in a few commands. This eliminates the need for manual downloads and FTP, making the process faster.
Command: wp core download
Example: wp core download –path=/var/www/mynewsite
This command installs WordPress in the directory /var/www/mynewsite. Developers can also specify a different path where they want WordPress installed. It saves developers time compared to manually downloading the files.
Reinstalling WordPress
When you need to reinstall WordPress (e.g., during a troubleshooting process or to restore core files), WP CLI makes this action straightforward.
Command: wp core reinstall
This wp-cli command will reinstall WordPress while maintaining posts, plugins, and other customizations. This is especially useful if core files are corrupt or missing.
Running WordPress Core Updates
WordPress is frequently updated to fix bugs and patch security vulnerabilities. WP CLI simplifies the update process, ensuring your site runs the latest and most secure version.
Command: wp core update
This WP-CLI command automatically checks for updates and installs the latest stable version of WordPress. Developers can also automate this process for managing multiple WordPress sites by running this command in a batch process.
Rollback WordPress to a Previous Version
If a new version of WordPress introduces issues, you may need to roll back to an earlier version. With WP CLI, this rollback can be done in seconds.
Command: wp core update –version=5.6
By specifying the version number, developers can roll back the WordPress core to a stable version if they encounter compatibility problems with plugins or themes after a new update.
Checking for Missing or Modified WordPress Core Files
To ensure that the WordPress core files are intact and have not been tampered with, developers can use this WP CLI command to verify the integrity of their files.
Command: wp core verify-checksums
This WP CLI command compares the checksums of your core files with those stored in the WordPress repository. If any discrepancies are found, you are alerted, which can be essential for security.
WP- CLI Command List to Manage WordPress Plugins
We all know that WordPress plugins enhance the functionality of WordPress sites. But, managing them effectively is the key. We have come up with a WP CLI command list that provides several commands to manage them, including installation, activation, and updates.
Installing and Activating Plugins
Instead of manually downloading and activating plugins, you can quickly install and activate them using a single WP CLI command.
Command: wp plugin install plugin-name –activate
Example: wp plugin install jetpack –activate
This wp-cli command installs the Jetpack plugin and activates it immediately, saving time compared to manual installation through the WordPress dashboard.
Deactivating a Plugin
If a plugin is causing issues or you simply need to deactivate it temporarily, use this command.
Command: wp plugin deactivate plugin-name
Example: wp plugin deactivate jetpack
This WP CLI command deactivates the plugin you specify. You can deactivate a plugin without needing to access the WordPress admin panel, which is ideal for troubleshooting.
Deactivating All WordPress Plugins
When troubleshooting or working with a fresh WordPress install, deactivating all plugins can be an essential step.
Command: wp plugin deactivate –all
Example: wp plugin deactivate –all
If your site is experiencing issues caused by a plugin conflict, deactivating all plugins can help identify the problem. This WP CLI command saves time by not having to deactivate plugins individually.
Updating Plugins
Keeping your plugins up to date is vital for security and compatibility. WP CLI allows you to update plugins efficiently.
Command: wp plugin update plugin-name
Example: wp plugin update jetpack
With this wp-cli command, you can update individual plugins. You can also use wp plugin update –all to update all plugins at once.
WP- CLI Command List to Manage a WordPress Database
Your WordPress database contains important content and settings for your WordPress site. WP CLI provides powerful commands to back up, repair, and optimize your WordPress database.
Exporting the Database
Backups are essential, and exporting the database through WP CLI is one of the easiest ways to perform this task.
Command: wp db export
Example: wp db export mydbbackup.sql
This WP-CLI command creates a backup of your database, which you can use for migration or as a restore point. Developers can automate this process with cron jobs for regular backups.
Importing a Database
When migrating a site or restoring from a backup, use WP CLI to import your database quickly.
Command: wp db import database-file.sql
Example: wp db import mydbbackup.sql
With the help of this WP-CLI command, developers can import a previously exported database, making it easy to migrate or restore your site.
Repairing the WordPress Database
Sometimes, the WordPress database may become corrupted, and repairing it can take days if done manually. WP-CLI can help you repair WordPress databases with a simple command.
Command: wp db repair
If you suspect database corruption or if you’re encountering errors related to database integrity, this command can fix common issues.
Performing a WordPress Database Search and Replace
If you’ve moved your site or changed URLs, this command helps you search and replace text in your database (e.g., replacing old URLs with new ones).
Command: wp search-replace ‘old-text’ ‘new-text’
Example: wp search-replace ‘http://oldsite.com’ ‘http://newsite.com’
This WP-CLI command is essential when migrating WordPress or updating URL structures, as it ensures all instances of the old URL are replaced across the database.
WP- CLI Command List to Manage WordPress Users
WordPress users are integral to the site’s functionality. With WP CLI, you can quickly manage users, create new ones, delete old ones, and more.
Creating a New User
Have multiple sites and need to add new users all of them? Don’t worry. Use the WP CLI command to quickly create a new user.
Command: wp user create user_name user_email –role=administrator
Example: wp user create jane jane@example.com –role=editor
This command creates a new user with the role of editor. You can change the role to any of the available WordPress roles, such as administrator, subscriber, or author.
Listing WordPress Users
Instead of manually browsing the WordPress admin panel, use WP CLI to list all the users.
Command: wp user list
This command provides a tabular display of all users with essential details like ID, login, email, and role.
Deleting a User
When a user needs to be removed from your site, use WP CLI to delete them.
Command: wp user delete user_id –reassign=another_user_id
Example: wp user delete 15 –reassign=2
This command deletes the user with ID 15 and reassigns all their posts to the user with ID 2. It’s helpful when managing a site with many contributors.
WP- CLI Command List to Troubleshoot with WP-CLI
WordPress troubleshooting is a constant task for developers and with the smart use of WP CLI commands, developers can help troubleshoot many common WordPress issues.
Enabling and Disabling Debugging Mode
When WordPress troubleshoots, enabling WordPress debugging mode or wp-debug can help you track down errors in your site.
Command: wp config set WP_DEBUG true –type=constant
This WP-CLI command enables WordPress’s debug mode, which helps developers identify errors by logging them into a debug file.
Flushing WordPress Permalinks
When you encounter issues with broken WordPress permalinks, flushing the WordPress rewrite rules can resolve them.
Command: wp rewrite flush
This command from our WP CLI command list is particularly useful after changing the permalink structure or modifying URL-related settings.
Advice for WordPress Developers to Maximize WP CLI
For WordPress developers looking to streamline their workflow, InstaWP offers a powerful tool to elevate your WP CLI experience. With InstaWP, you can execute WP CLI commands remotely, manage multiple sites from a centralized dashboard, and utilize a UI-based command builder for ease of use.
- Run from Web: Execute sequences of commands across one or more WordPress sites without needing SSH access. Simply select the sites from your dashboard and run your operations seamlessly.
- In-built Library: InstaWP provides a curated library of battle-tested commands, making it easy to ramp up your library. You can quickly import real-world examples and customize them for your needs.
- Bulk Execute: Run commands on multiple sites simultaneously—perfect for developers managing a large number of websites. Get outputs from all sites in one place for efficient management.
- Use Variables: InstaWP makes complex commands simpler with dynamic variables like {{var_name}}, enabling no-code solutions and automating the input process.
InstaWP brings flexibility and speed to WP CLI commands, transforming your WordPress management tasks into an efficient, code-free experience.
Whether you’re managing plugins, users, or databases, InstaWP is the ultimate tool to execute commands quickly and effectively while taking your WordPress development game to a top-notch level.
Get ready to simply WordPress management with wp-cli and InstaWP? Check this out.
Conclusion
Mastering WP CLI is a game-changer for WordPress developers, allowing them to manage and troubleshoot sites with ease. By utilizing WP-CLI commands effectively, developers can streamline WordPress installation, plugin management, database operations, and even troubleshooting.
With tools like InstaWP, executing WP CLI commands becomes even easier, offering a robust interface, command libraries, and powerful bulk execution features. The combination of WP CLI and InstaWP helps developers optimize their workflow and manage multiple sites seamlessly, ultimately saving time and boosting productivity.