Using WP-CLI to Automate WordPress Agency Workflows

by on May 15, 2025
Three WordPress website agency employees working on automating workflow.

WordPress is a breeze to manage — at least it is for site owners with one or two WordPress instances. Managing multiple WordPress sites is more demanding, especially when you’re responsible for configuring, deploying, and maintaining the sites your WordPress agency clients depend on.

WP-CLI is a built-in command-line tool that lets you automate WordPress tasks you carry out frequently. You can save time by using WP-CLI to script and standardize WordPress workflows across sites. If you’ve ever spent an afternoon manually implementing the same changes on a dozen sites, you already understand its value.

In this article, we’ll look at a few practical WP-CLI examples to see how WordPress agencies can use it to codify best practices into reusable scripts, reduce human error, and free up more time for creative work.

Note: To use WP-CLI, clients’ sites must be hosted with a WordPress hosting provider that supports Secure Shell (SSH) access and WP-CLI. If you’re not familiar with SSH, check out our guide to logging into your Pressable hosting account with SSH.

Automate WordPress: WP-CLI Workflows That Save Time and Impress Clients

1. Spin Up New Client Sites in Under 2 Minutes

A managed WordPress hosting provider will take care of installing WordPress, but you have to set it up in line with your agency’s standard site configuration. Done manually, that’s a lot of clicking around.

With WP-CLI, you can create a simple script that installs and activates your default theme and plugin stack, configures common settings, and preps the site for development.

# Install and activate the agency's preferred theme
wp theme install kadence --activate

# Install and activate essential plugins
wp plugin install advanced-custom-fields wpforms-lite seo-by-rank-math disable-comments --activate

# Set thetimezone
wp option update timezone_string 'America/Chicago'

# Disable comments
wp option update default_comment_status 'closed'

# Create a default Home and Contact page
wp post create --post_type=page --post_title='Home' --post_status=publish
wp post create --post_type=page --post_title='Contact' --post_status=publish

# Set the homepage to the newly created Home page
wp option update show_on_front 'page'
wp option update page_on_front $(wp post list --post_type=page --pagename=home --field=ID)

These scripts are especially helpful for onboarding junior developers and eliminating small discrepancies that might lead to support issues later. Once you have a solid starter script, you can extend it with client-specific requirements or integrate it into a larger automation pipeline.

Running Your WP-CLI Starter Script

The simplest way to run these commands is by logging into the site’s WordPress hosting account with SSH and pasting them into the terminal. That alone saves time over clicking through the admin.

But, depending on your host, you can go further.

  • Create a shell script containing the commands and upload it to your WordPress account over SFTP.
  • Use WP-CLI’s --ssh option to run script commands from your local machine.

    For example:
    wp --ssh=mywordpresssite@ssh.pressable.com theme install kadence --activate

    This method will require you to enter a password for each command. However, if your hosting provider supports SSH keys, you can authenticate without entering a password. Learn how to create SSH keys for your Pressable account.
  • If your client sites are hosted on Pressable, you can run WP-CLI commands remotely with the Pressable API. The API allows agencies to integrate the site setup process into their internal tools.

Pressable customers can also use the Bulk Operations feature to run WP-CLI commands on multiple websites simultaneously. Log in to the My.Pressable.com dashboard and select Bulk Operations in the Tools tab.

Bulk Operations feature in the Pressable managed WordPress hosting dashboard

2. Generate a Client-Facing WordPress Plugin Security Audit

Clients in regulated or security-conscious industries want to know their site is up to date and free from unnecessary risk. A plugin audit script is a lightweight but effective way to demonstrate that your agency is monitoring their stack for vulnerabilities and poor maintenance practices.

With WP-CLI, you can list all installed plugins, show their status (active/inactive), and flag any that are out of date.

For example:

wp plugin list --format=table

Or output to JSON for integration with internal tools:

wp plugin list --format=json

You can script this across all client sites and export the results for inclusion in monthly reports or client dashboards.

WP-CLI can surface many other types of information that are useful for client-facing reporting, including user lists, database overviews, content publication timelines, order status overviews on WooCommerce, and more.

With a little imagination, you can generate valuable reports and dashboards that demonstrate your role as a proactive partner and give your clients confidence that their site is being managed responsibly.

3. Automate Post-Migration Cleanup After a Domain Change

There is a risk of broken links, media paths, and theme settings when you move a WordPress site from one domain to another during a client rebrand or host migration. With WP-CLI, you can automate the cleanup process so that nothing gets missed.

First, run a search-and-replace across the entire database to update references to the old domain:

wp search-replace 'https://oldclientdomain.com' 'https://newclientdomain.com' --all-tables

This WP-CLI command handles serialized data safely and covers widgets, shortcodes, and internal links. Pressable managed WordPress hosting clients can also use our built-in Search and Replace interface, which adds useful features like sensible table defaults.

Built-in search and replace interface n the Pressable dashboard

Read the WP-CLI documentation for more information about wp search-replace capabilities. 

Next, you’ll need to flush the permalinks to make sure URLs and rewrites work correctly:

wp rewrite flush

If the migration affected image file paths or you’ve changed the directory structure, it’s also a good idea to regenerate thumbnails:

wp media regenerate --yes

Instead of walking through these steps manually each time, you can store this as a standard migration script. It’s a fast way to prevent subtle breakage and ensure that the site is client-ready as soon as a DNS switch is complete.

4. Enforce WordPress Security Defaults with a Hardening Script

WordPress is secure by design, but agency developers still need to enforce best practices, not least to prevent clients from introducing vulnerabilities and performance problems. With WP-CLI, you can apply a consistent set of security hardening steps across every site you manage.

A simple hardening script might include:

# Disable file editing in the admin
wp config set DISALLOW_FILE_EDIT true --raw

# Block plugin/theme changes from the dashboard
wp config set DISALLOW_FILE_MODS true --raw

# Force SSL for login and admin
wp option update force_ssl_admin 1

# Lock down debug display on production
wp config set WP_DEBUG false --raw
wp config set WP_DEBUG_DISPLAY false --raw
wp config set WP_DEBUG_LOG true --raw

# Remove default admin user if it exists
wp user delete admin --reassign=1 || echo "Admin user not found or already removed."

# Audit current admin users
wp user list --role=administrator --format=table

These settings reduce risk by limiting access and suppressing sensitive output. Wrapping them into a script ensures you don’t overlook anything.

Warning: Some commands can stop your site from working as expected. Be sure that you understand what they do before you run them on a production WordPress site. You can find more information in the WP-CLI documentation

5. Automate a Pre-Launch Technical QA

Every agency has some version of a launch checklist. WP-CLI lets you turn that checklist into a script to make your pre-launch process faster, more consistent, and less reliant on memory or manual clicking.

For example, here’s a simple quality assurance (QA) script that covers a few high-priority technical checks:

# Confirm permalink structure is set correctly
wp option get permalink_structure

# Flush rewrite rules to ensure clean permalinks
wp rewrite flush

# Double-check that debug mode isn’t exposed
wp config get WP_DEBUG
wp config get WP_DEBUG_DISPLAY

# Delete sample content (like "Sample Page")
wp post delete $(wp post list --post_title='Sample Page' --format=ids) --force
wp post delete $(wp post list --post_title='Hello world!' --format=ids) --force

You can expand the basic script to include any project-specific settings, like verifying homepage assignments or checking installed plugins. The benefit is repeatability: the same QA process can be run by any developer on your team, in any environment, with no surprises before launch.

Put WP-CLI to Work for Your Agency

We’ve barely scratched the surface of what WP-CLI can do. It’s a versatile, scriptable tool that helps WordPress agencies streamline operations and deliver consistent results across every client site. The five workflows we’ve covered are just a starting point. You can combine them, extend them, and integrate them into your agency’s internal tooling or deployment pipelines.

For more commands, examples, and customization options, check out the WP-CLI Handbook.

If you’re looking for managed WordPress hosting that helps agencies streamline operations and deliver sites with 100% uptime, Pressable agency WordPress hosting is built with you in mind.

Read More Articles in Running a WordPress Business