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)
21. What do I need to run it?
• SSH access to your WordPress install's directory
22. What do I need to run it?
• SSH access to your WordPress install's directory
• PHP 5.3+
23. What do I need to run it?
• SSH access to your WordPress install's directory
• PHP 5.3+
• WordPress 3.3+
24. What do I need to run it?
• SSH access to your WordPress install's directory
• PHP 5.3+
• WordPress 3.3+
• Enough RAM for shell processes to run WordPress
25. What do I need to run it?
• SSH access to your WordPress install's directory
• PHP 5.3+
• WordPress 3.3+
• Enough RAM for shell processes to run WordPress
• Easiest on Linux & MacOS
40. Handle --no-db
• SQL file not using temp location for simplicity of demo.
! // If --no-db is specified, don't include the database in backup
! if ( ! isset( $assoc_args['no-db'] ) ) {
! ! $dbname = '../database_temp.sql';
! ! // This is cheating a bit, since wp-cli doesn't currently support
! ! // running commands within commands without re-launching itself.
! ! WP_CLI::run_command( array( 'db', 'export', $dbname ), array() );
! }
41. 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( "Couldn't remove temporary database backup,
'$dbname'." );
42. 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." );
! }
}
Have worked with WordPress for about 6 years, starting with just a simple blog.\nContributing for just over a year -- Image API Improvements for 3.5\nSee me after -- or run into me at Dev day if you’d like to know how you can help!\n
Two Groups Of Users.\n- Get users who don’t use the command line excited about the command line!\n- Get users who DO use the command line excited about wp-cli\n- Make life better!\n
Two Groups Of Users.\n- Get users who don’t use the command line excited about the command line!\n- Get users who DO use the command line excited about wp-cli\n- Make life better!\n
Two Groups Of Users.\n- Get users who don’t use the command line excited about the command line!\n- Get users who DO use the command line excited about wp-cli\n- Make life better!\n
Two Groups Of Users.\n- Get users who don’t use the command line excited about the command line!\n- Get users who DO use the command line excited about wp-cli\n- Make life better!\n
Two Groups Of Users.\n- Get users who don’t use the command line excited about the command line!\n- Get users who DO use the command line excited about wp-cli\n- Make life better!\n
\n
Headed by Cristi Burcă (scribu), along with other major core contributors\n Uses WordPress core itself to perform operations\n Automation!\n
This means it does things the proper way, and in most cases will continue to do so as WordPress matures.\n
Headed by Cristi Burcă (scribu), along with other major core contributors\n Uses WordPress core itself to perform operations\n Automation!\n
\n
\n
\n
\n
\n
You can also install themes\n
\n
\n
\n
\n
\n
\n
\n
\n
Go to the directory you want to install to (this will create a wp-cli directory for you), and run the above\n
\n
Run this from the wp-cli directory!\nIt will automagically add a symlink to the wp-cli script to /usr/bin or /usr/local/bin, in that order, and install bash auto-complete files for you.\n
Run this from the wp-cli directory!\nIt will automagically add a symlink to the wp-cli script to /usr/bin or /usr/local/bin, in that order, and install bash auto-complete files for you.\n
Run this from the wp-cli directory!\nIt will automagically add a symlink to the wp-cli script to /usr/bin or /usr/local/bin, in that order, and install bash auto-complete files for you.\n
\n
While additional functionality is welcomed to the project with open arms, sometimes you just need something that works for *your* site or plugin. You can write your own commands as plugins to wp-cli.\n
While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can’t easily be generalized. You can write your own commands as plugins to wp-cli.\n
While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can’t easily be generalized. You can write your own commands as plugins to wp-cli.\n
While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can’t easily be generalized. You can write your own commands as plugins to wp-cli.\n
\n
WP_CLI_Command will pass us two variables -- $args and $assoc_args.\n$args is the list of stand-alone command-line arguments.\n$assoc_args will handle items like --argument=value, and it gives them to us in an associative array. Each argument is a key.\n\nHelp is preferred, although wp-cli will try to guess at the command’s detail if you don’t provide them.\nThere’s been a general move over to man pages, which can be generated using a bundled script.\n
Note that we’re using WordPress functions (get_bloginfo()) directly within our WP_CLI class.\n$args[0] is the filename we’re looking for.\nRemember to escape any user input that’s going back out to the shell.\n
If we’d passed something within --no-db, there’d be a value.\nAs is, even though we didn’t pass anything, the key was created by wp-cli.\nIf you were going to implement this for core wp_cli, you’d probably want to have it initially save to a temp location with random file, then zip it up with a proper name. This is only done for ease of this demo.\n
Point out launch() -- false is telling it that we don’t want it to automatically exit on failure.\nPoint out warning -- this will be more explained in the next slide\n
Point out launch() -- false is telling it that we don’t want it to automatically exit on failure.\nPoint out warning -- this will be more explained in the next slide\n