WordPress CLI
5 min read
WP-CLI automates WordPress tasks — install, migrate, export/import, manage plugins, flush caches.
WP-CLI
# Install
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
# Essential commands
wp core install --url=example.com --title=MySite
--admin_user=admin --admin_email=a@b.com --admin_password=pass
wp db export backup.sql
wp db import backup.sql
wp search-replace 'http://localhost/mysite' 'https://mysite.com' --all-tables
wp plugin install akismet --activate
wp plugin list
wp plugin update --all
wp theme install twentytwentyfour --activate
wp user create alice alice@example.com --role=editor
wp post create --post_title='Hello' --post_status=publish
wp cache flush
wp rewrite flush
# Custom command
WP_CLI::add_command('mycommand', function($args, $assoc) {
WP_CLI::success('Done!');
});