wordpress and the command line
DESCRIPTION
How to use WP-CLI to manage your WordPress site via the command line. From basic management like installing & updating plugins and themes, to scripting a installation workflow, this tool is a WordPress DevOps' best friend.TRANSCRIPT
WordPress & the command line
Kelly Dwan @ryelle
NERD Summit • Sept 2014
About Me
WordPress Developer
Core Contributor
Boston WordPress Organizer
“Why should I use the command line, when WordPress already has such a fantastic UI?”
• Already included in VVV, VIP Quickstart https://github.com/Varying-Vagrant-Vagrants/VVV/ https://github.com/Automattic/vip-quickstart
• Most major hosts include it: DreamHost, Media Temple, BlueHost, SiteGround, 1&1…
• Installation:http://wp-cli.org/#install
Basic Commands
wp command subcommand <argument> —flag
• wp core version
• wp core update
• wp plugin list
• wp plugin install <name> [--activate]
• wp theme list
• wp theme activate <name>
• wp core download
• wp core config
• wp core install / multisite-install
• wp core multisite-convert
wp help
wp help <command>
wp help <command> <subcommand>
Content Management
• wp post create
• wp post delete
• wp post url
• wp post meta list
• wp post meta update
• wp comment approve
• wp comment delete $(wp comment list --status=spam --format=ids)
• wp media import
• wp term create
• wp term generate
• wp term list
Tools
• wp export [—skip_comments]
• wp import
• wp media regenerate
Advanced Management
• wp user create
• wp user import-csv
• wp user remove-cap
• wp role list
• wp cap list
• wp cron test
• wp cron schedule list
• wp cron event list
• wp cron event run
• wp rewrite list
• wp rewrite flush
• wp rewrite structure
Custom Commands
–Matt Wiebe, Why You Should Develop Plugins With wp-cli
“Adding commands to your plugin is great for encouraging good API design, collaborating
amidst a changing data structure, efficiency, and better debugging.”
• Jetpack module control
• wp jetpack module list
• wp jetpack module activate
• BackUpWordPress
• wp backup [lots of options]
how to write your own
if ( defined('WP_CLI') && WP_CLI ) { include __DIR__ . '/my-command.php'; }
class Example_Command extends WP_CLI_Command { /** * Prints a greeting. * @synopsis <name> */ function hello( $args, $assoc_args ) { list( $name ) = $args; ! // Print a success message WP_CLI::success( "Hello, $name!" ); } } !WP_CLI::add_command( 'example', 'Example_Command' );
class Example_Command extends WP_CLI_Command { /** * Prints a greeting. * @synopsis <name> [<last-name>] */ function hello( $args, $assoc_args ) { list( $name ) = $args; ! // Print a success message WP_CLI::success( "Hello, $name!" ); } } !WP_CLI::add_command( 'example', 'Example_Command' );
• WP CLI Commands Cookbook walks through this in more detail.
Automated Migrations
From WordPress
• wp export [on source site]
• wp import [on destination]
• wp search-replace <old> <new> —skip-columns=guid —dry-run
From Other CMSs
• Importing (any!) Content with WP-CLI
• https://github.com/wp-cli/wp-cli/wiki/External-Resources
• http://redradar.net/nerds-wp-cli