Running with WP CLI for WordPress Multisite

by | Dec 31, 2024 | Etcetera | 0 comments

Through the years, WordPress builders have created and maintained WP-CLI, a powerful command-line interface in particular designed for WordPress operations. As a time-saving software, WP-CLI is particularly well-suited for managing WordPress Multisite networks, which permit a few web sites to run on a single WordPress arrange.

To use WP-CLI effectively, it’s essential to grasp key portions of WordPress: the Admin interface, the report construction, and the database. Without this foundational knowledge, WP-CLI will not be as surroundings pleasant or beneficial.

While WP-CLI is helping standard directions like setting up, updating, activating, deactivating, and deleting plugins or problems, its purposes lengthen way past what’s available inside the WordPress Admin dashboard, making it a really versatile software for advanced internet website keep watch over.

This newsletter explains how you’ll be able to use WP-CLI to keep watch over WordPress Multisite networks effectively and provides good examples to help you get started.

What’s WP CLI and why use it?

WP-CLI is a powerful software for managing WordPress web sites by the use of the command line. In a multisite environment, it should nicely significantly simplify the keep watch over of a group, enabling you to perform bulk actions and streamline your workflow.

Its true energy lies in its flexibility and extensibility — you’ll be capable to simply execute directions all over all the group or function specific web sites while moreover improving its capacity with rather a couple of WP-CLI packages available on GitHub and other repositories.

Builders incessantly create custom designed WP-CLI directions to simplify repetitive tasks. For example, you’ll be capable to use WP-CLI to scaffold boilerplate code for problems and plugins, saving time and effort everywhere building.

Must you’re web webhosting with Kinsta, WP-CLI is integrated and to be had by the use of SSH, allowing you to keep watch over WordPress web sites simply. For local building, WP-CLI is available in DevKinsta all over the devkinsta_fpm container. Once all over the container, you’ll be capable to navigate on your internet website folder and run directions. While this requires somewhat little bit of setup, it provides a powerful approach to arrange your local WordPress web sites effectively for debugging, testing, or deploying.

Faster than you get started

The directions highlighted in this article are somewhat decided on for their commonplace use by the use of WordPress Multisite developers and administrators.

WP-CLI is a big and flexible software, making it unattainable to cover each available command. To stick problems clear and good, we’ve inquisitive about simple, actionable examples to help you get started.

Since WP-CLI is in line with Unix instructions, likelihood is that you’ll no longer find a WP-CLI an identical for directions that already exist in Unix.

Key notes about WP-CLI

WP-CLI’s command building is flexible, allowing a few tactics to achieve the an identical finish end result. For instance, both one of the vital subsequent examples are official:

wp particular person create johndoe johndoe@example.com --display_name="John Doe" --nickname="Johnny"

Or:

wp particular person create johndoe --display_name="John Doe" johndoe@example.com --nickname="Johnny"

The order of flags, parameters, and values doesn’t subject as quickly because the command and subcommand are discussed.

Absolute best practices for operating WP-CLI directions

Apply the ones best practices to keep away from potential issues:

  • Always have a gift backup available, in particular as a couple of of those directions will totally alter your internet website(s).
  • Use a staging internet website any place possible. Must you’re using Kinsta, each WordPress arrange includes a unfastened staging atmosphere for safe testing. You’ll be capable to merely push changes between staging and reside environments.
  • Use the --dry-run flag to test database changes faster than applying them.

Crucial WP-CLI directions for WordPress Multisite keep watch over

WP-CLI directions in a Multisite group can function different levels of movement:

  • Neighborhood-wide: Directions carried out all over all web sites inside the group. For example:
    wp plugin deactivate --network --all

    This command deactivates all plugins all over each internet website inside the group.

  • Primary internet website: Directions carried out to the main internet website created everywhere the Multisite setup. For example:
    wp plugin checklist

    The command above lists all plugins installed at the #1 internet website most simple.

  • Secondary web sites: Directions focused on particular person web sites throughout the group, specified by their URLs. For example:
    wp plugin substitute --url=mysite.example.com akismet

    This command updates the akismet plugin on the internet website mysite.example.com.

To make managing your Multisite group more uncomplicated, we’ve grouped WP-CLI directions into the ones sections:

Basic directions

The ones fundamental directions have the same opinion with troubleshooting and managing plugins and problems all over your group.

See also  The Easiest Commercials We have Observed on TikTok + Why They Made Us Faucet the Hyperlink

Working with lists

WP-CLI makes it easy to retrieve lists of plugins and other portions in your Multisite environment.

  1. Get a list of all plugins inside the group:
    wp plugin checklist --network

    Output: Shows all network-installed plugins with details like name, recognition, updates available, and fashion.

  2. Filter plugins by the use of recognition (e.g., full of life):
    wp plugin checklist --network --status=full of life

    Output: A table of full of life plugins across the group.

  3. Get a list of plugins from the main internet website:
    wp plugin checklist

    Output: A list of plugins for the main internet website.

  4. Get a list of full of life plugins for a single internet website:
    wp plugin checklist --url= --status=full of life

    Input example:

    wp plugin checklist --url=blog.example.com --status=full of life

    Output: A table of full of life plugins for the internet website blog.example.com.

In conjunction with filtering plugins by the use of recognition=full of life, you’ll be capable to moreover use the following filters:

  • inactive: Plugins which may well be installed alternatively no longer full of life.
  • active-network: Plugins full of life across the group.
  • must-use: Must-use plugins that load robotically.

Deactivate plugins

Deactivating plugins is incessantly crucial when troubleshooting issues or making able for updates. WP-CLI signifies that you’ll be able to deactivate plugins across the group or for specific web sites.

  1. Deactivate all plugins across the group:
    wp plugin deactivate --network --all

    Consequence: All plugins inside the group are deactivated.

  2. Deactivate specific plugins for a single internet website:
    wp plugin deactivate   --url=

    Input example:

    wp plugin deactivate akismet hello-dolly --url=blog.example.com

    Consequence: The plugins akismet and hello-dolly are deactivated for the internet website blog.example.com.

Activate plugins

Use the ones directions to activate plugins each network-wide or for particular person web sites in your Multisite setup.

  1. Activate all plugins across the group:
    wp plugin activate --network --all

    Consequence: All plugins inside the group are activated.

  2. Activate specific plugins for a single internet website:
    wp plugin activate   --url=

    Input example:

    wp plugin activate akismet hello-dolly --url=blog.example.com

    Consequence: The plugins akismet and hello-dolly are activated for the internet website blog.example.com.

Arrange plugins

Putting in place plugins with WP-CLI is speedy and surroundings pleasant. Once installed, plugins will also be activated for particular person web sites or across the group.

The following command can be used to place in a plugin for the group:

wp plugin arrange 

Input example:

wp plugin arrange akismet

Consequence: The plugin akismet is installed and ready for activation.

Change plugins

Keep your plugins up-to-date all over your group or for specific web sites using the ones directions.

  1. Change all plugins across the group:
    wp plugin substitute --network --all

    Consequence: All plugins inside the group are up to the moment.

  2. Change specific plugins across the group:
    wp plugin substitute   --network

    Input example:

    wp plugin substitute akismet jetpack bbpress --network

    Consequence: The plugins akismet, jetpack, and bbpress are up to the moment across the group.

  3. Change a plugin for a single internet website:
    wp plugin substitute --url= 

    Input example:

    wp plugin substitute --url=blog.example.com hello-dolly

    Consequence: The plugin hello-dolly is up to the moment for the internet website blog.example.com.

Delete plugins

Removing plugins is straightforward with WP-CLI, whether or not or no longer you’re working on a single internet website or a Multisite group.

  1. Delete a plugin from the prevailing WordPress context (group or internet website):
    wp plugin delete 

    Input example:

    wp plugin delete bbpress

    Consequence: The plugin bbpress is deleted.

  2. Delete a plugin for a specific internet website in a Multisite:
    wp plugin delete  --url=

    Input example:

    wp plugin delete bbpress --url=blog.example.com

    Consequence: The plugin bbpress is deleted from the internet website blog.example.com.

Neighborhood keep watch over

Managing web sites within a WordPress Multisite group is a a very powerful procedure. Beneath aren’t ordinary WP-CLI directions to help you effectively create, arrange, and delete web sites, along with deal with caching operations.

Creating web sites

Together with new web sites on your group is straightforward with WP-CLI.

  • Basic command: Create a brand spanking new internet website by the use of specifying a novel slug.
    wp internet website create --slug=

    Input example:

    wp internet website create --slug=blog

    Consequence: A brand spanking new internet website blog.example.com or example.com/blog, depending in your group setup is created and is robotically full of life.

  • Sophisticated command: Alternatively, flags will also be appended to the command. Throughout the example beneath, a internet website is added with a specified internet website determine and internet website administrator.
    wp internet website create --slug= --title="" --email=

    Input example:

    wp internet website create --slug=blog --title="Blog Internet web page" --email=admin@blog.com

    Consequence: A internet website titled “Blog Internet web page” is created with admin@blog.com for the reason that administrator.

  • Tick list all web sites: Retrieve a table appearing internet website IDs, URLs, creation dates, and shutting up to the moment dates:
    wp internet website checklist

    You’ll be capable to moreover refine the internet website checklist to get most simple the URLs of all web sites inside the group:

    wp internet website checklist --field=url

    Output: A list of URLs for each internet website.

Emptying and deleting web sites

  1. Empty the main internet website:
    wp internet website empty

    Output: A confirmation prompt turns out to delete all content material subject material for the main internet website.

  2. Empty a single internet website (removes all posts, pages, links, and taxonomies):
    wp internet website empty --url=

    Input example:

    wp internet website empty --url=blog.example.com

    Consequence: All content material subject material from blog.example.com is deleted, alternatively the internet website remains intact.

  3. Empty all web sites inside the group:
    wp internet website checklist --field=url | xargs -n1 -I % wp internet website empty --url=% --yes

    Consequence: This command initiates a loop via all URLs and then proceeds to empty each internet website’s contents without the need to provide popularity of each internet website.

  4. Delete a single internet website by the use of ID:
    wp internet website delete 

    Input example:

    wp internet website delete 5

    Consequence: Internet web page with ID 5 is deleted.

  5. Delete a few web sites with confirmation bypass:
    wp internet website delete 2 --yes
    wp internet website delete 3 --yes

    Consequence: Web sites with IDs 2 and 3 are deleted. The --yes flag helps to skip turns on.

Clearing cache

On account of many cache types are stored in different tactics proper right here, we use the Kinsta Must-Use plugin. It’s installed routinely for each and every WordPress web site in our software.

This clears all cache, at the side of internet website cache, edge cache, CDN cache, and Redis cache.

  1. Clear all cache (internet website, edge, CDN, and Redis):
    wp kinsta cache purge --all
  2. Clear most simple internet website cache:
    wp kinsta cache purge --site
  3. Purge CDN cache:
    wp kinsta cache purge --cdn
  4. Clear object cache:
    wp cache purge

Shopper keep watch over

WP-CLI simplifies managing consumers in a Multisite environment, allowing you to perform tasks briefly and effectively. This segment covers no longer ordinary particular person keep watch over operations:

Tick list consumers

Tick list consumers in a group or a specific internet website is straightforward with WP-CLI.

  1. Tick list all consumers inside the group:
    wp particular person checklist --network

    Output: A table showing Shopper ID, Login, Display Identify, Username, Registration Date, and Place for each particular person or particular person checklist query.

  2. Tick list consumers for the main internet website:
    wp particular person checklist

    Consequence: Shows a table of shoppers for the main internet website.

  3. Tick list consumers for a specific internet website (secondary internet website):
    wp particular person checklist --blog_id=
    wp particular person checklist --url=

    Input example:

    wp particular person checklist --blog_id=6

    Consequence: Shows a table of all consumers for the internet website with Blog ID 6.

Create consumers

In a Multisite group, consumers are registered to the group by the use of default. Their roles depend on whether they’re the main particular person added to a internet website or subsequent consumers. Usernames must be a minimum of 4 characters long.

  1. Add a brand spanking new particular person to the main internet website:
    wp particular person create  

    Input example:

    wp particular person create johndoe johndoe@example.com

    Output: A excellent fortune message is displayed, at the side of a generated password.

  2. Add a brand spanking new particular person to a specific internet website with a specified serve as:
    wp particular person create   --role= --url=

    Input example:

    wp particular person create janedoe janedoe@example.com --role=editor --url=blog.example.com

    Output: The individual janedoe is added to the internet website blog.example.com as an “Editor”.

  3. Add particular person account meta everywhere creation:
    wp particular person create   --display_name= --nickname=

    Input example:

    wp particular person create johndoe johndoe@example.com --display_name="John Doe" --nickname="Johnny"

    Consequence: Shopper johndoe is created with a display name John Doe and nickname Johnny.

Change particular person

Updating particular person knowledge, an identical to roles or passwords, is speedy with WP-CLI.

  1. Exchange (promote it or downgrade) particular person roles:
    wp particular person substitute  --role=

    Input example:

    wp particular person substitute johndoe janedoe adminuser --role=super-administrator

    Consequence: Consumers johndoe, janedoe, and adminuser are promoted to Super Administrators.

  2. Reset or industry an individual password:
    wp particular person substitute  --user_pass=

    Input example:

    wp particular person substitute johndoe --user_pass=securePassword2024

    Consequence: The password for johndoe is up to the moment.

  3. Daisy-chained directions: WP-CLI signifies that you’ll be able to combine a few actions in a single command, saving time when improving consumers. For example, you’ll be capable to at the same time as substitute an individual’s password and serve as.
    wp particular person substitute  --user_pass= --role=

    Input example:

    wp particular person substitute johndoe --user_pass="newPassword2024" --role=editor

    Consequence: The password for particular person johndoe is up to the moment to newPassword2024, and their serve as is changed to “Editor”.

Arrange particular person meta

Shopper meta signifies that you’ll be able to add, retrieve, or delete metadata for particular person accounts.

  1. Get particular person meta:
    wp particular person meta get  

    Input example:

    wp particular person meta get johndoe nickname

    Output: Shows the price of the nickname meta key for particular person johndoe.

  2. Add particular person meta:
    wp particular person meta add   

    Input example:

    wp particular person meta add johndoe display_name "Mr. John Doe"

    Consequence: Mr. John Doe is set for the reason that display name for particular person johndoe.

  3. Delete particular person meta:
    wp particular person meta delete  

    Input example:

    wp particular person meta delete johndoe display_name

    Consequence: This command deletes the display_name meta key for the individual johndoe.

Delete consumers

Removing consumers from the group or specific web sites is surroundings pleasant with WP-CLI.

  1. Delete an individual from the group:
    wp particular person delete  --network

    Input example:

    wp particular person delete johndoe --network

    Consequence: The individual johndoe is removed from the group.

  2. Delete an individual from a specific internet website:
    wp particular person delete  --url=

    Input example:

    wp particular person delete johndoe --url=mysite.example.com

    Consequence: The individual johndoe is removed from the internet website mysite.example.com.

Database keep watch over

WP-CLI provides a powerful option to tools like phpMyAdmin for managing your database. This segment covers no longer ordinary database operations you’ll be capable to perform using WP-CLI:

Exporting a database

With WP-CLI, you’ll be capable to export your database as an SQL document. The exported document is saved inside the root checklist of your WordPress arrange.

wp db export

Consequence: An SQL document is created inside the root checklist.

See also  The way to Write a Video Script [Template + Video]

If the exported document has an inept name, you’ll be capable to rename it using the following command:

wp eval 'if ( rename( "unganglyfilename.sql", "newfilename.sql" ) ) { echo "Document renamed successfully."; } else { echo "Didn't rename document."; }'

Input example:

wp eval 'if ( rename( "cilawawugo4504_gTr4kSXUsmJ9FNauVnPb-2024-11-17-9545b3f.sql", "network-db.sql" ) ) { echo "Document renamed successfully."; } else { echo "Didn't rename document."; }'

Consequence: Document cilawaw…nPb--9545b3f.sql is renamed to network-db.sql.

Downloading a database

To acquire the exported database document on your local machine, use the curl command.

curl  -o 

Input example:

curl example.com/network-db.sql -o ~/Downloads/network-db.sql

Consequence: The document network-db.sql is downloaded on your local Downloads checklist.

Uploading a database

You’ll be capable to upload a database report back to the root checklist of your Multisite arrange using the scp command.

scp  @:

Input example:

scp ~/Downloads/network-db.sql admin@example.com:/var/www/example.com/public_html

Consequence: The document network-db.sql is uploaded to the root checklist of your WordPress arrange after authentication.

Importing a database

Faster than importing a database, you may need to reset your present wisdom tables.

  1. Reset wisdom tables:
    wp db reset

    Consequence: All wisdom tables inside the database are emptied.

  2. Import the database:
    wp db import 

    Input example:

    wp db import network-db.sql

    Consequence: The document network-db.sql populates the emptied wisdom tables.

  3. Delete the imported SQL document:For protection purposes, delete the SQL document after importing:
    rm 

Good examples

We can bring to mind many directions that may pace and simplify your workflow. Listed here are 3 examples. While a couple of of those directions are further complex, they assemble upon simpler directions to carry out useful operations.

Arrange and activate plugins and regenerate thumbnails at the same time as.

This command loops via all web sites inside the group, installs and activates two plugins, and regenerates image thumbnails for each internet website.

wp internet website checklist --field=url | xargs -n1 -I % sh -c 'wp plugin activate   --url=% && wp media regenerate --url=%'

Input example:

wp internet website checklist --field=url | xargs -n1 -I % sh -c 'wp plugin arrange akismet bbpress --activate --url=% && wp media regenerate --url=%'

Consequence: The plugins Akismet and BBPress are installed and activated all over all web sites, and image thumbnails are regenerated.

Together with a custom designed meta space for all consumers

This command loops via all web sites, retrieves the checklist of shoppers, and offers a custom designed meta space for each particular person.

wp internet website checklist --field=url | xargs -n1 -I % sh -c 'wp particular person checklist --fields=ID --url=% --format=csv | tail -n +2 | xargs -n1 -I {} wp particular person meta add {}   --url=%'

Input example:

wp internet website checklist --field=url | xargs -n1 -I % sh -c 'wp particular person checklist --fields=ID --url=% --format=csv | tail -n +2 | xargs -n1 -I {} wp particular person meta add {} favorite_color "" --url=%'

Consequence: A custom designed meta space, favorite_color, is added for all consumers all over all web sites.

To ground the favorite_color space, you’ll need to use your functions.php document or create a custom designed plugin.

Converting a single internet website set as much as a multisite

WP-CLI makes it easy to turn into a standalone WordPress internet website proper right into a Multisite group.

wp core multisite-convert

Consequence: The one internet website is remodeled proper right into a Multisite group.

Faster than conversion, you’ll want to deactivate all plugins.

After converting the internet website, you wish to have to configure the group URLs inside the wp-config.php document. You’ll be ready to choose from using subdomains (e.g., internet website.example.com) or subdirectories (e.g., example.com/internet website). Additionally, check out the .htaccess document, for the reason that URL rewrite rules (handled by the use of the mod_rewrite module in Apache) would possibly require information updates to verify your permalinks and internet website building art work accurately.

Summary

This knowledge highlights the power and flexibility of WP-CLI for managing WordPress Multisite environments, making it an essential software for developers and administrators searching for efficiency and control. From coping with plugins, consumers, and databases to showing advanced operations like converting single web sites to Multisite, WP-CLI simplifies complex tasks with precision and pace.

Kinsta supplies an invaluable and extensible WP-CLI software that permits seamless keep watch over of WordPress Multisite networks. Whether or not or no longer you’re working on reside or staging environments or using our local building software, DevKinsta, WP-CLI is instantly available to streamline your workflow.

Get began creating web sites, together with plugins, consumers, and additional with WP CLI!

The publish Running with WP CLI for WordPress Multisite appeared first on Kinsta®.

WP Hosting

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!