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.

WPSessions Composer for WordPress Plugin Development

842 views

Published on

  • Be the first to comment

  • Be the first to like this

WPSessions Composer for WordPress Plugin Development

  1. 1. Using Composer For WordPress Plugin Development Josh Pollock -- @Josh412 -- JoshPress.net
  2. 2. Hi, I'm Josh, I make WordPress plugins...
  3. 3. These Are Photos Of My Cats
  4. 4. Hypothesis[0] "reusable code" == "better code"
  5. 5. Hypothesis[1] The "Do Not Repeat Yourself Principle" Is Correct/Important
  6. 6. Hypothesis[2] The Single Responsibility Principle Is Correct/Important
  7. 7. Copypasta Is Uni-Directional That's Bad
  8. 8. Why Composer? It facilitates sharing your code & other's code. ● It's easy. ● It uses VCS, just like you're used to. ● It's a standard, works well with standards. ● Has WordPress support backed-in.
  9. 9. Out Of Scope For Today ● Installing Composer ○ Read https://getcomposer.org/doc/00-intro.md ○ Make sure to install globally ● Composer Basics ● Composer In Core ● Composer For Theme Development ● Composer For Full Stack Management ○ I probably can't resist this one:)
  10. 10. In Scope ● Discuss Structure For A Plugin With Composer ● Talk About The Autoloader ● Make An Example Plugin ● Worry About How To Ship It ● Get Some Helpful Links ● Take Questions
  11. 11. Plugin Structure
  12. 12. ● How much is in the plugin vs separate packages? ● Are we using the autoloader? ○ For the dependencies only or for the whole plugin? ● What 3rd party packages are we using? ● What about tests? Questions
  13. 13. Your Code: In The Plugin Or In A Package?
  14. 14. Autoloader
  15. 15. include_once( dirname( __FILE__ ) . '/vendor/autoload.php' ); Composer Autoloader: Fun Facts ● PSR-4, PSR-0, classmap, filemap ● Can be used for: ○ Dependencies ○ The package's classes ■ ^^ Means you can use it as the autoloader for your plugin.
  16. 16. Autoloaders Are Important! ● Less work/room for errors when adding classes. ● Less barriers to making a new class == smaller classes ○ More maintainable ○ More reusable ○ More likely to abide by the single responsibility principle
  17. 17. PSR-4 https://github.com/CalderaWP/calderawp-api/blob/wordpress/composer.json
  18. 18. PSR-4 + filemap https://github.com/postmatic/epoch/blob/master/composer.json
  19. 19. classmap https://github.com/Rarst/fragment-cache/blob/master/composer.json
  20. 20. Example Time!
  21. 21. PART ONE
  22. 22. Part Two
  23. 23. What About Shipping It?
  24. 24. ● Dependencies need to get to WordPress.org SVN ○ Can't I just commit my dependencies in the real repo? ○ Or automate it with grunt or bash? ● What about when someone checks out from Github? Concerns
  25. 25. More Examples ● Caldera Metaplate ○ Almost totally Composer Packages ○ Grunt script for shipping to WordPress.org ● Rarst's Fragment Cache ○ Uses Jaquith's tlc-transients package ○ Only on Github ● WordPress SEO by Yoast ○ Check out how they use scripts in composer.json
  26. 26. Helpful Links ● The Docs ● My Torque Articles ○ Introduction To Composer For WordPress ○ Introduction To Plugin Dev With Composer ○ Namespace & Autoloaders ● Rarst's Composer + WordPress ● Micah Wood's Composer Talk @ LoopConf
  27. 27. @Josh412 https://CalderaWP.com http://JoshPress.net Thanks. Ya'll Are Awesome!

×