SlideShare a Scribd company logo
Manage WordPress with
 Awesome using wp-cli
         WordCamp Vancouver 2012




    Mike Schroder (DH-Shredder)
    @GetSource - http://www.getsource.net
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
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 WordPress

wp core update
Install a Theme

wp theme install sunspot
Reset to default theme

wp theme activate twentytwelve
Backup your Database

wp db export backup.sql
Update Plugins

wp plugin update --all
What do I need to run it?
What do I need to run it?
•   SSH access to your WordPress install's directory
What do I need to run it?
•   SSH access to your WordPress install's directory

•   PHP 5.3+
What do I need to run it?
•   SSH access to your WordPress install's directory

•   PHP 5.3+

•   WordPress 3.3+
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
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
Okay. Got that covered.
  How can I get this
     Awesomeness?
Download wp-cli
git 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 ~/.bashrc
fi



(http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html)
You’ve got it installed?

   Let’s dig deeper.
wp-cli is extensible.
Add your own directly
wp-cli/src/php/wp-cli/commands/community/cmd_name.php
Or, define in your plugins.

if ( defined('WP_CLI') && WP_CLI ) {
! include( PLUGIN_DIR . '/lib/wp-cli.php' );
}
Sample Plugin:

WCYVR Backup.
Goal:
wp wcyvr 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_command( 'wcyvr', 'WCYVR_Backup_Command' );

/**
 * The WCYVR Backup Plugin
 *
 * @package WCYVR_Backup
 * @subpackage commands/community
 * @maintainer Mike Schroder
 */
class WCYVR_Backup_Command extends WP_CLI_Command {
...
Define Sub-Commands
•   $args: stand-alone arguments

•   $assoc_args: --arg=value style in associative array


class WCYVR_Backup_Command extends WP_CLI_Command {

!   function backup( $args, $assoc_args ) {
!   !   $filename = $dbname = null;
!   !   ...
!   }

! public static function help() {
! !   WP_CLI::line( "usage: wp wcyvr backup [--no-db] [path/to/file]" );
! }
}
Grab Filename

function backup( $args, $assoc_args ) {
! $filename = $dbname = null;

!   // If a filename isn't specified, default to "Site's Title.tar.gz".
!   if ( empty( $args ) )
!   !   $filename = '../' . escapeshellarg( get_bloginfo() ) . '.tar.gz';
!   else
!   !   $filename = $args[0];
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() );
!   }
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'." );
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." );
!   }
}
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.html


Mike Schroder (DH-Shredder)
@GetSource - http://www.getsource.net

More Related Content

What's hot

Front-end tools
Front-end toolsFront-end tools
Front-end tools
Gleb Vinnikov
 
Bower - A package manager for the web
Bower - A package manager for the webBower - A package manager for the web
Bower - A package manager for the web
Larry Nung
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.Graham Dumpleton
 
Workshop On WP-CLI
Workshop On WP-CLIWorkshop On WP-CLI
Workshop On WP-CLI
Ajit Bohra
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
Otto Kekäläinen
 
Task 1
Task 1Task 1
Task 1EdiPHP
 
WordPress Development in a Modern PHP World
WordPress Development in a Modern PHP WorldWordPress Development in a Modern PHP World
WordPress Development in a Modern PHP World
DrewAPicture
 
Automatic testing and quality assurance for WordPress plugins
Automatic testing and quality assurance for WordPress pluginsAutomatic testing and quality assurance for WordPress plugins
Automatic testing and quality assurance for WordPress plugins
Otto Kekäläinen
 
Dc kyiv2010 jun_08
Dc kyiv2010 jun_08Dc kyiv2010 jun_08
Dc kyiv2010 jun_08
Andrii Podanenko
 
體驗 Hhvm
體驗 Hhvm體驗 Hhvm
體驗 Hhvm
Chen Cheng-Wei
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Diana Thompson
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize it
Otto Kekäläinen
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
Derek Willian Stavis
 
10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...
Otto Kekäläinen
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2Graham Dumpleton
 
Improving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingImproving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP Profiling
Otto Kekäläinen
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
Seravo
 
Making Magic with WP-CLI
Making Magic with WP-CLIMaking Magic with WP-CLI
Making Magic with WP-CLI
ryanduff
 
Plone: The CMS that hits above it's weight
Plone: The CMS that hits above it's weightPlone: The CMS that hits above it's weight
Plone: The CMS that hits above it's weight
Dylan Jay
 

What's hot (20)

Node.js
Node.jsNode.js
Node.js
 
Front-end tools
Front-end toolsFront-end tools
Front-end tools
 
Bower - A package manager for the web
Bower - A package manager for the webBower - A package manager for the web
Bower - A package manager for the web
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
 
Workshop On WP-CLI
Workshop On WP-CLIWorkshop On WP-CLI
Workshop On WP-CLI
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
 
Task 1
Task 1Task 1
Task 1
 
WordPress Development in a Modern PHP World
WordPress Development in a Modern PHP WorldWordPress Development in a Modern PHP World
WordPress Development in a Modern PHP World
 
Automatic testing and quality assurance for WordPress plugins
Automatic testing and quality assurance for WordPress pluginsAutomatic testing and quality assurance for WordPress plugins
Automatic testing and quality assurance for WordPress plugins
 
Dc kyiv2010 jun_08
Dc kyiv2010 jun_08Dc kyiv2010 jun_08
Dc kyiv2010 jun_08
 
體驗 Hhvm
體驗 Hhvm體驗 Hhvm
體驗 Hhvm
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize it
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 
10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
 
Improving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP ProfilingImproving WordPress Performance with Xdebug and PHP Profiling
Improving WordPress Performance with Xdebug and PHP Profiling
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Making Magic with WP-CLI
Making Magic with WP-CLIMaking Magic with WP-CLI
Making Magic with WP-CLI
 
Plone: The CMS that hits above it's weight
Plone: The CMS that hits above it's weightPlone: The CMS that hits above it's weight
Plone: The CMS that hits above it's weight
 

Similar to WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depth
Sanjay Willie
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
Diana Thompson
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
Chandra Patel
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
Diana Thompson
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLI
ryanduff
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Andrea Cardinali
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
WP Engine
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
LumoSpark
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!
Jeff Geerling
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
Diana Thompson
 
Drupal Deployment Troubles and Problems
Drupal Deployment Troubles and ProblemsDrupal Deployment Troubles and Problems
Drupal Deployment Troubles and Problems
Andrii Lundiak
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
Chandra Patel
 
A WordPress workshop at Cefalo
A WordPress workshop at Cefalo A WordPress workshop at Cefalo
A WordPress workshop at Cefalo
Beroza Paul
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute Install
Steve Taylor
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
InstaWP Inc
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
Chris Adams
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLI
Suwash Kunwar
 
Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Helgi Þormar Þorbjörnsson
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
Sysdig
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabricandymccurdy
 

Similar to WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli (20)

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depth
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLI
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
 
DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!DevOps for Humans - Ansible for Drupal Deployment Victory!
DevOps for Humans - Ansible for Drupal Deployment Victory!
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Drupal Deployment Troubles and Problems
Drupal Deployment Troubles and ProblemsDrupal Deployment Troubles and Problems
Drupal Deployment Troubles and Problems
 
WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
 
A WordPress workshop at Cefalo
A WordPress workshop at Cefalo A WordPress workshop at Cefalo
A WordPress workshop at Cefalo
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute Install
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLI
 
Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 

WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli

  • 1. Manage WordPress with Awesome using wp-cli WordCamp Vancouver 2012 Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net
  • 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. There are two groups of people.
  • 4. Those who use the command line
  • 5. Those who are going to use the command line
  • 6. Don’t be afraid of the CLI. It’s your friend.
  • 7. Oh, you like the CLI? wp-cli will make your life better.
  • 8. What’s wp-cli? super-cool Open Source tool to manage WordPress
  • 9. Why so cool? Headed up by Andreas Creten and Cristi Burcă (scribu)
  • 10. Why so cool? Uses WordPress itself to perform operations
  • 11. Why so cool? Automation!
  • 12. What can I do with it?
  • 13.
  • 16. Install a Theme wp theme install sunspot
  • 17. Reset to default theme wp theme activate twentytwelve
  • 18. Backup your Database wp db export backup.sql
  • 19. Update Plugins wp plugin update --all
  • 20. What do I need to run it?
  • 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
  • 26. Okay. Got that covered. How can I get this Awesomeness?
  • 27. Download wp-cli git clone --recursive git://github.com/wp-cli/wp-cli.git
  • 28. Make it runnable from your WordPress Install.
  • 29. If you have sudo: sudo utils/dev-build
  • 30. Otherwise, add an alias (.bashrc/.bash_profile) alias wp='/home/user/wp-cli/src/bin/wp';
  • 31. In ~/.bash_profile: if [ -f ~/.bashrc ]; then source ~/.bashrc fi (http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html)
  • 32. You’ve got it installed? Let’s dig deeper.
  • 34. Add your own directly wp-cli/src/php/wp-cli/commands/community/cmd_name.php
  • 35. Or, define in your plugins. if ( defined('WP_CLI') && WP_CLI ) { ! include( PLUGIN_DIR . '/lib/wp-cli.php' ); }
  • 37. Goal: wp wcyvr backup [--no-db] [/dir/outputfile.tar.gz]
  • 38. Our Plan: - Use built-in SQL Backup - Create a .tar.gz of install and db
  • 39. Define the Base Command <?php // Let WP_CLI know we exist! // Earlier versions of wp-cli used WP_CLI::addCommand() WP_CLI::add_command( 'wcyvr', 'WCYVR_Backup_Command' ); /** * The WCYVR Backup Plugin * * @package WCYVR_Backup * @subpackage commands/community * @maintainer Mike Schroder */ class WCYVR_Backup_Command extends WP_CLI_Command { ...
  • 40. Define Sub-Commands • $args: stand-alone arguments • $assoc_args: --arg=value style in associative array class WCYVR_Backup_Command extends WP_CLI_Command { ! function backup( $args, $assoc_args ) { ! ! $filename = $dbname = null; ! ! ... ! } ! public static function help() { ! ! WP_CLI::line( "usage: wp wcyvr backup [--no-db] [path/to/file]" ); ! } }
  • 41. Grab Filename function backup( $args, $assoc_args ) { ! $filename = $dbname = null; ! // If a filename isn't specified, default to "Site's Title.tar.gz". ! if ( empty( $args ) ) ! ! $filename = '../' . escapeshellarg( get_bloginfo() ) . '.tar.gz'; ! else ! ! $filename = $args[0];
  • 42. 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() ); ! }
  • 43. 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'." );
  • 44. 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." ); ! } }
  • 45. 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.html Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net