WP-CLI adalah aplikasi tool WordPress berbasis command line interface yang berfungsi untuk melakukan setting WordPress, seperti install WordPress, install plugin, install theme, mengatur post dan mengatur comment. WP-CLI dikembangkan dengan tujuan untuk membantu mempercepat alur kerja dari seorang WordPress developer.
*0. Minimum Requirement*
Sebelum install WP-CLI pastikan sistem sudah memenuhi minimum requirement agar WP-CLI bisa berjalan.
· Sistem operasi Unix-like (Linux, macOS, FreeBSD). · PHP 5.4 atau yang terbaru. · WordPress 3.7 atau yang terbaru.
*1. Install WP-CLI di Linux*
Aplikasi WP-CLI sama dengan composer, didistribusikan dalam format phar extension, sehingga cara installnya pun sama.
Download wp-cli.phar.
[INPUT]1 curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Menguji apakah extension Phar bisa dieksekusi.
[INPUT]1 php wp-cli.phar –info
Hasil perintahnya.
[INPUT]1 2 3 4 5 6 7 8 9 10 11 12 OS: Linux 4.15.0-48-generic #51~16.04.1-Ubuntu SMP Fri Apr 5 12:01:12 UTC 2019 x86_64 Shell: /bin/zsh PHP binary: /usr/bin/php7. PHP version: 7.0.33-0ubuntu0.16.04.4 php.ini used: /etc/php/7.0/cli/php.ini WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /tmp WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.2.0
Selanjutnya memberikan hak akses untuk semua user dan memindahkannya ke folder bin.
[INPUT]1 2 chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
Uji kembali.
[INPUT]1 2 3 4 5 6 7 8 9 10 11 12 13 14 wp –info OS: Linux 4.15.0-48-generic #51~16.04.1-Ubuntu SMP Fri Apr 5 12:01:12 UTC 2019 x86_64 Shell: /bin/zsh PHP binary: /usr/bin/php7. PHP version: 7.0.33-0ubuntu0.16.04.4 php.ini used: /etc/php/7.0/cli/php.ini WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /home/musa WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.2.0
*3. Update*
Update WP-CLI dapat dilakukan dengan menjalankan perintah *wp cli update* atau bisa juga dengan mengulangi langkah install di atas.
[INPUT]1 wp cli update
*4. Tab completions*
WP-CLI juga mendukung tab compeletion untuk bash dan zsh. Cukup dengan mendownload wp-completion.bash dan memanggilnya di file .bashrc atau .zshrc. Di sini saya menggunakan zsh.
Download file wp-completion.bash.
[INPUT]1 2 cd /opt sudo curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/v1.5.1/utils/wp-completion.bash
Buka file .zshrc.
[INPUT]1 nano ~/.zshrc
Pasang kode ini.
[INPUT]1 2 3 autoload bashcompinit bashcompinit source /opt/wp-completion.bash
Tutup terminal dan buka kembali terminal. Uji coba dengan mengetik perintah wp, lalu spasi, lalu tab. Harusnya muncul perintah dan parameternya.
[INPUT]1 2 3 4 5 6 7 wp cache core eval-file language option rewrite shell term cap cron export maintenance-mode package role sidebar theme cli db help media plugin scaffold site transient comment embed i18n menu post search-replace super-admin user config eval import network post-type server taxonomy widget
Mencoba mengetik perintah *wp plugin *.
[INPUT]1 2 3 4 wp plugin activate delete install is-installed path status uninstall verify-checksums deactivate get is-active list search toggle update
*5. Format Perintah WP-CLI*
Format perintah WP-CLI secara umum, diawali dengan perintah *wp*, kemudian diikuti dengan perintah, sub-perintah, dan terakhir diikuti oleh parameter baik itu wajib atau hanya opsi saja.
[INPUT]1 wp perintah sub-perintah –parameter1=value –parameter2=value –parameterN=value
Contohnya seperti di bawah ini, install plugin classic-editor dan langsung aktifkan.
[INPUT]1 wp plugin install classic-editor –activate
*6. Install WordPress via WP-CLI*
Kita bisa melakukan install WordPress langsung melalui WP-CLI tanpa harus melakukan install melalui web browser seperti biasanya. Diasumsikan semua kebutuhan untuk WordPress sudah tersedia, yaitu web server (Apache atau Nginx), database (MySQL atau MariaDB), dan PHP. Direktori document root untuk install WordPress ini sudah tersedia di */var/www/html/wpcli.oke* dan dengan URL akses WordPress *https://wpcli.oke*.
Masuk ke direktori document root.
[INPUT]1 cd /var/www/html/wpcli.oke
Download WordPress.
[INPUT]1 wp core download
Buat file konfigurasi WordPress wp-config.php.
[INPUT]1 wp config create –dbname=wpcli –dbuser=userdb –dbpass=passdb –dbhost=localhost
Membuat database, dbuser di atas harus bisa memiliki hak akses untuk membuat database. Jika sebelumnya sudah membuat database melalui mysql-shell atau phpMyAdmin, tidak perlu menjalankan perintah di bawah ini.
[INPUT]1 wp db create
Terakhir jalankan perintah install lengkap dengan parameter informasi website dan akun administrator.
[INPUT]1 wp core install –url=https://wpcli.oke –title=WordPress\ via\ WP-CLI –admin_user=admin –admin_password=admin –admin_email=mail@server.com
Setelah proses install WordPress selesai dengan menampilkan pesan *Success: WordPress installed successfully.*, uji hasil install dengan mengakses URL yang sudah ditentukan di web browser.
*7. Beberapa Perintah WP-CLI*
Download WordPress tanpa theme dan plugin default.
[INPUT]1 wp core download –skip-content –force
Check update WordPress core.
[INPUT]1 2 3 4 5 6 7 wp core check-update +———+————-+———————————————————–+ | version | update_type | package_url | +———+————-+———————————————————–+ | 5.2 | major | https://downloads.wordpress.org/release/wordpress-5.2.zip | +———+————-+———————————————————–+
Update WordPress core.
[INPUT]1 2 3 4 5 6 wp core update Updating to version 5.2 (en_US)… Downloading update from https://downloads.wordpress.org/release/wordpress-5.2-no-content.zip… Unpacking the update… Success: WordPress updated successfully.
Mengubah URL WordPress.
[INPUT]1 2 wp option update home ‘http://example.com’ wp option update siteurl ‘http://example.com’
Menampilkan plugin yang terinstall.
[INPUT]1 2 3 4 5 6 7 8 9 wp plugin list +—————-+———-+——————————+———+ | name | status | update | version | +—————-+———-+——————————+———+ | akismet | inactive | none | 4.1.1 | | classic-editor | active | none | 1.4 | | hello | inactive | version higher than expected | 1.7.1 | +—————-+———-+——————————+———+
Update plugin.
[INPUT]1 wp plugin update –all
Mencari plugin.
[INPUT]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 wp plugin search security Success: Showing 10 of 4793 plugins. +————————————————————————–+————————————-+——–+ | name | slug | rating | +————————————————————————–+————————————-+——–+ | Wordfence Security – Firewall & Malware Scan | wordfence | 96 | | Sucuri Security – Auditing, Malware Scanner and Security Hardening | sucuri-scanner | 88 | | iThemes Security (formerly Better WP Security) | better-wp-security | 94 | | Cerber Security, Antispam & Malware Scan | wp-cerber | 98 | | All In One WP Security & Firewall | all-in-one-wp-security-and-firewall | 96 | | Shield: Security, Scanning & Protection For All | wp-simple-firewall | 98 | | WP Hide & Security Enhancer | wp-hide-security-enhancer | 84 | | Jetpack by WordPress.com | jetpack | 78 | | WP Security Audit Log | wp-security-audit-log | 94 | | NinjaFirewall (WP Edition) – Advanced Security | ninjafirewall | 96 | +————————————————————————–+————————————-+——–+
Menampilkan theme yang terinstall.
[INPUT]1 2 3 4 5 6 7 8 9 wp theme list +—————–+———-+——–+———+ | name | status | update | version | +—————–+———-+——–+———+ | twentynineteen | active | none | 1.3 | | twentyseventeen | inactive | none | 2.1 | | twentysixteen | inactive | none | 1.9 | +—————–+———-+——–+———+
Export database.
[INPUT]1 2 3 wp db export Success: Exported to ‘wpcli-2019-05-06-4057acc.sql’.
Import database.
[INPUT]1 2 3 wp db import wpcli-2019-05-06-4057acc.sql Success: Imported from ‘wpcli-2019-05-06-4057acc.sql’.
Dokumentasi perintah WP-CLI secara lengkap baca di developer.wordpress.org.
Selamat mencoba ð