getting started with wp-cli

80
@cwpnolen @emagineusa @WordCampRI #WCRI WordCamp Rhode Island WP-CLI GETTING STARTED WITH

Upload: christian-nolen

Post on 26-Jan-2017

78 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

WordCamp Rhode Island

WP-CLIGETTING STARTED WITH

Page 2: Getting Started with WP-CLI

Who Am I?Christian Nolen

Technical Director for emagine @cwpnolen

@cwpnolen @emagineusa@WordCampRI #WCRI

Page 3: Getting Started with WP-CLI

http://www.emagine.com/careers/

We’re Hiring

@cwpnolen @emagineusa@WordCampRI #WCRI

Page 4: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

What is WP-CLI?

Page 5: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

1. UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment

2. PHP 5.3.29 or later 3. WordPress 3.7 or later

Requirements

Page 6: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

InstallationManual Install

http://wp-cli.org/#installing

Third-Party Companies https://wp-cli.org/docs/hosting-companies/

Vagranthttps://github.com/Varying-Vagrant-Vagrants/VVV

Page 7: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Why Bother

Page 8: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Improved productivity means less human sweat, not more.

Henry Ford

Page 9: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

65%The amount of time I save setting up WordPress

compared to the 5 Minute Install

Page 10: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp command subcommand --options --paramaters

Syntax

Page 11: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wpwp-cli

Page 12: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

commandthe section of WordPress you want to work with

Page 13: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

subcommandthe action we want to take on the section

Page 14: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

--optionsdefinable options or settings for your subcommand

Page 15: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

--parametersglobal options that can be assigned to any command

Page 16: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Setup WordPress

Page 17: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core downloaddownload and unpack the latest version of WordPress

Page 18: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core download --version=4.6 you can also specify the version of WordPress you want to download

Page 19: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core download --locale=nl_NL you can also specify the language for WordPress

Page 20: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core config --prompt creates wp-config.php

Page 21: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp db create creates your database specified in wp-config is it doesn’t exist

Page 22: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core install --prompt populates your database with the WordPress tables using the supplied data

Page 23: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Working with Plugins

Page 24: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin list displays a table list all your installed plugins

Page 25: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin delete hello deletes the Hello Dolly plugin

Page 26: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin install jetpack installs the Jetpack plugin

Page 27: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin activate jetpack activates the Jetpack plugin

Page 28: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin install wp-super-cache --activate installs and activates the WP Super Cache plugin

Page 29: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin install buddypress woocommerce install multiple plugins

Page 30: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin install bbpress —version=2.5.9 installs version 2.5.9 of bbPress

Page 31: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin update bbpress updates the bbPress plugin to the latest version

Page 32: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin --all updates all plugins

Page 33: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin search 'Yoast SEO' searches wordpress.org plugin repository for 'Yoast Seo'

and returns a table list of results

Page 34: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp plugin toggle bbpress activates bbpress if the plugin is currently inactive

deactivates the plugin if it is currently active

Page 35: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Working with Themes

Page 36: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme list displays a table list all available themes

Page 37: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme search 'travel blog' searches wordpress.org plugin repository for 'travel blog'

and returns a table list of relevant themes

Page 38: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme search 'travel blog' --fields=name,slug,rating,num_ratings

returns the same table list of relevant themes but includes a column for the number of ratings for the theme

Page 39: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme search 'travel blog' --per-page=50

updates the number of items returns from 10 to 50

Page 40: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme install nisarg --activate installs and activates the Nisarg theme

Page 41: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp theme delete twentysixteen deletes the twentysixteen theme

(themes can only be deleted when they are not active)

Page 42: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Working with Posts

Page 43: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post list displays a table list all available themes

(by default only lists items from the 'post' post type)

Page 44: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post list displays a table list of posts

(by default only lists items from the 'post' post type)

Page 45: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post list --post_type=post,page displays a table list of posts narrowed by the 'post' and 'page' post type

Page 46: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post create --post_type=page --post_title= 'Sample Page' --post_name=sample-page-one

--post_status=publish --post_content= '<p>Some test.</p>'

creates a post of the 'page' post type defining the page title, slug, status and content

Page 47: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post generate --count=100creates 100 posts for the 'post' post type

(generate defaults to the 'post' post type and 'published' post_status)

Page 48: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post delete 3deletes the post with the post ID of '3'

(the deleted post is moved to the trash)

Page 49: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post delete 4 --forcepermanently deletes the post with the post ID of '4'

(skips moving the post to the trash)

Page 50: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post delete 5 6deletes the post with the post ID of '4' and '5'

Page 51: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post delete $(wp post list --format=ids)deletes all posts of the 'post' post type

(--format=ids returns a list of post IDs space delimited)

Page 52: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp post delete $(wp post list --post_status=trash --format=ids)

empties the trash for posts that belong to the 'post' post type

Page 53: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Generate Post Content

Page 54: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

curl loripsum.net/api/5/short/headers/ul/bq | wp post generate --post_content --count=5

retrieves dummy html markup and and applies it to the post_content for each generated post

Page 55: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

for n in {1..5}; do curl loripsum.net/api/5/short/headers/ul/bq

| wp post generate --post_content --count=1; done uses a for loop to get our dummy html markup to be used for generated post content

using the for loop allows the content being generated to be dynamic(note: the count option needs to be set to 1. the loop is dictating the count)

Page 56: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Export / Import

Page 57: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp export --dir=../exports all posts to the parent directory you are currently in

Page 58: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp export --dir=../ --post_type=pageexports all post in the 'page' post type

to the parent directory you are currently in

Page 59: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp import ../<filename>imports the data found in the export file

located in the parent directory

Page 60: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

The Database

Page 61: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp db export ../my-export.sqlexports your WordPress database to the parent directory

with the file name my-export.sql

Page 62: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp db import ../my-export.sqlimports the exported WordPress database found in the parent directory

with the file name my-export.sql

Page 63: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Search and Replace

Page 64: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp search-replace old-domain.com new-domain.comperforms a serialized search and replace on the database

changes old-domain.com to new-domain.com (no plugin or third-party library needed)

Page 65: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Working with Media

Page 66: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp media import ../sample-files/*imports all files found in the 'sample-files' folder

found in the parent directory

Page 67: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp media import http://www.emagine.com/assets/logo.png

imports an image via the assets URL

Page 68: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp media regenerateregenerates all thumbnails created by WordPress

(no additional plugin needed)

Page 69: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp media regenerate <attachment_id>regenerates all thumbnails for a specific media item

(no additional plugin needed)

Page 70: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Working with Core

Page 71: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core check-updatechecks if there is an update available for your

current version of WordPress

Page 72: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core updateupdates WordPress to the latest version

(if an update is available)

Page 73: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core update-dbupdates the WordPress database if needed

Page 74: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core verify-checksumsverifies that the core files in your WordPress install match wordpress.org's

Page 75: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core multisite-convertchanges a single site install to a multisite install

(defaults to sub-directories)

Page 76: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

wp core multisite-convert --subdomainschanges a single site install to a sub-domain multisite install

Page 77: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Resourceshttp://wp-cli.org/docs/

http://wp-cli.org/commands/ https://wp-cli.org/docs/external-resources/

Page 78: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Don’t Fear the Command Line

Page 79: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Whenever you are asked if you can do a job, tell 'em, “Certainly I can!”

Then get busy and find out how to do it.

Theodore Roosevelt

Page 80: Getting Started with WP-CLI

@cwpnolen @emagineusa@WordCampRI #WCRI

Thank You