Advanced guide for managing WordPress core, themes, and plugins strictly via the command line (WP-CLI). Streamline updates, automate bulk actions, and improve security on your Hovixa VPS.

Managing WordPress Core, Themes, and Plugins via WP-CLI

For technical users and system administrators, using the WordPress dashboard is often inefficient. WP-CLI provides a powerful alternative for managing multiple sites directly over SSH. By using the command line, you can execute bulk updates, automate maintenance scripts, and manage site components even when the web UI is unreachable due to errors.

1. Managing WordPress Core

Updating the core files is the most critical maintenance task for security. WP-CLI allows you to update and verify the integrity of these files without leaving the terminal.

  • Check for updates: wp core check-update
  • Perform update: wp core update
  • Verify file integrity: wp core verify-checksums

Tip: Verifying checksums compares your local files against the official WordPress.org repository to identify if any core files have been modified by malware.

2. Plugin Lifecycle Management

Instead of clicking "Update" for 20 plugins, you can handle them all with a single string. WP-CLI also allows you to search the official repository and install plugins directly.

# List all plugins and their status
wp plugin list

# Update all plugins at once
wp plugin update --all

# Install and activate a plugin
wp plugin install wordfence --activate

# Deactivate a plugin (useful if a plugin causes a WSOD)
wp plugin deactivate contact-form-7
    

3. Theme Administration

Themes can be managed similarly to plugins. This is particularly useful for removing unused "default" themes (Twenty-Twenty, etc.) that increase your server's attack surface.

Requirement WP-CLI Command
List Themes wp theme list
Switch Theme wp theme activate generatepress
Update All wp theme update --all
Delete Theme wp theme delete twentytwentythree

4. Advanced: Bulk Operations and Automation

The true power of WP-CLI on a Hovixa VPS lies in its ability to loop through commands. You can combine it with standard Linux tools like xargs or bash scripts.

Example: Auto-Updating and Cleaning

# Update everything and optimize the database in one go
wp core update && wp plugin update --all && wp theme update --all && wp db optimize
    

5. Technical Implementation Details

  • The --allow-root Flag: By default, WP-CLI prevents execution as the root user for security. If you must run it as root, append --allow-root. Ideally, run it as the web user: sudo -u www-data wp plugin list.
  • Configuring Defaults: You can create a wp-cli.yml file in your project root to set default parameters, such as the path to the WordPress installation or the specific user to run as.
  • Exit Codes: WP-CLI uses standard Unix exit codes. A 0 indicates success, which makes it perfect for integrating into cron jobs for automated nightly updates.

Sysadmin Advice: Always run **wp db export** before performing bulk updates via CLI. This gives you a localized database rollback point if a plugin update breaks your site's functionality.

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)