Examples of how to use Wordpress WP-CLI

In our last article we have installed WP-CLI and saw how wp-cli can help us with Wordpress administration. (if you have not read it see here Install WP-CLI). Is time for us to see how to use wp-cli to optimize our Wordpress administration and be more efficient and exact on what we are doing. Follow the examples and apply them by your self.

How to list all the themes available in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp theme list
+-------------------+----------+--------+---------+

| name              | status   | update | version |
+-------------------+----------+--------+---------+

| suprema           | active   | none   | 1.1.2   |
| twentyfifteen     | inactive | none   | 1.6     |
| twentysixteen_old | inactive | none   | 1.2     |
| wpbkp             | inactive | none   |         |
+-------------------+----------+--------+---------+

How to  list all available plugins in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp plugin list
+--------------------------------------------+--------+-----------+----------+

| name                                       | status | update    | version  |
+--------------------------------------------+--------+-----------+----------+

| after-post-manager                         | active | none      | 3.3      |
| akismet                                    | active | none      | 3.2      |
| amazon-web-services                        | active | none      | 1.0      |
| autoptimize                                | active | none      | 2.1.0    |
| contact-form-7                             | active | none      | 4.5.1    |
| contact-form-7-mailchimp-extension         | active | none      | 0.4.31   |
| crayon-syntax-highlighter                  | active | none      | 2.8.4    |
| download-monitor                           | active | none      | 1.9.5    |
| email-before-download                      | active | none      | 3.4.2    |
| header-footer                              | active | none      | 2.0.3    |
| iframe                                     | active | none      | 4.3      |
| insert-post-ads                            | active | none      | 1.0.6    |
| jetpack                                    | active | available | 4.3.1    |
| list-category-posts                        | active | none      | 0.70     |
| mailchimp-top-bar                          | active | none      | 1.2.15   |
| remove-query-strings-from-static-resources | active | none      | 1.3.1    |
| reveal-ids-for-wp-admin-25                 | active | none      | 1.4.6.2  |
| scripts-to-footerphp                       | active | none      | 0.6.1    |
| select-core                                | active | none      | 1.0      |
| simple-file-downloader                     | active | none      | 1.0.4    |
| wp-smushit                                 | active | none      | 2.4.5    |
| yet-another-related-posts-plugin           | active | none      | 4.3.1    |
| wordpress-seo                              | active | none      | 3.7.0    |
| youtube-embed-plus                         | active | none      | 11.4     |
+--------------------------------------------+--------+-----------+----------+

How to list all users  in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp user list
+----+--------------+--------------+------------------------+---------------------+---------------+

| ID | user_login   | display_name | user_email             | user_registered     | roles         |
+----+--------------+--------------+------------------------+---------------------+---------------+

| 3  | adminusr     | admin         | ao@aodba.com           | 2016-09-21 11:32:48 | subscriber    |
| 2  | AO           | AODBA        | o_3@aodba.com          | 2016-06-24 03:36:42 | administrator |
| 1  | useradm      | AODBA        | drian1@gmail.com       | 2016-05-07 13:48:17 | administrator |
+----+--------------+--------------+------------------------+---------------------+---------------+

How to  create a new user in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp user create dan dna@example.com --role=author

Success: Created user 3.
Password: pass123#$%

How to optimize your Database  in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp db optimize
aodba451_wordpress.wp_amazoncache          Table is already up to date
aodba451_wordpress.wp_blog_versions        Table is already up to date
aodba451_wordpress.wp_blogs                Table is already up to date
aodba451_wordpress.wp_caa_profile_db       Table is already up to date

How to  update an user in Wordpress with WP-CLI

 aodba451@sgp25 [~/www]#wp user update 3 --display_name=Dan --user_pass=DanPass

         Success: Updated user 123.

How to  download and install a plugin in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wget https://downloads.wordpress.org/plugin/mailchimp-for-wp.4.0.6.zip
--2016-10-18 20:29:55--  https://downloads.wordpress.org/plugin/mailchimp-for-wp.4.0.6.zip

Resolving downloads.wordpress.org (downloads.wordpress.org)... 66.155.40.186, 66.155.40.189, 66.155.40.188, ...
Connecting to downloads.wordpress.org (downloads.wordpress.org)|66.155.40.186|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1444241 (1.4M) [application/zip]
Saving to: 'mailchimp-for-wp.4.0.6.zip'

mailchimp-for-wp.4.0.6.zip                                 100%[=========]   1.38M   954KB/s   in 1.5s

2016-10-18 20:29:57 (954 KB/s) - 'mailchimp-for-wp.4.0.6.zip' saved [1444241/1444241]
Install and Activate Plugin
aodba451@sgp25 [~/www]# wp plugin install mailchimp-for-wp.4.0.6.zip --activate

Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Activating 'mailchimp-for-wp'...
Success: Plugin 'mailchimp-for-wp' activated.

How to  verifiy a plugin status in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp plugin status mailchimp-for-wp
Plugin mailchimp-for-wp details:
    Name: MailChimp for WordPress
    Status: Active
    Version: 4.0.6
    Author: ibericode
    Description: MailChimp for WordPress by ibericode. Adds various highly effective sign-up methods to your site.

How to  search for a plugin in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp plugin search gmail
Success: Showing 10 of 752 plugins.
+---------------------------------+---------------------------------+--------+

| name                            | slug                            | rating |
+---------------------------------+---------------------------------+--------+

| Gmail Like Gravatar Fallback    | gmail-like-gravatar-fallback    | 100    |
| Gmail SMTP                      | gmail-smtp                      | 86     |
| EDD Customer Lookup for Gmail   | edd-customer-lookup-for-gmail   | 100    |
| Postman Gmail API Extension     | postman-gmail-extension         | 100    |
| WP Gmail SMTP                   | wp-gmail-smtp                   | 100    |
| Fraud Gmail Filter              | fraud-gmail-filter              | 0      |
| Import emails to Gmail Contacts | import-emails-to-gmail-contacts | 0      |
| Gmail Style Preloader           | gmail-style-preloader           | 100    |
| Postman SMTP Mailer/Email Log   | postman-smtp                    | 98     |
| Inbox Status                    | inbox-status                    | 60     |
+---------------------------------+---------------------------------+--------+

How to disable/deactivate a plugin  in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp plugin  deactivate mailchimp-for-wp
Success: Plugin 'mailchimp-for-wp' deactivated.
aodba451@sgp25 [~/www]# wp plugin status mailchimp-for-wp
Plugin mailchimp-for-wp details:
    Name: MailChimp for WordPress
    Status: Inactive
    Version: 4.0.6
    Author: ibericode
    Description: MailChimp for WordPress by ibericode. Adds various highly effective sign-up methods to your site.

How to  enable/activate a plugin in Wordpress with WP-CLI

aodba451@sgp25 [~/www]# wp plugin  activate mailchimp-for-wp
Success: Plugin 'mailchimp-for-wp' activated.
aodba451@sgp25 [~/www]# wp plugin status mailchimp-for-wp
Plugin mailchimp-for-wp details:
    Name: MailChimp for WordPress
    Status: Active
    Version: 4.0.6
    Author: ibericode
    Description: MailChimp for WordPress by ibericode. Adds various highly effective sign-up methods to your site.

How to  delete a plugin in Wordpress with WP-CLI

The will completely remove the plugin from your Wordpress installation
aodba451@sgp25 [~/www]# wp plugin delete mailchimp-for-wp
Success: Deleted 'mailchimp-for-wp' plugin.
aodba451@sgp25 [~/www]# wp plugin status mailchimp-for-wp
Error: The 'mailchimp-for-wp' plugin could not be found.

How to update a plugin in Wordpress with WP-CLI

List available for update plugins and update one of them.
aodba451@sgp25 [~/www]# wp plugin list | grep available
jetpack active  available       4.3.1
w3-total-cache  active  available       0.9.5
js_composer     active  available       4.11.2.1
amazon-s3-and-cloudfront        active  available       1.1
aodba451@sgp25 [~/www]# wp plugin update amazon-s3-and-cloudfront
Enabling Maintenance mode...
Downloading update from https://downloads.wordpress.org/plugin/amazon-s3-and-cloudfront.1.1.1.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Disabling Maintenance mode...
Success: Updated 1/1 plugins.
+--------------------------+-------------+-------------+---------+

| name                     | old_version | new_version | status  |
+--------------------------+-------------+-------------+---------+

| amazon-s3-and-cloudfront | 1.1         | 1.1.1       | Updated |
+--------------------------+-------------+-------------+---------+