Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WP-CLI: Unleash the power - Γιάννης Οικονόμου

WP-CLI: Unleash the power - Γιάννης Οικονόμου

WordCamp Athens 2019

Το WP-CLI είναι το standard command line εργαλείο του WordPress σήμερα.
Στην ομιλία θα δούμε γιατί το WP-CLI αποτελεί ένα σημαντικό ατού στο toolstack του WordPress και πώς μπορεί να μας λύνει τα χέρια για πλήθος καθημερινών εργασιών σε κάθε WordPress Project.
Θα παρουσιάσουμε σημαντικές δυνατότητές του, τις ευκολίες που μας προσφέρει, τα οφέλη από την αξιοποίησή του στο performance και στο workflow μας, αλλά και ευκαιρίες αυτοματισμών που πλέον μας ανοίγονται με τη χρήση του.

More Decks by WordPress Greek Community

Other Decks in Technology

Transcript

  1. > WP-CLI H O S T I N G D

    O N E R I G H T www.trustservers.gr (+30) 211 800 33 70 UNLEASH 
 THE
 POWER Giannis Economou Founder / Sr. Software Engineer [email protected]
  2. c CLI: COMMAND LINE INTERFACE
 OVERVIEW 8 Y [ Terminal

    Console Shell ( SSH ) Developers DevOps SysAdmins Engineers Advanced Users Several Tools Script Repeat Automate Save A LOT of Time!
  3. WP-CLI PROJECT Formal WordPress Project Started 2011 MATURE UNIX Like

    Environment PHP 5.4+ REQUIREMENTS DETAILS https://make.wordpress.org/cli/ https://github.com/wp-cli https://wp-cli.org/ Slack: #cli
  4. MS WINDOWS … SOON WITH A LINUX KERNEL! MAY-2019 Beginning

    with Windows Insiders builds this Summer, we will include an in-house custom-built Linux kernel to underpin the newest version of the Windows Subsystem for Linux (WSL) Jack Hammons Program Manager, Linux Systems Group - Microsoft.com
  5. YOUR *UNIX-LIKE* TERMINAL EVERYWHERE Native LINUX / UNIX/ MACOS WSL:

    Windows Subsystem For Linux WSL 2: Native Linux Kernel! The “Windows Terminal” ! MICROSOFT WINDOWS SSH YOUR HOSTING! (view animated gif: https://fournos.antithesis.gr/f/4abad885df7d46e3936e/)
  6. C R O N EVEN TS & SC H ED

    U LES EXPO RT/IM PO RT W XR D ATABASE O PER ATIO N S I18N TO O LS M ED IA IM PO RT R EG EN ER ATE TH U M BS TH EM ES O PTIO N S PLU G IN S PO STS R O LES D B SEAR C H AN D R EPLAC E M U LTISITE M AN AG EM EN T U SER S W ID G ETS TAXO N O M IES R EW R ITES M AIN TEN AN C E M O D E M EN U S LAN G U AG ES TR AN SIEN TS R -AD M IN S C AC H ES C O M M EN TS M O D ER ATIO N C APABILITIES IN STALLATIO N 20+ W O O C O M M ER C E C M D S EXTEN SIBLE / PAC K AG ES SC AFFO LD IN G SID EB W P-C O N FIG WP-CLI IS REALLY POWERFUL FIN D W (without using a browser!) (without a plugin!) (fast!)
  7. INSTALL: WORDPRESS FIRST CONTACT Download WP Install WP Installation in

    seconds (view animated gif: https://fournos.antithesis.gr/f/2d6af8310a1f4eff9a3e/)
  8. INSTALL: A THEME AND A PLUGIN EVERYDAY TASKS Search Install

    Activate Many plugins in one command: wp plugin install p1 p2 p3 (view animated gif: https://fournos.antithesis.gr/f/3fcfe66c859c4109b69f/)
  9. PACKAGES PROVIDE FUNCTIONALITY EXAMPLE: ADD SAMPLE CONTENT wp package install

    Many 3rd party packages You can write your own packages (view animated gif: https://fournos.antithesis.gr/f/b0f83fe984904fca8233/)
  10. UPDATES: CORE, PLUGINS AND THEMES IN SECONDS View plugins status

    (Backup database) Perform all the updates (view animated gif: https://fournos.antithesis.gr/f/5cd896f264b7449c827f/)
  11. ALIASES
 MANAGE SEVERAL WP Grouping Logical groups of WP instances

    Remote execution Instances can be remote, commands are executed on remote host An alias is a shorthand reference to a WordPress install Manage several WP Execute wp-cli commands on many WordPress installations at once
  12. ALIASES
 IN ONE FILE wp-cli.yml (configuration file, global or project

    based) wp cli alias list wp cli alias add wp cli alias update wp cli alias delete
  13. EXECUTE
 ON SELECTED ALIASES wp @ALIAS command wp @all verify-checksums

    wp @live updatedraftplus backup wp @all core update wp @staging plugin update —all wp @all cache flush wp @all super-cache flush wp @live cron event run --due-now Useful examples: check for altered core files everywhere backup live sites update core and plugins on all staging installations flush object cache and super cache everywhere run due cron events on live sites
  14. DEPLOY YOUR DB
 FROM PRODUCTION TO STAGING wp @siteone-live db

    export - | wp @siteone-stage db import - wp @siteone-stage search-replace “www.example.org” “staging.example.org” Export database from production and import on staging Search and replace base URL READY!
  15. C R O N EVEN TS & SC H ED

    U LES EXPO RT/IM PO RT W XR D ATABASE O PER ATIO N S I18N TO O LS M ED IA IM PO RT R EG EN ER ATE TH U M BS TH EM ES O PTIO N S PLU G IN S PO STS R O LES D B SEAR C H AN D R EPLAC E M U LTISITE M AN AG EM EN T U SER S W ID G ETS TAXO N O M IES R EW R ITES M AIN TEN AN C E M O D E M EN U S LAN G U AG ES TR AN SIEN TS R -AD M IN S C AC H ES C O M M EN TS M O D ER ATIO N C APABILITIES IN STALLATIO N 20+ W O O C O M M ER C E C M D S EXTEN SIBLE / PAC K AG ES SC AFFO LD IN G SID EB W P-C O N FIG REMEMBER? REALLY POWERFUL FIN D W (without using a browser!) (without a plugin!) (fast!)
  16. SOME EXAMPLES DO TRY THIS AT HOME #create your child

    theme fast wp scaffold child-theme myTheme --parent_theme=‘Sydney’ --theme_name='Sweet child of mine' #downgrade: test your plugin on older WP versions wp core update --force --version=5.1 #import content from wordpress.com wp import example.wordpress.2019-05-18.xml --authors=create #Re-generate all thumbnails, without confirmation. wp media regenerate --yes Found 3 images to regenerate. 1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760). 2/3 Regenerated thumbnails for "Boardwalk" (ID 757). 3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756). Success: Regenerated 3 of 3 images.
  17. MORE ADVANCED EXAMPLES THE SKY IS THE LIMIT #delete all

    posts, but leave pages. wp post delete --force $(wp post list --post_type=post --format=ids) #!/bin/bash #reset all user passwords (also see ‘wp user reset-password’) for uid in $(wp user list --field=id) do pass=`openssl rand 15 -base64` wp user update $uid --user_pass="$pass" done Use your shell Write a script