Fun with WP CLI

Add yourself as an admin user
wp user create myusername email@email.com --role=administrator --user_pass='password'

Quickly reset a list of user passwords
wp user list
wp user update user1 user2 --user_pass='password'

Correct URLs after DB migration
wp option update siteurl 'http://domain.com'
wp option update home 'http://domain.com'
wp search-replace 'olddomain.com' 'newdomain.com'

Generate MySQL prompt
wp db cli

Regenerate thumbs
wp media regenerate

Convert to subdomain multisite install
wp core multisite-convert --title='My Network' --subdomains

Update the title for page with slug ‘about’
wp post list --pagename=about
wp post update <post ID> --post_title='New Title'

Update ‘Mood: Happy’ to ‘Mood: Sad’ for the same page, without knowing the name of the field
wp post meta list <post ID>
wp post meta update <post ID> my_mood 'Sad'

Remove unneeded themes
wp theme list
wp theme delete themename1 themename2

Toggle state of plugins ( active / inactive )
wp plugin toggle plugin1 plugin2

Create new empty child theme
wp scaffold child-theme <slug> --parent_theme=<slug> [--theme_name=<title>] [--author=<full-name>] [--author_uri=<uri>] [--theme_uri=<uri>] [--activate]

Ex:
wp scaffold child-theme my-child --parent_theme=genesis --theme_name='My Child' --author='Pat Ramsey' --author_uri=http://testsite.com --theme_uri=http://testsite.com --activate

Comments

  1. Thanks Pat.

    Question for you: I’m looking to use a script someone wrote to run multisite upgrades (https://gist.github.com/westonruter/beb6120e61e9691e88ac).

    In the CLI Wiki / Commands Cookbook under Loading it says that one way to use a 3rd party CLI command is to run

    wp –require=my-command.php my-command

    I tried that, as

    wp –require=/path/to/multisite-network-upgrade.php multisite-network-upgrade

    and got

    Error: This does not seem to be a WordPress install.

    What am I missing here?

  2. Never mind – I figured it out.

    Answering my own question: you need to cd into the target directory first, then can run the above and it does the upgrade.

    So:

    cd /path/to/WPsiteDirectory
    wp –require=/path/to/multisite-network-upgrade.php multisite-network-upgrade

    results in :

    Success: upgraded http://subdomain1.mydomain.com
    Success: upgraded http://subdomain2.mydomain.com
    .
    .
    .
    Success: upgraded http://subdomainX.mydomain.com

%d bloggers like this: