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

Using Composer to Manage WordPress

Using Composer to Manage WordPress

Talk given at Manchester WordCamp October ’15

Tom de Bruin

October 10, 2015
Tweet

More Decks by Tom de Bruin

Other Decks in Programming

Transcript

  1. Using Composer to
    manage WP
    Tom de Bruin
    @deadlyhifi

    View Slide

  2. “Composer is a tool for dependency management in PHP. It
    allows you to declare the libraries your project depends on and it
    will manage (install/update) them for you.”
    https://getcomposer.org/
    https://packagist.org/

    View Slide

  3. https://packagist.org/packages/guzzlehttp/guzzle

    View Slide

  4. https://getcomposer.org/doc/articles/versions.md#caret
    http://semver.org/

    View Slide

  5. View Slide

  6. composer.json and composer.lock and composer
    install and composer update
    • composer install
    • installs everything if .lock file doesn’t exist, writes .lock file.
    • subsequently, brings everything up to date with what’s in the .lock
    file.
    • composer update
    • brings everything in your .json up to date, and updates the .lock file.
    • Always run composer install on the server.
    • Composer sees that .json and .lock match, installs everything.
    • This can be confusing. Read all about it on http://daylerees.com/
    composer-primer/ and https://adamcod.es/2013/03/07/composer-
    install-vs-composer-update.html

    View Slide

  7. packagist for WP
    http://wpackagist.org/

    View Slide

  8. WP’s file structure
    You can’t put your plugins in the vendor folder.
    https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder

    View Slide

  9. https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder
    ‛ Change the location, and name, of wp-config with a setting in
    your wp-config.php file.
    define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/app');
    define('WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/app');

    View Slide

  10. https://github.com/composer/installers#custom-install-paths

    View Slide

  11. View Slide

  12. Composer has many powers
    • require-dev
    • Register other repos (e.g. GitHub, BitBucket, …)
    • Post install scripts
    • And many more…

    View Slide

  13. https://github.com/deadlyhifi/wp-gate8
    https://roots.io/bedrock/

    View Slide

  14. https://roots.io/bedrock/docs/environment-variables/

    View Slide

  15. .gitignore
    You don’t commit your dependencies.
    https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md

    View Slide

  16. Deployment
    At deployment you run composer install on the server.
    http://stackoverflow.com/questions/21721495/how-to-deploy-correctly-when-using-composers-develop-production-switch

    View Slide

  17. Keeping in Sync
    same as it ever was…
    https://codex.wordpress.org/Editing_wp-config.php#Disable_Plugin_and_Theme_Update_and_Installation
    Pic: https://www.flickr.com/photos/ericbegin/1281728810

    View Slide

  18. Questions?
    Tom de Bruin @deadlyhifi
    Read this…

    https://roots.io/using-composer-with-wordpress/
    http://composer.rarst.net/
    http://www.smashingmagazine.com/2014/03/better-dependency-
    management-team-based-wordpress-projects-composer/
    Use this…
    https://roots.io/bedrock/
    https://github.com/deadlyhifi/wp-gate8

    View Slide