Skip to content

A collection of command-line for managing WordPress installations.

Notifications You must be signed in to change notification settings

thejaydip/WP-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Installing WordPress with WP-CLI

Checking WP-CLI Version

Simply type this command to check the WP-CLI version information:

To install WP-CLI click here.

wp --info

Create directory

cd /var/www/html

mkdir demo

wp core download

wp core config --dbname=db_gutenberg --dbuser=root --dbpass=mysql123 --dbhost=localhost --dbprefix=rl_ --extra-php <<PHP

define( 'WP_DEBUG_LOG', true );

PHP

Use the following command for creating the database. Note that this command will create a fresh database with the name used in wp-config file.

wp db create

wp core install --url="http://localhost/demo" --title="demo Test" --admin_user="admin" --admin_password="admin" --admin_email="test@test.com"

Use the following command to Enable DEBUG and DEBUG LOG.

wp config set WP_DEBUG true --raw

wp config set WP_DEBUG_LOG true --raw

To activate the theme, type:

wp theme activate [theme name]

Display the WordPress version

wp core version

Updating the WordPress core files:

wp core update

To install a plugin, type the following command.

wp plugin install [plugin name]

To update all themes

wp theme update --all

To update all plugins

wp plugin update --all

Reinstall WordPress Core

wp core download --skip-content --force

Database

Check database.

wp db check

Create a new database.

wp db create

Drop an existing database.

wp db drop --yes

Reset the current database.

wp db reset --yes

Delete all tables that match the current site prefix.

wp db clean --yes

Export database

wp db export

Export certain tables

wp db export --tables=wp_options,wp_users

Import MySQL from a file.

wp db import wordpress_dbase.sql

Displays the database table prefix.

wp db prefix

Repairs the database.

wp db repair

Executes a SQL query against the database. Execute a query stored in a file

wp db query < debug.sql

Check all tables in the database

wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"

Displays the database name and size.

wp db size

WordPress Menus

Create a new menu

wp menu create "My Menu"

List existing menus

wp menu list

Create a new menu link item

wp menu item add-custom my-menu Apple http://apple.com --porcelain 1922

Assign the 'my-menu' menu to the 'primary' location

wp menu location assign my-menu primary

Deletes one or more menus.

wp menu delete "My Menu"

Database Search And Replace

wp search-replace 'http://example.dev' 'http://example.com' --precise --recurse-objects --all-tables

Regenerating Thumbnails

Regenerating All Thumbnails

To regenerate all thumbnails for all images inside your WordPress media library, you can use the following command:

wp media regenerate --yes

Regenerating Missing Thumbnails

You can regenerate thumbnails for only the missing image sizes using the --only-missing option like this:

wp media regenerate --only-missing

Regenerating Thumbnails for Specific Images

If you want to regenerate thumbnails for a specific image, you can specify it by including the attachment ID after the command like this:

wp media regenerate 122

To regenerate thumbnails for multiple specified attachment IDs, just add them to the command like the following example:

wp media regenerate 125 234 456

Keeping Old Thumbnail Sizes

When regenerating your WordPress media library image thumbnails, the default behavior is to delete the old thumbnails. If you want to keep them, you can use the --skip-delete option:

wp media regenerate --skip-delete

Regenerating Specific Thumbnail Sizes

wp media regenerate --image_size=large

List all registered image sizes

wp media image-size

Maintenance Mode

Activating Maintenance Mode

wp maintenance-mode activate

Deactivate Maintenance Mode

wp maintenance-mode deactivate

Display Maintenance mode status.

wp maintenance-mode status

Get Maintenance mode status for scripting purpose.

wp maintenance-mode is-active

Importing WordPress Content

Importing WordPress WXR (.xml) Files

wp import my-file.xml

Importing WordPress WXR (.xml) Files

wp import my-file.xml

Creating Non-Existent Authors

If you want to create any authors that don't already exist, set value of the --authors option to create like this:

wp import my-file.xml --authors=create

Skipping Non-Existent Authors

If you'd like to just leave the post's author empty if the user doesn't already exist, you can set the value of the --authors option to skip:

wp import my-file.xml --authors=skip

Skipping Attachment Imports

wp import my-file.xml --skip=attachment

Skipping Thumbnail Generation

wp import my-file.xml --skip=image_resize

Exporting WordPress Content

Exporting All WordPress Content

wp export

Changing Your Export File Path

wp export --dir="/my/path/here"

Exporting Without Comments

wp export --skip_comments

WordPress All Cron

Displaying All Cron Events

wp cron event list

Running All WordPress Cron Events

If you want to trigger all currently due cron events (events that are due but haven't been run yet), you can run them with the following command:

wp cron event run --due-now

WordPress cache flush

Manually Clearing the Object Cache with WP-CLI

wp cache flush

WordPress Transient

Transients deleted from the database

wp transient delete --all

WordPress search and replace in DB

wp search-replace 'old.example.com' 'new.example.com'

Searching All Database Tables

wp db search 'my search string'

Searching Through Specific Tables

wp db search 'my search string' wp_posts

WordPress Core Language Packs

Listing Available Language Packs

To view a list of all language packs that can be installed with WP-CLI, simply use the following command:

wp language core list

Listing Installed Language Packs

To get a list of the currently installed language packs for WordPress core, issue the following WP-CLI command:

wp language core list --status=installed

Installing a Language Pack

To install a language pack for WordPress core, just grab the language name (the list command helps with this) and install it using the install subcommand like this:

wp language core install es_ES

Activating a Language Pack

wp language core activate es_ES

Uninstalling a Language Pack

wp language core uninstall es_ES

Updating All Language Packs

wp language core update

Create POT file for theme and plugin

wp i18n make-pot /var/www/html/demo/wp-content/themes/hello-world/ /var/www/html/demo/wp-content/themes/hello-world/languages/hello-world.pot

wp i18n make-pot /var/www/html/demo/wp-content/plugins/hello-world-addons/ /var/www/html/demo/wp-content/plugins/hello-world-addons/languages/hello-world-addons.pot

WordPress Plugin

Activate plugin

wp plugin activate hello

Deactivate plugin

wp plugin deactivate hello

To deactivate all your plugins at once run the following command.

wp plugin deactivate --all

Delete plugin

wp plugin delete hello

Install the latest version from wordpress.org and activate

wp plugin install bbpress --activate

List active plugins on the site.

wp plugin list --status=active --format=json

Uninstalls one or more plugins.

wp plugin uninstall hello

Updates one or more plugins for development version.

wp plugin update bbpress --version=dev

Update all plugins

wp plugin update --all

Update all plugins except akismet

wp plugin update --all --exclude=akismet

You can also install older versions of WordPress plugins if needed with the --version attribute.

wp plugin install wordpress-seo --version=4.8 --activate

Install theme unit test data

Below you can find the WP-CLI commands for all of the above tasks.

Go to on WordPress Project Directory Path:

curl -O https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml

wp plugin install wordpress-importer --activate

wp import ./theme-unit-test-data.xml --authors=create

rm theme-unit-test-data.xml

About

A collection of command-line for managing WordPress installations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published