#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.

[sourcecode language=”php”]
<?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’,
‘daniel@automattic.com’,
‘@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 );
}

}
[/sourcecode]

Here’s what the presentation actually looked like:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>