#pdxwp: wp-cli is for WP devs on a deadline

As a part of tonight’s “It’s Tool Time: 4 Tools You Cannot Live Without” meetup, I presented on my beloved wp-cli. wp-cli is a command line interface for WordPress, and a tremendously powerful tool for WordPress developers on a deadline. So powerful, in fact, I wrote my slides as a command 15 minutes before my talk.

<?php

if ( ! defined( 'WP\_CLI' ) ) return;

WP\_CLI::add\_command( 'pdxwp-presentation', 'PDXWP\_WP\_CLI\_Presentation\_Command' );

class PDXWP\_WP\_CLI\_Presentation\_Command extends WP\_CLI\_Command {

/\*\* \* Start the presentation with a demonstration \* \* @subcommand slide \* @synopsis <number> \*/ public function slide( $args ) {

list( $num ) = $args;

$slides = array( 0 => array( 'header' => 'wp-cli is for WP devs on a deadline (http://wp-cli.org)', 'body' => array( 'Daniel Bachhuber', '[email protected]', '@danielbachhuber', ), ), 1 => array( 'header' => 'What is wp-cli?', 'body' => array( '- A Command Line Interface for WordPress', '- A powerful tool for manipulating WordPress', '- A nascent WordPress community project with lots of opportunity for contributions', ), ), 2 => array( 'header' => 'Why is it useful to me?', 'body' => array( '- Open wp shell to execute arbitrary functions', '- Install, update, or delete plugins', '- Create posts, users, terms', '- More easily manage lots of client sites', '- Export a large amount of data', '- Scaffold a theme, plugin, or unit tests for a plugin', ), ), 3 => array( 'header' => 'Where do I start?', 'body' => array( '- Install wp-cli', '- (monkey dance)', '- Profit!', ), ), 4 => array( 'header' => 'How do I install?', 'body' => array( 'On your command line:', '- git clone git://github.com/wp-cli/wp-cli.git ~/git/wp-cli', '- cd ~/git/wp-cli', '- curl -sS https://getcomposer.org/installer | php', '- php composer.phar install', ), ), 5 => array( 'header' => 'How do I write my own command?', 'body' => array( '- Create a class extending WP\_CLI\_Command', "- Register your command with WP\_CLI::add\_command( 'pdxwp-presentation', 'PDXWP\_WP\_CLI\_Presentation\_Command' );", '- public methods are subcommands', '- PHPdoc allows you to set a <synopsis>', '- Sekret pro tip: Package useful commands with your plugins :)', ), ), 6 => array( 'header' => 'Now go! http://wp-cli.org', 'body' => array( ), ), );

passthru( '/opt/local/bin/clear' ); if ( ! empty( $slides\[(int)$num\] ) ) { $slide = $slides\[(int)$num\]; for( $i = 0; $i < 23; $i++ ) {

if ( $i == 3 ) { $this->line( $slide\['header'\] ); continue; }

if ( $i == 6 ) { foreach( $slide\['body'\] as $line ) { $this->line( $line ); $i++; } } $this->line(); } } else { WP\_CLI::error( "No slide #{$num}" ); }

}

private function line( $out = '' ) { WP\_CLI::line( " " . $out ); }

}

Here’s what the presentation actually looked like:

01.png 11.png 21.png 31.png 41.png 51.png 61.png