SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Manage WordPress with
 Awesome using wp-cli
           WordCamp Vegas 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.
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_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 {
...
Define Sub-Commands
•   $args: stand-alone arguments

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


class 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]" );
! }
}
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

Automating WordPress Theme Development
Automating WordPress Theme DevelopmentAutomating WordPress Theme Development
Automating WordPress Theme DevelopmentHardeep Asrani
 
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
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp HamiltonPaul Bearne
 
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
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Ryan Brown
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2Yros
 
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
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Joe Casabona
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Michael Peacock
 
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
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricksbcoca
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Task 1
Task 1Task 1
Task 1EdiPHP
 
Rapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningRapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningUchit Vyas ☁
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflowRiccardo Coppola
 

Tendances (20)

Automating WordPress Theme Development
Automating WordPress Theme DevelopmentAutomating WordPress Theme Development
Automating WordPress Theme Development
 
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
 
Front-end tools
Front-end toolsFront-end tools
Front-end tools
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Memory Management in WordPress
Memory Management in WordPressMemory Management in WordPress
Memory Management in WordPress
 
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.
 
Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015Drupal cambs ansible for drupal april 2015
Drupal cambs ansible for drupal april 2015
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
 
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!
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)Responsive Design with WordPress (WCPHX)
Responsive Design with WordPress (WCPHX)
 
Perl dancer
Perl dancerPerl dancer
Perl dancer
 
Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
 
More tips n tricks
More tips n tricksMore tips n tricks
More tips n tricks
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Task 1
Task 1Task 1
Task 1
 
Rapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningRapid Infrastructure Provisioning
Rapid Infrastructure Provisioning
 
Dc kyiv2010 jun_08
Dc kyiv2010 jun_08Dc kyiv2010 jun_08
Dc kyiv2010 jun_08
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
 

Similaire à Manage WordPress with Awesome using wp cli

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depthSanjay Willie
 
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
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabricandymccurdy
 
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 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
 
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
 
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
 
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
 
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
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallSteve Taylor
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments Ohad Raz
 
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
 
A WordPress workshop at Cefalo
A WordPress workshop at Cefalo A WordPress workshop at Cefalo
A WordPress workshop at Cefalo Beroza Paul
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabricandymccurdy
 
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
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
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
 

Similaire à Manage WordPress with Awesome using wp cli (20)

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depth
 
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)
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
 
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 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
 
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
 
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
 
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
 
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
 
Beyond the WordPress 5 minute Install
Beyond the WordPress 5 minute InstallBeyond the WordPress 5 minute Install
Beyond the WordPress 5 minute Install
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments
 
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...
 
A WordPress workshop at Cefalo
A WordPress workshop at Cefalo A WordPress workshop at Cefalo
A WordPress workshop at Cefalo
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabric
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
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
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
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
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Manage WordPress with Awesome using wp cli

  • 1. Manage WordPress with Awesome using wp-cli WordCamp Vegas 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.
  • 35. Goal: wp wclv backup [--no-db] [/dir/outputfile.tar.gz]
  • 36. Our Plan: - Use built-in SQL Backup - Create a .tar.gz of install and db
  • 37. 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 { ...
  • 38. Define Sub-Commands • $args: stand-alone arguments • $assoc_args: --arg=value style in associative array class 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]" ); ! } }
  • 39. 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];
  • 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." ); ! } }
  • 43. 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

Notes de l'éditeur

  1. \n
  2. 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&amp;#x2019;d like to know how you can help!\n
  3. Two Groups Of Users.\n- Get users who don&amp;#x2019;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
  4. Two Groups Of Users.\n- Get users who don&amp;#x2019;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
  5. Two Groups Of Users.\n- Get users who don&amp;#x2019;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
  6. Two Groups Of Users.\n- Get users who don&amp;#x2019;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
  7. Two Groups Of Users.\n- Get users who don&amp;#x2019;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
  8. \n
  9. Headed by Cristi Burc&amp;#x103; (scribu), along with other major core contributors\n Uses WordPress core itself to perform operations\n Automation!\n
  10. This means it does things the proper way, and in most cases will continue to do so as WordPress matures.\n
  11. Headed by Cristi Burc&amp;#x103; (scribu), along with other major core contributors\n Uses WordPress core itself to perform operations\n Automation!\n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. You can also install themes\n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. Go to the directory you want to install to (this will create a wp-cli directory for you), and run the above\n
  27. \n
  28. 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
  29. 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
  30. 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
  31. \n
  32. 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
  33. While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can&amp;#x2019;t easily be generalized. You can write your own commands as plugins to wp-cli.\n
  34. While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can&amp;#x2019;t easily be generalized. You can write your own commands as plugins to wp-cli.\n
  35. While additional functionality is usually welcomed to the project with open arms, sometimes you just need something that can&amp;#x2019;t easily be generalized. You can write your own commands as plugins to wp-cli.\n
  36. \n
  37. 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&amp;#x2019;s detail if you don&amp;#x2019;t provide them.\nThere&amp;#x2019;s been a general move over to man pages, which can be generated using a bundled script.\n
  38. Note that we&amp;#x2019;re using WordPress functions (get_bloginfo()) directly within our WP_CLI class.\n$args[0] is the filename we&amp;#x2019;re looking for.\nRemember to escape any user input that&amp;#x2019;s going back out to the shell.\n
  39. If we&amp;#x2019;d passed something within --no-db, there&amp;#x2019;d be a value.\nAs is, even though we didn&amp;#x2019;t pass anything, the key was created by wp-cli.\nIf you were going to implement this for core wp_cli, you&amp;#x2019;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
  40. Point out launch() -- false is telling it that we don&amp;#x2019;t want it to automatically exit on failure.\nPoint out warning -- this will be more explained in the next slide\n
  41. Point out launch() -- false is telling it that we don&amp;#x2019;t want it to automatically exit on failure.\nPoint out warning -- this will be more explained in the next slide\n
  42. \n