Manage WordPress using WP-CLI
WP-CLI, also known as the wp
command,
is a command-line utility for managing WordPress.
See the WP-CLI commands documentation for a full list of available commands.
To use the wp
command,
SSH into your server as an app’s system user
and change your current directory to the app’s web root directory.
cd apps/APPNAME/public
From the app’s public/
directory,
use the wp
commands shown on this page.
WP-CLI with WordPress Multisite
For apps using WordPress Multisite,
check the available flags for a wp
command before running a command.
For some commands, you may need to provide the --network
flag
to specify which Multisite network the command should operate on.
Manage WordPress users
Use the wp user
command to manage WordPress user accounts.
See the
wp user
documentation
for all available subcommands.
List users
See the
wp user list
documentation
for all available flags.
wp user list
Create a user
See the
wp user create
documentation
for all available flags.
wp user create USERNAME EMAIL --role=administrator
A random password will be generated and displayed in the command’s output.
Change a user’s password
See
the wp user update
documentation
for all available flags.
wp user update USERNAME --user_pass=PASSWORD
Change a user’s role
See the
wp user update
documentation
for all available flags.
wp user update USERNAME --role=ROLE
The available roles are:
administrator
editor
author
contributor
subscriber
Delete a user
See the
wp user delete
documentation
for all available flags.
Delete a user and all of their posts.
wp user delete USERNAME
To delete a user without deleting their posts,
use the --reassign
flag to transfer the user’s posts to another user.
wp user delete USERNAME --reassign=OTHER_USERNAME
Manage plugins
Use the wp plugin
command to manage WordPress plugins.
See the
wp plugin
documentation
for all available subcommands.
List installed plugins
See the
wp plugin list
documentation
for all available flags.
wp plugin list
Install a plugin
See the
wp plugin install
documentation
for all available flags.
wp plugin install PLUGIN_ID
Activate a plugin
See the
wp plugin activate
documentation
for all available flags.
wp plugin activate PLUGIN_ID
Update plugins
See the
wp plugin update
documentation
for all available flags.
Update a single plugin.
wp plugin update PLUGIN_ID
Update all plugins.
wp plugin update --all
Deactivate plugins
See the
wp plugin deactivate
documentation
for all available flags.
Deactivate one plugin.
wp plugin deactivate PLUGIN_ID
Deactivate all plugins.
wp plugin deactivate --all
Delete a plugin
See the
wp plugin delete
documentation
for all available flags.
wp plugin delete PLUGIN_ID
Manage themes
Use the wp themes
command to manage WordPress themes.
See the
wp themes
documentation
for all available subcommands.
List installed themes
See the
wp theme list
documentation
for all available flags.
wp theme list
Install a theme
See the
wp theme install
documentation
for all available flags.
wp theme install THEME_ID
Activate a theme
See the
wp theme activate
documentation
for all available flags.
wp theme activate THEME_ID
Update themes
See the
wp theme update
documentation
for all available flags.
Update a theme.
wp theme update THEME_ID
Update all themes.
wp theme update --all
Deactivate a theme
See the
wp theme deactivate
documentation
for all available flags.
wp theme deactivate THEME_ID
Delete a theme
See the
wp theme delete
documentation
for all available flags.
wp theme delete THEME_ID
Search and replace
Use the wp search-replace
command to replace contents of the WordPress database.
See the
wp search-replace
documentation
for all available flags.
Use the --dry-run
flag to see what the command would change
without making changes to the database.
wp search-replace "SEARCH_STRING" "REPLACEMENT_STRING" --dry-run
When you’re ready to make changes to the database,
run the command without the --dry-run
flag.
wp search-replace "SEARCH_STRING" "REPLACEMENT_STRING"
Replace a domain name
To replace references to an old domain name in the WordPress database,
first use the --dry-run
flag to see which tables and columns
have occurrences of the old domain name that will be replaced.
wp search-replace "old.example.com" "new.example.com" --dry-run
The output will look similar to the following.
+------------------------+-----------------+--------------+------+| Table | Column | Replacements | Type |+------------------------+-----------------+--------------+------+| wp_c7734cd387_comments | comment_content | 0 | SQL || wp_c7734cd387_links | link_url | 0 | SQL || wp_c7734cd387_links | link_image | 0 | SQL || wp_c7734cd387_options | option_value | 2 | SQL || wp_c7734cd387_posts | post_content | 1 | SQL || wp_c7734cd387_posts | post_title | 0 | SQL || wp_c7734cd387_posts | guid | 0 | SQL || wp_c7734cd387_users | display_name | 0 | SQL |+------------------------+-----------------+--------------+------+Success: 5 replacements to be made.
When you’re ready to update the database,
run the command without the --dry-run
flag.
wp search-replace "old.example.com" "new.example.com"