Allow Root from wp-cli 2.5

In the past on order to run wp commands from the root user we would amend `–allow-root` to the wp command. With the release of wp-cli 2.5 we may now set the new environment variable: WP_CLI_ALLOW_ROOT just once.

 export WP_CLI_ALLOW_ROOT=true

More info here

WordPress wp-cli

Migrate a WordPress Website with UpdraftPlus for Free (without Migrator or UpdraftClone)

How to Move a WordPress Site to a New Host

We often need to move a WordPress website to a new server or set up locally. I will usually use Wordmove and SSH to do this. But sometimes the client does not have SSH access to the server. In this case I will usually use Duplicator. Recently the client website had UpdraftPlus installed on the existing website.

  1. Install the free UpdraftPlus plugin on the old and new website.
  2. Backup your old website (db, plugins, theme, uploads, etc…) using the plugin.
  3. Transfer the backup files from the old site to the new site’s updraft directory
  4. And add the following lines in the new site’s wp-config.php file: define(‘WP_SITEURL’, ‘’);
    define(‘WP_HOME’, WP_SITEURL);
  5. Login to the new site and restore the backup files via the UpdraftPlus plugin. 
  6. Once restored, you will need to update the new website’s database with the new url. You can either use wp-cli or install a database Search and Replace plugin.

Search and Replace with wp-cli

wp search-replace

WordPress wp-cli

Regenerate image sizes in WordPress

Regenerate your site’s images.

wp media regenerate --yes
Ubuntu WordPress wp-cli

Delete image sizes from WordPress

Easily delete images sizes from the command line.
This is permanent!

 find wp-content/uploads/*  -iname '*-2000x750.*' -exec rm {} \;

Creating a new WordPress user from the command line with wp-cli

wp user create sunny --role=administrator --user_pass=PASSWORD

It may be simpler to update an existing user. e.g.

wp user update 1 --display_name=Admin --user_pass=PASS

Change post type

wp db query "UPDATE  `wp_posts` SET  `post_type` =  'new-cpt-post' WHERE  `post_type` = 'old-cpt-post';"
WordPress wp-cli

Optimize WordPress images

Easily optimize images using wp-cli,

wp package install typisttech/image-optimize-command:@stable
# optimize specific attachments
$ wp image-optimize attachment 123 223 323

# optimize certain number of attachments
$ wp image-optimize batch --limit=20

# restore the full sized images of specific attachments
$ wp image-optimize restore 123 223 323
$ wp media regenerate 123 223 323

# restore all full sized images and drop all meta flags
$ wp image-optimize reset
$ wp media regenerate

# Find and optimize images under a given directory **without backup**
$ wp image-optimize find /path/to/my/directory --extensions=gif,jpeg,jpg,png,svg,webp

# shortcusts for `wp image-optimize find` **without backup**
$ wp image-optimize mu-plugins
$ wp image-optimize plugins
$ wp image-optimize themes
$ wp image-optimize wp-admin
$ wp image-optimize wp-includes

# learn more
$ wp help image-optimize
$ wp help image-optimize <subcommand>

wp import backup.sql.gz

Import a gzip compressed database

gunzip < backup.sql.gz | wp db import -

Settings up a new WordPress install with wp-cli


wp core update --allow-root; 
wp option update timezone_string "America/New_York" --allow-root; 
wp option update posts_per_page 9 --allow-root; 
wp rewrite structure '/%category%/%postname%/' --allow-root;
wp user update 1 --display_name=Admin --user_pass=PASS--allow-root;
wp option update admin_email --allow-root;


wp plugin delete hello --allow-root;
wp plugin install query-monitor --activate --allow-root;
wp plugin install nginx-helper --activate --allow-root;
wp plugin install "" --activate --allow-root;