Upload
adam-englander
View
55
Download
1
Tags:
Embed Size (px)
Citation preview
WordPress Plugins
Observations of a full stack developer
Who Am I?
Developer/Evangelist at LaunchKey
Organizer of Las Vegas Python User Group
Founder/Co-Organizer of Las Vegas PHP UG
Co-Organizer of Las Vegas Developer UG
National Junior Basketball Coach
WordPress Overview
• Open Source CMS
• First released in 2003
• 24.1% of all websites as of July 2015*
• 60.2% CMS market share as of July 2015*
• Over 38,000 Plugins with nearly 1 billion total downloads
* W3Techs Usage statistics and market share of WordPress for websites
WordPress Extensibility
Theme system for user interface
Plugin system for add and/or customizing functionality
Event system for triggering events
Filter system for adding or modifying content
WordPress Events
https://codex.wordpress.org/Plugin_API/Action_Reference
Many listed
Not all documented
Google and step through debugging was better than developer documentation
WordPress Filters
https://codex.wordpress.org/Plugin_API/Filter_Reference
Many listed
Many undocumented
Google and step through debugging was better than developer documentation
Plugin Development
Know what is required of your plugin: https://codex.wordpress.org/Plugin_Submission_and_Promotion
Follow Plugin Development suggestions
User built in internationalization
Be prepared for some archaic nonsense
Steal from popular plugins for ideas on implementation and less than obvious tricks
MVC Lessons
Use view files to separate that from your event methods
Make sure to use translations
If you need to persist options, use a single option with filters to validate and sanitize the data. Do not circumvent the system.
If you have complex configuration, make a simple controller to manage flow.
Use plugins_url to determine location of files
JavaScript
JQuery included – Check your version
wp_enqueue_script
Add scripts to the HEAD or bottom of BODY
Allows for dependencies determining load order
Use version for cache busting
wp_localize_script
Configure data to be used by your plugin
CSS
wp_enqueue_style
Make sure to tell it to put the code in the HEAD
Use version to cache bust
Plugin Structure
Use plugin base file for bootstrapping
Provide uninstall.php file to allow clean removal
Give each directory a blank index.php to prevent directory browsing
If you have static assets, use a separate directory for those files
Dependencies
Prefer WordPress provided functionality over external libraries
Reduces the size of your plugin
Better interoperability with other plugins
Works on nearly every installation
No built in solution for external dependencies
Using Composer
Use a build system to not include extraneous files like tests and docs in your plugin
Load the autoloader in the plugin root file
Use only what is required
Unit Testing
Separate your code into classes
Dependency injection happens in the root file
Create a façade for global functions. WordPress is ALL global functions.
You may need to write some Output Buffer wrapping methods in the façade. WordPress loves to echo and error_log directly.
Test PHP 5.3 – 7.0 and HHVM
Integration Testing
Test as many versions as possible
Manual and automated testing
Docker Container for automated testing: https://github.com/LaunchKey/docker-wordpress
http://spkr8.com/t/60821
@adam_englander
#launchkey on freenode.net
#vegastech on freenode.net