WP-CLI untuk Developer WordPress

WP-CLI untuk Developer WordPress

WP-CLI adalah tool command line untuk mengelola WordPress tanpa masuk dashboard. Cepat, efisien, dan wajib untuk developer yang bekerja di server, VPS, atau local development.

Artikel ini merangkum semua perintah inti yang paling sering dipakai, lengkap dengan contoh real yang langsung bisa digunakan.


1. Instalasi & Cek Versi

Instalasi (Linux/Mac):

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Test:

wp --info

2. Perintah Dasar yang Selalu Dipakai

Cek versi WP

wp core version

Download WordPress

wp core download

Generate wp-config

wp config create \
  --dbname=namadb \
  --dbuser=user \
  --dbpass=pass \
  --dbhost=127.0.0.1

Install WordPress

wp core install \
  --url="https://site.com" \
  --title="Judul" \
  --admin_user=admin \
  --admin_password=pass \
  [email protected]

3. Manajemen Database

Buat database

wp db create

Export database

wp db export backup.sql

Import database

wp db import backup.sql

Search-replace URL (pindahan hosting / staging)

wp search-replace "https://lama.com" "https://baru.com"

4. Manajemen Plugin

List plugin

wp plugin list

Install

wp plugin install woocommerce --activate

Aktifkan

wp plugin activate nama-plugin

Nonaktifkan

wp plugin deactivate nama-plugin

Update semua plugin

wp plugin update --all

5. Manajemen Theme

List theme

wp theme list

Install

wp theme install generatepress --activate

Update semua theme

wp theme update --all

6. Manajemen User

List user

wp user list

Tambah admin

wp user create nama [email protected] --role=administrator --user_pass=pass

Ubah password user

wp user update admin --user_pass=passbaru

7. Manajemen Post / CPT

List post

wp post list

Buat post draft

wp post create --post_title="Judul" --post_status=draft

Publish

wp post update 123 --post_status=publish

8. Manajemen Options

Cek siteurl / home

wp option get siteurl
wp option get home

Set siteurl / home (jika website broken setelah pindahan)

wp option update siteurl "https://baru.com"
wp option update home "https://baru.com"

9. Clear Cache

Jika pakai plugin cache:

wp cache flush

Jika pakai Nginx FastCGI:

rm -rf /var/cache/nginx/*
systemctl restart nginx

10. Health Check & Debugging

Cek info environment

wp --info

Enable debug

wp config set WP_DEBUG true --raw

Disable debug

wp config set WP_DEBUG false --raw

Cek error pada config

Jika error:

mysql: No such file or directory

→ Pastikan PATH MySQL benar:

export PATH=/usr/local/mysql/bin:$PATH

Atau jika di WSL:
Gunakan --dbhost=127.0.0.1.


11. Automasi & Speed Boost

Update WordPress + plugin + theme sekali klik

wp core update
wp plugin update --all
wp theme update --all

Regenerate thumbnail

wp media regenerate

Generate salinan staging

wp db export staging.sql
scp staging.sql user@server:/home/site

12. WP-CLI untuk Migrasi Cepat (Template)

Ini format migrasi cepat yang biasa dipakai di VPS:

wp db export before.sql
wp search-replace "https://domainlama.com" "https://domainbaru.com"
wp option update siteurl "https://domainbaru.com"
wp option update home "https://domainbaru.com"
wp cache flush

13. Command yang Paling Penting (Ringkas)

KebutuhanCommand
Install WPwp core download
Setup configwp config create
Installwp core install
Export DBwp db export
Import DBwp db import
Migrasi URLwp search-replace
Install pluginwp plugin install
Update pluginwp plugin update --all
Buat user adminwp user create ...
Cek database errorwp --info

Penutup

WP-CLI mempercepat workflow developer WordPress secara drastis: instalasi lebih cepat, migrasi lebih rapi, debugging lebih mudah, dan otomatisasi bisa dilakukan dalam beberapa detik.

Jika kamu bekerja di VPS, WP-CLI bukan tambahan — ini kebutuhan.

Built with Breakdance.
©2025 All rights reserved.