Nội dung
WP-CLI is a set of tools that help developers easily manage installation packages for WordPress websites. With WP-CLI, developers can perform backend tasks easily through the command line.
The tasks that WP-CLI supports can be listed as follows:
- Install, set up, update and remove themes, plugins, widgets.
- Manage posts and comments on the page.
- Manage uploaded media files.
- Manage menus.
- Manage user list.
- Manage cron jobs.
- Manage site options.
How to use WP CLI to administer the plugin?
See the list of plugins on the website
To see the list of plugin libraries, go to the folder containing the source code and enter the following command:
wp plugin list
[dotrungq@chv10-24851 linuxcanban.com]$ wp plugin list
+-----------------------+----------+--------+---------+
| name | status | update | version |
+-----------------------+----------+--------+---------+
| a3-lazy-load | inactive | none | 2.0.0 |
| akismet | active | none | 4.1.3 |
| amp | active | none | 1.4.2 |
| classic-editor | inactive | none | 1.5 |
| contact-form-7 | inactive | none | 5.1.6 |
| easy-watermark | active | none | 1.0.5 |
| easy-wp-smtp | active | none | 1.3.9.1 |
| imagify | inactive | none | 1.9.8.1 |
| insert-post-ads | active | none | 1.3.2 |
| litespeed-cache | active | none | 2.9.9.2 |
| native-lazyload | inactive | none | 1.0.2 |
| popups | inactive | none | 1.9.3.8 |
| google-site-kit | active | none | 1.1.4 |
| td-composer | active | none | 1.0 |
| td-social-counter | active | none | 4.2 |
| wordfence | active | none | 7.4.2 |
| wordpress-seo-premium | active | none | 12.1 |
| advanced-cache.php | dropin | none | |
| object-cache.php | dropin | none | |
+-----------------------+----------+--------+---------+
Deactivated a plugin
For example, I will deactivate the Easy SMTP plugin with the following command:
wp plugin deactivate easy-wp-smtp
Output
[dotrungq@chv10-24851 linuxcanban.com]$ wp plugin deactivate easy-wp-smtp
Plugin 'easy-wp-smtp' deactivated.
Success: Deactivated 1 of 1 plugins.
[dotrungq@chv10-24851 linuxcanban.com]$
Activate a plugin
To activate the Plugin, enter the command below, for example, I will reactivate the Easy SMTP plugin.
wp plugin activate easy-wp-smtp
Output
[dotrungq@chv10-24851 linuxcanban.com]$ wp plugin activate easy-wp-smtp
Plugin 'easy-wp-smtp' activated.
Success: Activated 1 of 1 plugins.
Delete a plugin
To remove a plugin using the CLI, you specify the plugin name to remove and run the following command:
wp plugin delete contact-form-7
Output
[dotrungq@chv10-24851 linuxcanban.com]$ wp plugin delete contact-form-7
Deleted 'contact-form-7' plugin.
Success: Deleted 1 of 1 plugins.
Install a plugin using CLI
CLI has support plugin installation and to do that, you need to specify the plugin name. So here I will guide you to find the plugin and install it.
Find a plugin
I will find the SSL plugin, I enter SSL to suggest plugins with this related name.
wp plugin search ssl
Output [dotrungq@chv10-24851 linuxcanban.com]$ wp plugin search ssl Success: Showing 10 of 1584 plugins. +-----------------------------------------------------------------------+----------------------------+--------+ | name | slug | rating | +-----------------------------------------------------------------------+----------------------------+--------+ | Really Simple SSL | really-simple-ssl | 100 | | WP Force SSL | wp-force-ssl | 94 | | W3 Total Cache | w3-total-cache | 86 | | Cloudflare Flexible SSL | cloudflare-flexible-ssl | 96 | | SSL Insecure Content Fixer | ssl-insecure-content-fixer | 96 | | Free SSL Certificate for WordPress – SSL Zen | ssl-zen | 96 | | Easy HTTPS Redirection (SSL) | https-redirection | 84 | | One Click SSL | one-click-ssl | 98 | | JSM's Force HTTP to HTTPS (SSL) | Simple, Safe, and Best for SEO | jsm-force-ssl | 100 | | WP Fastest Cache | wp-fastest-cache | 98 | +-----------------------------------------------------------------------+----------------------------+--------+
If no such plugin exists in the list above, you can enter the option –page=2 to go to page 2.
- For example: wp plugin search ssl –page=2
Install plugin
I will install the Really Simple SSL plugin, you need to run the install command with the name slug.
wp plugin install really-simple-ssl
Output [dotrungq@chv10-24851 linuxcanban.com]$ wp plugin install really-simple-ssl Installing Really Simple SSL (3.2.7) Loading installation package from https://downloads.wordpress.org/plugin/really-simple-ssl.3.2.7.zip... Unpacking files... Installing the expansion pack... The plugin has been installed successfully. Success: Installed 1 of 1 plugins.
- Hotline 247: 028 888 24768 (Ext 0)
- Ticket/Email: You can use your email to register for the service and send it directly to: support@azdigi.com
- Visit the AZDIGI website to refer to the best Hosting/VPS service in Vietnam.