Black Friday Sale is live: save up to 85% on Web & WordPress HostingView Deals
Step-by-Step TutorialWordPress & Web OptimizationIntermediate

Using WP-CLI for WordPress Administration

What is WP-CLI?

WP-CLI (WordPress Command-Line Interface) provides a fast, scripting-friendly environment to control WordPress directly from your shell terminal.

Rather than navigating through the wp-admin dashboard or encountering PHP timeout errors during heavy administration tasks, WP-CLI communicates directly with the PHP runtime and MySQL database. It is indispensable for automated updates, bulk operations, emergency recovery from fatal plugin crashes, and domain migrations.


Verifying WP-CLI Availability

SSH access is included on WP Professional and higher WordPress hosting plans. To confirm that WP-CLI is available on your hosting environment, establish an SSH connection to your server and check the installed version:

wp --info

You should see output detailing the WP-CLI version, PHP binary path, and system architecture. Navigate to the root directory where your WordPress installation resides (typically public_html or the website application directory):

cd ~/public_html
wp core check-update

Essential WP-CLI Administrative Commands

1. Managing Core Updates

Verify current core status, download new WordPress releases, and trigger database upgrades without browser intervention:

# Check current WordPress version
wp core version

# Update WordPress core files to the latest version
wp core update

# Update the WordPress database schema after a core release
wp core update-db

# Verify core file integrity against official checksums
wp core verify-checksums

The verify-checksums command compares all local core files against official WordPress hashes, immediately flagging any modified or injected malicious files.


2. Managing Plugins and Themes

When a broken plugin causes a fatal error (White Screen of Death) and locks you out of wp-admin, WP-CLI allows you to isolate and disable problem extensions in seconds.

# List all installed plugins with their status and version
wp plugin list

# Deactivate an offending or conflicting plugin
wp plugin deactivate problematic-plugin-name

# Deactivate all active plugins simultaneously for troubleshooting
wp plugin deactivate --all

# Update all plugins to their latest secure versions
wp plugin update --all

# Install and activate a new plugin
wp plugin install litespeed-cache --activate

Theme management follows identical syntax:

# List installed themes
wp theme list

# Activate a default fallback theme during emergencies
wp theme activate twentytwentyfour

3. User Administration and Password Resets

If an administrator loses their credentials or cannot receive transactional password reset emails, you can view users and reset passwords directly:

# List all registered users and their capabilities
wp user list

# Create a new administrator account
wp user create adminuser notifications@your-domain --role=administrator --user_pass="StrongGeneratedPassword123!"

# Reset the password for an existing user
wp user update adminuser --user_pass="NewSecurePassphrase987!"

4. Safe Database Search and Replace (Domain Migrations)

When moving a WordPress website to a new domain or enabling SSL (switching from http:// to https://), URLs across posts, options, and theme metadata must be updated.

Because WordPress stores settings in PHP serialized strings, standard SQL queries break serialized arrays. WP-CLI handles serialization seamlessly.

Step 1: Perform a Dry Run (Simulation)

Always run a dry run first to see how many table rows will be modified without writing any changes to the database:

wp search-replace "http://old-domain.com" "https://new-domain.com" --dry-run

Step 2: Execute the Live Replacement

Once verified, execute the replacement across all tables:

wp search-replace "http://old-domain.com" "https://new-domain.com" --precise --recurse-objects

Step 3: Flush Object Cache

Ensure cached database queries are purged so that fresh URLs are served immediately:

wp cache flush

5. Maintenance Mode and Database Backups

WP-CLI simplifies taking snapshot backups and toggling visitor maintenance screens during site upgrades:

# Activate maintenance mode
wp maintenance-mode activate

# Export a compressed database dump
wp db export ~/backup_wordpress_$(date +%F).sql

# Deactivate maintenance mode when finished
wp maintenance-mode deactivate

Summary of Best Practices

  • Always execute commands as your hosting account user, never as root, to preserve correct Linux file ownership.
  • Use --dry-run on destructive commands such as search-replace before committing changes.
  • Combine with cron jobs to automate periodic tasks like clearing transients or checking plugin updates.

Frequently Asked Questions

What is WP-CLI and why should I use it instead of the admin dashboard?

WP-CLI is the official command-line interface for WordPress. It allows administrators to update core files, configure plugins, manage users, and perform database operations directly through SSH without relying on a web browser, eliminating timeout issues on large operations.

Is WP-CLI pre-installed on Web Hosting Wale hosting servers?

Yes. WP-CLI is pre-installed globally on all Web Hosting Wale Linux hosting, managed WordPress, and VPS platforms. You can invoke it immediately via terminal using the 'wp' command.

Why is 'wp search-replace' better than running SQL REPLACE queries?

WordPress stores many configuration options, widgets, and theme settings as PHP serialized strings. A raw SQL REPLACE query alters string lengths without updating serialization metadata, which corrupts the data. WP-CLI's search-replace command correctly deserializes objects, replaces text, and recalculates string length offsets safely.

Need Technical Assistance?

Web Hosting Wale support is available 24/7. Tickets are typically answered within 10-15 minutes.

Open Support TicketView All Support Channels