16
WordPress Plugins Observations of a full stack developer

WordPress Plugin Development

Embed Size (px)

Citation preview

Page 1: WordPress Plugin Development

WordPress Plugins

Observations of a full stack developer

Page 2: WordPress Plugin Development

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

Page 3: WordPress Plugin Development

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

Page 4: WordPress Plugin Development

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

Page 5: WordPress Plugin Development

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

Page 6: WordPress Plugin Development

WordPress Filters

https://codex.wordpress.org/Plugin_API/Filter_Reference

Many listed

Many undocumented

Google and step through debugging was better than developer documentation

Page 7: WordPress Plugin Development

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

Page 8: WordPress Plugin Development

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

Page 9: WordPress Plugin Development

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

Page 10: WordPress Plugin Development

CSS

wp_enqueue_style

Make sure to tell it to put the code in the HEAD

Use version to cache bust

Page 11: WordPress Plugin Development

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

Page 12: WordPress Plugin Development

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

Page 13: WordPress Plugin Development

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

Page 14: WordPress Plugin Development

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

Page 15: WordPress Plugin Development

Integration Testing

Test as many versions as possible

Manual and automated testing

Docker Container for automated testing: https://github.com/LaunchKey/docker-wordpress

Page 16: WordPress Plugin Development

http://spkr8.com/t/60821

@adam_englander

#launchkey on freenode.net

#vegastech on freenode.net

[email protected]