SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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 webLarry 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-CLIAjit 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 WorldDrewAPicture
 
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 pluginsOtto Kekäläinen
 
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 BeachDiana 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 itOtto 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 ProfilingOtto 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 developersSeravo
 
Making Magic with WP-CLI
Making Magic with WP-CLIMaking Magic with WP-CLI
Making Magic with WP-CLIryanduff
 
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 weightDylan Jay
 

Tendances (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
 

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

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depthSanjay 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-CLIDiana 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 DeveloperChandra 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-CLIDiana 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-CLIryanduff
 
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-CLIWP 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-CLIDiana Thompson
 
Drupal Deployment Troubles and Problems
Drupal Deployment Troubles and ProblemsDrupal Deployment Troubles and Problems
Drupal Deployment Troubles and ProblemsAndrii 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 DeveloperChandra 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 InstallSteve Taylor
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comInstaWP 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 28thChris Adams
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLISuwash 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 produccionSysdig
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabricandymccurdy
 

Similaire à 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
 

Dernier

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Dernier (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

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