🎉 AgentWP is now in Public Beta Testing.
WordPress developers know that command-line tools offer unbeatable control and speed when managing sites. That's why WP-CLI has become a favorite in the community.
In this guide, we're sharing the best WP-CLI packages that'll make your development process smoother than ever. These tools can handle everything from content creation to site health checks. If you want to boost your productivity and focus on building great WordPress sites, these packages are just what you need.
Keep reading to learn how to install each package, use it effectively, and tap into its best features.
What Is a WP-CLI Package?
WP-CLI packages are add-ons that expand the core functionality of WP-CLI (WordPress Command Line Interface) with new commands and features. Users can use these packages to perform a lot of tasks more efficiently through the command line.
For example, the wp-cli/search-replace package allows you to run search and replace operations on your WordPress database. This is particularly useful for bulk updates or when migrating a site to a new domain.
And if you need to manage your database or troubleshoot performance issues on your WordPress site, there are packages for that too.
Developers love WP-CLI packages because they can create custom commands tailored to specific needs. This flexibility means you can simplify repetitive tasks and boost your productivity. And thanks to the vibrant WordPress community, there's a growing library of packages available for all sorts of tasks.
WP-CLI packages can save you time and effort. They're particularly handy for bulk operations, diagnostics, and advanced database management - tasks that might be tedious or error-prone through the admin interface.
How to Install a WP-CLI Package
Installing a WP-CLI package is straightforward, especially if you’ve got some experience with command-line interfaces. Here's how to do it:
1) Install WP-CLI
First, make sure WP-CLI is installed and properly set up on your system. You can verify this by running wp --info in your terminal. If WP-CLI is not installed, download it from the official WP-CLI website and follow the installation instructions.
2) Choose Your WP-CLI Package
Next, identify the WP-CLI package you want to install. You can browse available packages on the WP-CLI package index, or install packages manually if you have its Git URL, local path to the directory, or a zip file.
3) Install the WP-CLI Package
On your terminal or command prompt, enter wp package install to install the package. This command can accept a package specified as a Git URL, a local path to a directory, or a zip file.
Here are some examples:
From a Git URL:
wp package install git@github.com:user/package.git
From a local directory:
wp package install /path/to/mypackage
From a zip file:
wp package install /path/to/sample-package.zip
4) Verify the Installation
Enter the following command to display all installed packages along with their details:
wp package list
5) Try New Commands
Once the package is installed, you can start using the new commands it provides. For example, if you installed the wp-cli/search-replace-command package, you could run:
wp search-replace 'old-domain.com' 'new-domain.com'
Note: WP-CLI packages are typically installed in the ~/.wp-cli/packages/ directory. If you want to use a custom path, you can set the WP_CLI_PACKAGES_DIR environment variable to your preferred directory.
Adding the directory containing the wp executable (usually bin/wp or bin/wp.bat) to your system's PATH environment variable isn’t required. However, it makes using WP-CLI easier because you won’t need to type out the full path to the executable every time.
You may check out these tutorials for adding to your PATH environment variable for your specific operating system:
- How to set the path and environment variables in Windows
- How to set/change $PATH variable command in MacOS
- How to set the $PATH variable in Redhat 9.0
List of WP-CLI Packages for WordPress Developers
1) Yoast/wp-cli-faker
Yoast/wp-cli-faker is a WP-CLI extension designed for developers and testers who need to quickly populate WordPress sites with dummy content. This includes posts, pages, comments, and users. If you want to test themes, plugins, or custom code under realistic conditions, then you’ll find this tool invaluable.
The package offers two primary commands:
- wp faker core content: Generates a full range of WordPress elements including authors, attachments, categories, tags, posts, and pages.
- wp faker woocommerce products: Creates product-related data for WooCommerce sites.
For example, to generate 50 dummy posts, you’d use:
wp faker core content --posts=50
2) woocommerce/wc-smooth-generator
The WooCommerce Smooth Generator is a plugin that’ll help you create dummy data for your WooCommerce online store, including products, orders, coupons, customers, and terms.
You can access its UI on the WordPress admin dashboard (under Tools). However, it’s best to use it with WP-CLI commands to efficiently generate bulk data.
To install, download the latest release from the GitHub repository and upload it to your WordPress site. The plugin can create various types of data, such as products and orders, based on specified parameters.
Once activated, you can explore its capabilities using:
wp help wc generate
This command lists all available options. For more details on a specific command, use:
wp help wc generate <command name>
Now, let’s say you want to generate 100 simple products. You’d use the following command:
wp wc generate products 100 --type=simple
3) alleyinteractive/wp-doc-command
The wp-doc-command package brings WordPress core documentation directly to your command line. It offers PHPDoc information for functions, classes, methods, and properties so you don’t need to navigate through the online code reference.
Developers can access this information using the wp doc command, which provides quick insights into any documented WordPress element. Using this command, you can save time and stay focused on your tasks.
To use this package, you'll need WP-CLI v0.23.0 or later. Install it with:
wp package install alleyinteractive/wp-doc-command
Now, let’s say you want to view the PHPDoc information for the get_posts, simply type:
wp doc get_posts
4) wp-cli/doctor-command
The wp-cli/doctor-command package is a diagnostic tool for WordPress sites. It includes many built-in checks and allows for custom checks via a YAML configuration file.
To start using the tool, install it with:
wp package install wp-cli/doctor-command
Then, run checks using:
wp doctor check
This command identifies problems and provides statuses and messages. The tool supports various output formats to suit different debugging needs.
For example, to check if your WordPress core is current, enter:
wp doctor check core-update
5) aaemnnosttv/wp-cli-login-command
The wp-cli-login-command package creates magic login links for WordPress users. It's especially useful on production servers for secure user impersonation during troubleshooting or password resets.
After installing the package and its companion plugin, you can create a magic login link using this command:
wp login create <user>
Note that this link will expire after 15 minutes or one use.
For automation or scripting, you can use --url-only return just the link, or --redirect-url=<url> to specify a custom redirect URL after login.
For example, to create a magic login link for the admin user, enter this command:
wp login create admin
This generates a one-time, 15-minute link for the admin user. You can configure the expiration time and other parameters as needed.
6) schlessera/wp-cli-psysh
If you want to replace the default WP-CLI shell with PsySH, you can install the schlessera/wp-cli-psysh package.
PsySH offers a more robust REPL (Read-Eval-Print-Loop) environment for WordPress developers. It allows you to correct mistakes without restarting, unlike the standard wp shell command, which can be unforgiving with minor typos. It also provides better output formatting and includes tab completion for WordPress functions.
To install, make sure you have WP-CLI v1.1.0 or later, then run:
wp package install git@github.com:schlessera/wp-cli-psysh.git
After installation, you can start using the enhanced shell immediately:
wp shell
Here's an example of how it works:
>>> $id = 61;
=> 61
>>> wp_get_attachment_image_src($id);
=> [
"http://www.example.com/wp-content/uploads/2022/08/image2.png",
150,
84,
false,
]
Even if you make a syntax error, PsySH won't crash:
>>> wp_get_attachment_image_src($id):
PHP Parse error: Syntax error, unexpected ':' on line 1
7) php-stubs/wp-cli-stubs
If you're a WordPress developer using static analysis tools like PHPStan, you might have run into issues with WP-CLI code. That's where php-stubs/wp-cli-stubs comes in handy.
This package provides stub declarations for WP-CLI functions, classes, and interfaces. It's like a translator between WP-CLI's not-so-OOP code and your static analysis tool.
To get started, make sure you're running PHP 7.1 or higher. Then, add it to your project with:
composer require --dev php-stubs/wp-cli-stubs
You can also download wp-cli-stubs.php directly if you prefer not to use Composer.
To use it with PHPStan, just add these lines to your PHPStan config:
parameters:
scanFiles:
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
This configuration allows PHPStan to recognize and correctly analyze WP-CLI code in your WordPress projects.
8) wp-cli/restful
Ever wished you could access WordPress REST API endpoints straight from your terminal? That's exactly what wp-cli/restful does.
With this package, you can list, get, create, update, and delete content using familiar CLI commands. It even throws in some extra goodies like edit, generate, and diff operations. It's perfect for developers who love the command line and need more muscle than standard WP-CLI commands offer.
Getting started is easy. Just run:
wp package install wp-cli/restful
Once it's set up, you're ready to roll. Want to grab excerpts from a specific site? Try this:
wp --http=runcommand.io rest excerpt list
This command reaches out to the REST API endpoint and fetches the excerpt list from runcommand.io.
9) iandunn/wp-cli-rename-db-prefix
Sometimes, changing WordPress database table prefixes can be a pain. That's where iandunn/wp-cli-rename-db-prefix comes in handy. This WP-CLI command takes the headache out of renaming your database table prefix, especially when you're migrating data between sites with different prefixes.
Now, a word of caution. Always back up your wp-config.php file and export your database before making changes. Safety first!
Then, install the package using this command:
wp package install iandunn/wp-cli-rename-db-prefix
Here’s a basic command to rename the database prefix:
wp rename-db-prefix <new_prefix>
Here are the additional options to tailor the command to your needs:
- --dry-run: Preview changes without applying them. Perfect for double-checking.
- --no-confirm: Skip the confirmation prompt. Use with caution!
- --no-config-update: Run without updating wp-config.php. Handy for non-standard setups.
To run a dry run of the rename command, try:
wp rename-db-prefix flyinghellfish_ --dry-run
This shows the SQL commands that will run, so you can check the changes. For standard installations, it makes changing the table prefix easy.
In Summary
We've just scratched the surface of what WP-CLI can do for your WordPress workflow. From populating test sites to running health checks, these packages turn tedious tasks into quick commands so you can save hours of work.
There are plenty of other WP-CLI packages out there, and you'll find more that meet your unique needs as you get comfortable with these.
We hope this guide helps you make the most of WP-CLI. Give these packages a try, and see how they can improve your workflow!