If you’re a WordPress administrator or a developer working with a WordPress Multisite network, then mastering WP-CLI (WordPress Command Line Interface) can drastically improve your productivity and site management experience. Whether you’re handling plugin installations across multiple sites, managing users, or updating themes, WP-CLI allows you to perform tasks in seconds that might otherwise take hours using the standard WordPress dashboard.
What is WP-CLI?
WP-CLI is a powerful tool that enables you to interact with your WordPress installation using command-line instructions. Instead of clicking through the WordPress admin panel, you can run simple commands to perform complex operations. This is especially valuable when working with WordPress Multisite, where managing multiple sites from a single dashboard can become unwieldy.
Setting Up WP-CLI for Multisite
Before you begin using WP-CLI with Multisite, you must ensure that WP-CLI is properly installed and that your WordPress installation is running in MultiSite mode. You can check your current setup with the following command:
wp core is-installed --network
If WordPress Multisite is correctly configured, WP-CLI will return a success message. If not, you’ll need to enable Multisite in your wp-config.php file by adding:
define( 'WP_ALLOW_MULTISITE', true );
Navigating the Network with WP-CLI
One of the most useful features of WP-CLI for Multisite environments is the ability to switch between sites in the network easily. You can perform operations on a specific site using the --url
parameter:
wp plugin list --url=subsite.example.com
This command will list the plugins active on the specified subsite, allowing you precise control over each site in your network.
Useful WP-CLI Commands for Multisite
There are a variety of commands specifically useful when managing a Multisite setup:
- Add a new site:
wp site create --slug=newsite --title="New Site" --email=admin@example.com
- List all sites:
wp site list
- Delete a site:
wp site delete SITE_ID
- Activate plugin across network:
wp plugin activate plugin-name --network
These commands enable you to streamline multisite management, avoiding repetitive steps for each individual installation.
Managing Users Across the Network
Managing users on a Multisite network can be a headache through the dashboard, especially when dealing with hundreds or thousands of users. WP-CLI makes this very efficient:
- List all users:
wp user list
- Add a user to site:
- Create a new user across network:
wp user set-role USER_ID contributor --url=subsite.example.com
wp user create newuser newuser@example.com --role=subscriber
These commands help automate user management across multiple subsites, especially during migrations or site onboarding processes.
Exporting and Importing Data
When moving sites from one network to another or backing up content, WP-CLI’s export and import capabilities are invaluable:
wp export --url=subsite.example.com --dir=./exports
wp import ./exports/filename.xml --authors=create --url=subsite.example.com
This helps preserve data integrity and facilitates quick site cloning or backups within a multisite environment.
Scheduling and Automation with WP-CLI
WP-CLI can be combined with CRON jobs to automate daily tasks like database backups, plugin updates, or even security scans:
wp plugin update --all --quiet
By placing this command in a shell script and calling it via CRON, you can ensure your entire network stays up-to-date without manual intervention.
Wrapping Up
Working with WP-CLI in a WordPress Multisite setup opens doors to powerful automation, efficiency, and accuracy. It’s a game-changer for developers and administrators managing large networks, allowing you to tackle complex operations with simple, scriptable commands.
If you haven’t yet explored the potential of WP-CLI in your Multisite environment, now is the perfect time to experiment and streamline your workflow.