wpsessions composer for wordpress plugin development
TRANSCRIPT
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.
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:)
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
● 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
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.
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
PSR-4
https://github.com/CalderaWP/calderawp-api/blob/wordpress/composer.json
PSR-4 + filemap
https://github.com/postmatic/epoch/blob/master/composer.json
classmap
https://github.com/Rarst/fragment-cache/blob/master/composer.json
PART ONE
Part Two
● 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
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
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
@Josh412https://CalderaWP.com
http://JoshPress.net
Thanks.Ya'll Are
Awesome!