Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Composer to create manageable WordPress websites

958 views

Published on

WordCamp Europe 2016 talk about using Composer with WordPress - how to introduce dependency management into existing development workflow.

Published in: Internet
  • Be the first to comment

Using Composer to create manageable WordPress websites

  1. 1. Using Composer to create manageable WordPress websites Anna Ladoshkina WordCamp Europe, 24/06/2016
  2. 2. I’ve been making websites for NGOs for 7 years @foralien bureau / Teplitsa. Technologies for social good
  3. 3. You may need it if… You are developing websites on PHP (with WordPress) You would like to use modern development tool You would like to have more organized projects You would like to start easily You hear that buzzword all the time, but…
  4. 4. What’s dependency? Suppose: You have a project that depends on a number of libraries. Some of those libraries depend on other libraries. Composer: Enables you to declare the libraries you depend on. Finds out versions of packages and installs them (into your project)
  5. 5. How to install? PHP 5.3.x and command line Follow instruction at https://getcomposer.org/doc/00-intro.md Add composer.json to the project folder
  6. 6. Composer.json? $ composer init { "name": "foralien/my_pack", "description": "Test package", "authors": [ { "name": "Anna Ladoshkina", "email": "webdev@foralien.com" } ], "require": {} }
  7. 7. Where to find packages? Composer-specific repositories https://packagist.org/ GitHub (other open-source repositories) https://github.com/ Create yourself author/package_name
  8. 8. packagist.org
  9. 9. Add them one by one… $ composer config repositories.foo vcs https://github.com/foo/bar $ composer require package More on command-line interface: https://getcomposer.org/doc/03-cli.md
  10. 10. …or specify them all in composer.json "repositories": [ { "type": "composer", "url" : "http://some-packagist.org" }, { "type": "vcs", "url": "https://github.com/username/repo" }, { "type": "artifact", "url": "local_folder/" } ], "require" : { "author/package": "1.0", "another_author/package" : "4.4" } More on composer.json schema: https://getcomposer.org/doc/04-schema.md
  11. 11. $ composer install
  12. 12. Have some coffee and check /vendor folder
  13. 13. Even for WordPress?
  14. 14. What’s the problem?
  15. 15. Common WordPress website project - core files - wp-config.php - wp-content/plugins - wp-content/themes - wp-content/languages - wp-content/uploads
  16. 16. A few questions to ask What should be under version control? - What are dependencies? - Where are Composer-compatible repositories? - What to do with vendor folder?
  17. 17. Give me an example https://roots.io/ Bedrock - WordPress boilerplate http://composer.rarst.net Unofficial companion to Composer documentation for WordPress developers
  18. 18. Step by step
  19. 19. Core is dependency plugins languages themes What are dependencies?
  20. 20. Tune project structure WordPress in subfolder https://codex.wordpress.org/ Giving_WordPress_Its_Own_Directory Move wp-content folder https://codex.wordpress.org/ Editing_wp-config.php#Moving_wp- content_folder
  21. 21. In settings
  22. 22. In wp-config.php define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' ); define( 'WP_CONTENT_URL', '//domain.com/wp-content' );
  23. 23. WordPress specific repositories core plugins languages Where are Composer-compatible repositories?
  24. 24. WordPress core at https://packagist.org/
  25. 25. Plugins at wpackagist.org
  26. 26. Language-packs at wp-languages.github.io
  27. 27. Local folder /artifacts myproject/myplugin-2.0.zip — plugins code — composer.json
  28. 28. Add them into composer.json "repositories": [ { "type": "composer", "url" : "http://wpackagist.org" }, { "type": "composer", "url": "http://wp-languages.github.io" }, ]
  29. 29. Config custom paths for dependencies core plugins languages What to do with vendor folder?
  30. 30. Paths in composer.json "config" : { "vendor-dir": "wp-content/vendor", }, "extra" : { "wordpress-install-dir": "core", "dropin-paths": { "wp-content/languages/": ["vendor:koodimonni-language"] } }
  31. 31. Finally add dependencies into…
  32. 32. …require or requires-dev sections "require" : { "composer/installers" : "~1.0", "johnpbloch/wordpress" : ">=4.4", "wpackagist-plugin/wordpress-seo" : "@stable", "koodimonni-language/core-ru_ru" : "*" , "myproject/myplugin" : "2.0", }, "require-dev" : { "wpackagist-plugin/menu-exporter" : "@stable", "wpackagist-plugin/wordpress-importer" : "@stable" }
  33. 33. $ composer install
  34. 34. composer.lock $ composer update
  35. 35. @foralien bureau / foralien.com Thank you Anna Ladoshkina www.facebook.com/anna.ladoshkina webdev@foralien.com

×