Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Manage WordPress with Awesome using wp-cli           WordCamp Vegas 2012    Mike Schroder (DH-Shredder)    @GetSource - ht...
Who Am I?•   Mike Schroder, a.k.a DH-Shredder, a.k.a. @GetSource•   Third Culture Kid, enjoy Coffee & Sailing•   WordPress...
There are two groups     of people.
Those who use the  command line
Those who are going to use    the command line
Don’t be afraid of the CLI.       It’s your friend.
Oh, you like the CLI?wp-cli will make your life better.
What’s wp-cli?super-cool Open Source tool  to manage WordPress
Why so cool?Headed up by Andreas Creten and     Cristi Burcă (scribu)
Why so cool?Uses WordPress itself to perform         operations
Why so cool? Automation!
What can I do with it?
No, Really.
Update WordPresswp core update
Install a Themewp theme install sunspot
Reset to default themewp theme activate twentytwelve
Backup your Databasewp db export backup.sql
Update Pluginswp plugin update --all
What do I need to run it?
What do I need to run it?•   SSH access to your WordPress installs directory
What do I need to run it?•   SSH access to your WordPress installs directory•   PHP 5.3+
What do I need to run it?•   SSH access to your WordPress installs directory•   PHP 5.3+•   WordPress 3.3+
What do I need to run it?•   SSH access to your WordPress installs directory•   PHP 5.3+•   WordPress 3.3+•   Enough RAM f...
What do I need to run it?•   SSH access to your WordPress installs directory•   PHP 5.3+•   WordPress 3.3+•   Enough RAM f...
Okay. Got that covered.  How can I get this     Awesomeness?
Download wp-cligit clone --recursive git://github.com/wp-cli/wp-cli.git
Make it runnable from your    WordPress Install.
If you have sudo:sudo utils/dev-build
Otherwise, add an alias      (.bashrc/.bash_profile)alias wp=/home/user/wp-cli/src/bin/wp;
In ~/.bash_profile:if [ -f ~/.bashrc ]; then   source ~/.bashrcfi(http://www.joshstaiger.org/archives/2005/07/bash_profile_...
You’ve got it installed?   Let’s dig deeper.
wp-cli is extensible.
Sample Plugin:WCLV Backup.
Goal:wp wclv backup [--no-db] [/dir/outputfile.tar.gz]
Our Plan:- Use built-in SQL Backup- Create a .tar.gz of install and db
Define the Base Command<?php// Let WP_CLI know we exist!// Earlier versions of wp-cli used WP_CLI::addCommand()WP_CLI::add...
Define Sub-Commands•   $args: stand-alone arguments•   $assoc_args: --arg=value style in associative arrayclass WCLV_Backu...
Grab Filenamefunction backup( $args, $assoc_args ) {! $filename = $dbname = null;!   // If a filename isnt specified, defa...
Handle --no-db•   SQL file not using temp location for simplicity of demo.! // If --no-db is specified, dont include the d...
Back it up!•   See class-wp-cli.php for more magical functions! // GZ/Tar and Backup the install!! WP_CLI::line( "Backing ...
ERROR ERROR!   // Will automatically exit on WP_CLI::error, but not WP_CLI::success.!   if ( 0 == $result ) {!   !   WP_CL...
Resources!    •   https://github.com/wp-cli/wp-cli    •   https://github.com/wp-cli/wp-cli/wiki/List-of-internal-commands ...
Manage WordPress with Awesome using wp cli
Upcoming SlideShare
Loading in …5
×

Manage WordPress with Awesome using wp cli

2,731 views

Published on

Manage WordPress with Awesome using wp-cli talk from WordCamp Vegas 2012.

Does updating all your plugins by running `wp plugin update –all` sound too good to be true? Enter wp-cli, an open source WordPress management tool. Learn how to install it locally or globally on your host, perform common WordPress administration tasks, and expand its functionality with plugins of your own.

Presented by Mike Schroder (@GetSource/DH-Shredder)

Published in: Technology
  • Be the first to comment

Manage WordPress with Awesome using wp cli

  1. 1. Manage WordPress with Awesome using wp-cli WordCamp Vegas 2012 Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net
  2. 2. Who Am I?• Mike Schroder, a.k.a DH-Shredder, a.k.a. @GetSource• Third Culture Kid, enjoy Coffee & Sailing• WordPress Core and wp-cli Contributor• Happy DreamHost Employee
  3. 3. There are two groups of people.
  4. 4. Those who use the command line
  5. 5. Those who are going to use the command line
  6. 6. Don’t be afraid of the CLI. It’s your friend.
  7. 7. Oh, you like the CLI?wp-cli will make your life better.
  8. 8. What’s wp-cli?super-cool Open Source tool to manage WordPress
  9. 9. Why so cool?Headed up by Andreas Creten and Cristi Burcă (scribu)
  10. 10. Why so cool?Uses WordPress itself to perform operations
  11. 11. Why so cool? Automation!
  12. 12. What can I do with it?
  13. 13. No, Really.
  14. 14. Update WordPresswp core update
  15. 15. Install a Themewp theme install sunspot
  16. 16. Reset to default themewp theme activate twentytwelve
  17. 17. Backup your Databasewp db export backup.sql
  18. 18. Update Pluginswp plugin update --all
  19. 19. What do I need to run it?
  20. 20. What do I need to run it?• SSH access to your WordPress installs directory
  21. 21. What do I need to run it?• SSH access to your WordPress installs directory• PHP 5.3+
  22. 22. What do I need to run it?• SSH access to your WordPress installs directory• PHP 5.3+• WordPress 3.3+
  23. 23. What do I need to run it?• SSH access to your WordPress installs directory• PHP 5.3+• WordPress 3.3+• Enough RAM for shell processes to run WordPress
  24. 24. What do I need to run it?• SSH access to your WordPress installs directory• PHP 5.3+• WordPress 3.3+• Enough RAM for shell processes to run WordPress• Easiest on Linux & MacOS
  25. 25. Okay. Got that covered. How can I get this Awesomeness?
  26. 26. Download wp-cligit clone --recursive git://github.com/wp-cli/wp-cli.git
  27. 27. Make it runnable from your WordPress Install.
  28. 28. If you have sudo:sudo utils/dev-build
  29. 29. Otherwise, add an alias (.bashrc/.bash_profile)alias wp=/home/user/wp-cli/src/bin/wp;
  30. 30. In ~/.bash_profile:if [ -f ~/.bashrc ]; then source ~/.bashrcfi(http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html)
  31. 31. You’ve got it installed? Let’s dig deeper.
  32. 32. wp-cli is extensible.
  33. 33. Sample Plugin:WCLV Backup.
  34. 34. Goal:wp wclv backup [--no-db] [/dir/outputfile.tar.gz]
  35. 35. Our Plan:- Use built-in SQL Backup- Create a .tar.gz of install and db
  36. 36. Define the Base Command<?php// Let WP_CLI know we exist!// Earlier versions of wp-cli used WP_CLI::addCommand()WP_CLI::add_command( wclv, WCLV_Backup_Command );/** * The WCLV Backup Plugin * * @package WCLV_Backup * @subpackage commands/community * @maintainer Mike Schroder */class WCLV_Backup_Command extends WP_CLI_Command {...
  37. 37. Define Sub-Commands• $args: stand-alone arguments• $assoc_args: --arg=value style in associative arrayclass WCLV_Backup_Command extends WP_CLI_Command {! function backup( $args, $assoc_args ) {! ! $filename = $dbname = null;! ! ...! }! public static function help() {! ! WP_CLI::line( "usage: wp wclv backup [--no-db] [path/to/file]" );! }}
  38. 38. Grab Filenamefunction backup( $args, $assoc_args ) {! $filename = $dbname = null;! // If a filename isnt specified, default to "Sites Title.tar.gz".! if ( empty( $args ) )! ! $filename = ../ . escapeshellarg( get_bloginfo() ) . .tar.gz;! else! ! $filename = $args[0];
  39. 39. Handle --no-db• SQL file not using temp location for simplicity of demo.! // If --no-db is specified, dont include the database in backup! if ( ! isset( $assoc_args[no-db] ) ) {! ! $dbname = ../database_temp.sql;! ! // This is cheating a bit, since wp-cli doesnt currently support! ! // running commands within commands without re-launching itself.! ! WP_CLI::run_command( array( db, export, $dbname ), array() );! }
  40. 40. Back it up!• See class-wp-cli.php for more magical functions! // GZ/Tar and Backup the install!! WP_CLI::line( "Backing up to $filename ..." );! $result = WP_CLI::launch( "tar -zcvf $filename . $dbname", false );! // If we created a database backup, remove the temp file.! if ( $dbname && ! unlink( $dbname ) )! ! WP_CLI::warning( "Couldnt remove temporary database backup,$dbname." );
  41. 41. ERROR ERROR! // Will automatically exit on WP_CLI::error, but not WP_CLI::success.! if ( 0 == $result ) {! ! WP_CLI::success( "Backup Complete." );! } else {! ! WP_CLI::error( "Backup Failed." );! }}
  42. 42. Resources! • https://github.com/wp-cli/wp-cli • https://github.com/wp-cli/wp-cli/wiki/List-of-internal-commands • https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook • http://scribu.net/wordpress/a-command-line-interface-for- wordpress.html • http://wp.tutsplus.com/tutorials/using-wp-cli-for-fun-and-profit/ • http://halfelf.org/2012/command-line-wp/ • http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.htmlMike Schroder (DH-Shredder)@GetSource - http://www.getsource.net

×