WPday Bologna 2013: wp-cli

225d14114dc6e632c0fa4d7a86b61225?s=47 francescolaffi
September 13, 2013

WPday Bologna 2013: wp-cli

WPday - Bologna 13 Sept 2013 - wpday.it

http://flweb.it/2013/09/wpday-2013-bologna-wp-cli/
get wp-cli: http://wp-cli.org

The talk was a mix of slides and live demo, I included some snippets from the live demo for reference in the slides with the dark background.

225d14114dc6e632c0fa4d7a86b61225?s=128

francescolaffi

September 13, 2013
Tweet

Transcript

  1. WP-CLI A command line interface for WordPress by Francesco Laffi

    @francescolaffi #WPDAY Bologna 13 September 2013
  2. #WPDAY - 13 Sept 2013 @FrancescoLaffi 2 + = awesome

  3. #WPDAY - 13 Sept 2013 @FrancescoLaffi WHY SO AWESOME? -

    open source with great contributors (headed by @scribu and @andreascreten) - uses WordPress to perform operations - extensible with your own commands - save time! - automate tasks! 3
  4. #WPDAY - 13 Sept 2013 @FrancescoLaffi WHAT CAN I DO?

    - admin tasks: install, update, multisite, database, cache, ... - manage wp: plugins, themes, options, permalinks, users, import-export, ... - manage content: pages, posts, media, comments, tags, categories, ... - generate code: themes, plugins, CPT, ... 4
  5. #WPDAY - 13 Sept 2013 @FrancescoLaffi WHAT DO I NEED?

    - UNIX-like env: OS X, Linux, Cygwin, ... - PHP 5.3.2+ - WordPress 3.4+ - your shell of choice 5 Or use it inside a Vagrant VM with VVV: github.com/10up/varying-vagrant-vagrants
  6. #WPDAY - 13 Sept 2013 @FrancescoLaffi INSTALL WP-CLI 6 $

    curl https://raw.github.com/wp-cli/wp- cli.github.com/master/installer.sh | bash Full instructions: wp-cli.org Default location: ~/.wp-cli/ Add ~/.wp-cli/bin/ to your $PATH
  7. #WPDAY - 13 Sept 2013 @FrancescoLaffi SYNTAX 7 $ wp

    <command> <subcommand> <args...> Learn your wp-cli fu $ wp help $ wp <command> [<subcommand>] --help
  8. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp help $

    wp cli --help $ wp cli $ wp cli info $ wp help --help 8
  9. #WPDAY - 13 Sept 2013 @FrancescoLaffi CORE COMMAND - download:

    optional version, locale, ... - config: setup wp-config.php (db data, ...) - install: url, title, admin data - update and update-db - multisite: install or convert ... 9
  10. #WPDAY - 13 Sept 2013 @FrancescoLaffi ADMIN COMMANDS - rewrite:

    manage permalinks and flush - db: create, drop, reset, optimize, repair, export, import, query, cli - cache: manage objects cache - user, cap and role - site: manage sites in a multisite install - option, meta fields, ... 10
  11. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp core download

    $ wp core config --dbname=wpday_dev --dbuser=wpday $ wp db create $ wp core install --url=wpday.dev --title=wpDay --admin_user=admin --admin_email=admin@example.com --admin_password=admin $ open http://wpday.dev $ wp rewrite structure /%year%/%monthnum%/%day%/%postname%/ $ wp core multisite-convert --subdomains $ wp site create --slug=2013 $ open http://2013.wpday.dev 11
  12. #WPDAY - 13 Sept 2013 @FrancescoLaffi PLUGIN & THEME -

    install from repository or local/remote zip - activate / deactivate / status - update single or --all - list what is already installed - search the repository ... 12
  13. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp theme list

    $ wp theme activate twentytwelve $ wp plugin install mp6 --activate $ open http://wpday.dev/wp-admin 13
  14. #WPDAY - 13 Sept 2013 @FrancescoLaffi MANAGE CONTENTS - post:

    manage post, pages and custom post types - comment: manage comments - media: manage attachments - term: manage tags, categories and custom taxonomies terms 14
  15. #WPDAY - 13 Sept 2013 @FrancescoLaffi SCAFFOLD COMMAND - plugin:

    starter code for plugins - plugin-tests: setup phpunit and travis - _s: underscores.me starter theme - child-theme - post-type and taxonomy 15
  16. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp scaffold child-theme

    wpday --parent_theme=twentytwelve --activate $ echo 'a {color:green !important}' >> wp-content/themes/wpday/style.css $ open http://wpday.dev 16
  17. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp scaffold post-type

    talk --theme --textdomain=wpday $ echo "<?php require __DIR__.' /post-types/talk.php';" > wp-content/themes/wpday/functions.php $ wp rewrite flush $ wp post create --post_status=publish --post_type=talk --post_title='wp-cli' --post_content='WP command line fu' $ open http://wpday.dev/talk 17
  18. #WPDAY - 13 Sept 2013 @FrancescoLaffi BACKUP / MIGRATE -

    db export and db import: sql dumps - search-replace in database (change URLs easily!) - export and import: WXR files (needs plugin wordpress-importer) 18
  19. #WPDAY - 13 Sept 2013 @FrancescoLaffi SHELLS wp shell: interactive

    PHP console within the WordPress environment choose your REPL: basic, boris or psysh wp db cli: mysql shell connected to the WordPress database 19
  20. #WPDAY - 13 Sept 2013 @FrancescoLaffi EXTENDING WP-CLI wp plugins

    can add commands - guide: wiki > command cookbook commands in composer packages (WIP) - always active and available on all sites - guide: wiki > community packages --require <.php> or into ./wp-cli.yml 20
  21. #WPDAY - 13 Sept 2013 @FrancescoLaffi COMMUNITY COMMANDS - cache:

    W3 Total Cache, WP Super Cache - backup: BackWPup, BackUpWordPress - WP-Crontrol - Developer - Co-Authors Plus - see more: wiki > community commands 21
  22. #WPDAY - 13 Sept 2013 @FrancescoLaffi COMMUNITY PACKAGES - wp-cli/server-command

    serve wp easily with php cli web server - pixline/wp-cli-theme-test-command install and configure theme unit tests - see more: wp-cli.org/package-index/ 22
  23. #WPDAY - 13 Sept 2013 @FrancescoLaffi $ wp server --port=2013

    $ wp plugin install developer --activate $ wp plugin list $ wp developer --help $ wp developer install-plugins --type=wporg --activate 23
  24. #WPDAY - 13 Sept 2013 @FrancescoLaffi Q&A Francesco Laffi @francescolaffi

    francesco@laffi.io flweb.it 24