WP CLI is a command line tool to interact with your WordPress installation. Its a way to configure and query WordPress websites without ever having to go to the admin interface.
I find to use it myself very often especially to add, remove and activating plugins but also to generate new users or just to run some simple queries to find out more about the installation. If you haven’t used at all visit wp-cli.org to get to know more about it. In this post however I would like to collect some of the most used commands. Here we go:
Common WP CLI commands
I will give you a few example commands, in some cases they are specific to your config and installation. In these cases I wrote these parameter in all CAPITAL letters. Replace all caps words with your own installs configuration. parameters. For instance replace PLUGINNAME with wordpress-seo if you would like to install the Yoast SEO plugin. Ok, here we go!
1. Downloading WordPress using WP CLI commands
Download an instance of WordPress using WP-CLI. Useful when you are trying to set up a new local instance of an exiting website on a server. If you already have a local DB and files and all you need to get is the WP core files.
wp core download // To skip default themes and hello plugin etc. wp core download --skip-content // To override any existing files in directory wp core download --force
2. Installing WordPress
Running the default installation process to create a DB user and password etc.
wp core install --url=EXAMPLE.COM --title=EXAMPLE --admin_user=USERNAME --admin_password=STRONGPASSWORD --admin_email=EXAMPLE@EMAIL.COM # Install WordPress without disclosing admin_password to bash history wp core install --url=example.com --title=Example --admin_user=supervisor --firstname.lastname@example.org --prompt=admin_password < admin_password.txt
2.1 Get Version ow your WP install
wp core version
2.2 Setting the Admin Email
WP email address where systems emails get sent to, through the user interface you can change this under Settings > General. But this may need to send an email for you to confirm etc.
You can do it with wp cli as well:
wp option update admin_email email@example.com
3. Update WP core using WP CLI
wp core update # update to a specific version wp core update --version=4.5.2 --force # update DB only, for pending DB updates wp core update-db # check if update available wp core check-update
more here : https://developer.wordpress.org/cli/commands/core/update/ https://developer.wordpress.org/cli/commands/core/check-update/
4. Handling Plugins with WP CLI
4.1 Installing and activating plugins
# Install and Activate a Plugin, use plugin instead of PLUGIN wp plugin install PLUGIN--activate # Install a specific version from WordPress.org using URL wp plugin install https://downloads.wordpress.org/plugin/perfecto-portfolio.1.0.0.zip –activate # force reinstall of all plugins wp plugin install $(wp plugin list --field=name) --force
4.2 Deactivating and uninstalling plugins
# Deactivate plugin wp plugin deactivate PLUGIN # Remove and Delete plugin $ wp plugin delete PLUGIN
5. Managing users with WP CLI
5.1 Creating a user and assigning a role
# Create new user wp user create USERNAME USER@EMAIL.COM # Assign a role to a user wp user add-role USERNAME administrator
5.2 Delete a user
# Delete user 123 and reassign posts to user 567 wp user delete 123 --reassign=567 # Delete all contributors and reassign their posts to user 2 wp user delete $(wp user list --role=contributor --field=ID) --reassign=2
5. 3. Regenerate Password for user
wp user reset-password [username] [username 2] [username ..] # this will send a regenerate password email for the user
6. Managing Media and Images
6.1 Regenerate image styles and sizes
# Re-generate only the thumbnails of "large" image size for all images. wp media regenerate --image_size=large # Regenerate thumbnails for given attachment IDs. $ wp media regenerate 123 124 125 # Re-generate all thumbnails that have IDs between 1000 and 2000. $ seq 1000 2000 | xargs wp media regenerate
7. Creating or scaffolding new post types and Taxonomies
7.2 Scaffolding new taxonomies
$ wp scaffold taxonomy # usage usage: wp scaffold taxonomy <slug> [--post_types=<post-types>] [--label=<label>] [--textdomain=<textdomain>] [--theme] [--plugin=<plugin>] # Example $ wp scaffold taxonomy academic-level --label="Academic Level" --post_types=uscr-event,glossary,page,post --theme=hello-elementor-child
I hope this helps you all,