惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
月光博客
月光博客
S
SegmentFault 最新的问题
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
WP-CLI: The Terminal Way to WordPress — Part 1
Kushang Tail · 2026-05-04 · via DEV Community

Stop clicking through wp-admin for every small task. WP-CLI is a command-line tool that lets you manage WordPress sites faster — all from your terminal.


📌 Table of Contents

  1. Why WP-CLI?
  2. Problems It Solves
  3. Is It Good or Bad?
  4. Setup & Installation
  5. Must-Know Commands
  6. A Quick Real-World Use Case
  7. Your First Custom Script
  8. What's Next

Why WP-CLI?

Every WordPress developer knows the pain — update 12 plugins, flush cache, reset a password, run a search-replace after moving a site. Through the dashboard, that's 30+ clicks. With WP-CLI? A single line.

WP-CLI is the official command-line interface for WordPress. It lets you do everything you'd normally do in wp-admin, but from your terminal — faster, scriptable, and without touching a browser.


Problems It Solves

  • Bulk operations — update all plugins/themes in one command
  • Database search-replace — migrate sites without touching serialized data manually
  • Locked out of wp-admin? — reset passwords or create admin users directly from CLI
  • Repetitive setup tasks — stop doing the same 10 steps every new project
  • Cron & scheduled tasks — trigger wp-cron reliably from server crontabs

Is It Good or Bad?

Honest answer — excellent for developers, a non-issue for anyone who'll never open a terminal.

✅ Good For ⚠️ Watch Out For
Developer workflows No undo on DB commands
Managing multiple sites Wrong path → affects wrong site
Automating repetitive tasks Needs SSH/terminal access
Faster deployments Shared hosts may restrict it

💡 Golden rule: Always test destructive commands on staging first. Power cuts both ways.


Setup & Installation

Linux / macOS

Step 1 — Download the Phar file:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Enter fullscreen mode Exit fullscreen mode

Step 2 — Make it executable and move it globally:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Enter fullscreen mode Exit fullscreen mode

Step 3 — Verify:

wp --info

Enter fullscreen mode Exit fullscreen mode

You should see your OS, PHP version, and WP-CLI version. If you do — you're good to go.

Windows

Use WSL (recommended) or install via Composer:

composer global require wp-cli/wp-cli-bundle

Enter fullscreen mode Exit fullscreen mode

💡 Using LocalWP, DevKinsta, or DDEV? WP-CLI is already bundled — no setup needed.


Must-Know Commands

Run all commands from your WordPress root directory.

Command What It Does
wp core install Install WordPress in one shot
wp plugin install <slug> --activate Install + activate a plugin from .org
wp plugin update --all Update every plugin at once
wp theme activate <slug> Switch active theme instantly
wp user create Create a user with role and password
wp search-replace 'old' 'new' Safe DB search-replace
wp db export / import Backup or restore your database
wp cache flush Clear the object cache
wp option get/update Read or change wp_options values
wp cron event run Manually trigger a WP-Cron event

Full command reference → developer.wordpress.org/cli/commands


A Quick Real-World Use Case

🔁 Site Migration

Moving a site from local to staging? After transferring files and importing the DB, just run:

wp search-replace 'localhost' 'staging.example.com' --all-tables

Enter fullscreen mode Exit fullscreen mode

That's it. Serialized data is handled safely — no broken arrays, no manual SQL editing. What used to take 20 minutes of careful find-and-replace now takes 3 seconds.


Your First Custom Script

Once you know the commands, the next step is combining them into a shell script. Here's a simple one that sets up a fresh WordPress install with your go-to plugins:

#!/bin/bash
# setup.sh — run after: wp core download && wp config create

# Install WordPress
wp core install \
  --url=localhost \
  --title="My Site" \
  --admin_user=admin \
  --admin_email=you@dev.com

# Install & activate your standard plugins
wp plugin install wordfence woocommerce yoast-seo --activate

# Clean permalink structure
wp rewrite structure '/%postname%/' --hard

echo "✅ Setup complete!"

Enter fullscreen mode Exit fullscreen mode

Save it as setup.sh, make it executable with chmod +x setup.sh, and run it after every fresh install. Consistent environment, zero effort.


What's Next

You now have WP-CLI installed, know the essential commands, and have your first script running. That's a solid foundation.

In Part 2, we'll go deeper:

  • Writing advanced custom PHP commands with WP_CLI::add_command()
  • Using WP-CLI in CI/CD pipelines
  • Managing remote WordPress sites
  • --dry-run patterns so you never break production

Found this helpful? Drop a ❤️ and follow along for Part 2!