The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

47
The WordPress Hacker’s Guide to the \Galaxy() Saturday, March 2, 13

description

Having started out as a self-described "WordPress hacker", it's taken me years to discover how to incorporate best practices into a WordPress context. I'll share a brief overview of the plugin devleopment concepts I wish I'd understood earlier, including object-oriented architecture, interface-like dependency management, robust app-like directory structure, super-charged deployment, the power of WP constants and APIs, and more.

Transcript of The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Page 1: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

The WordPress Hacker’s Guide to the \Galaxy()

Saturday, March 2, 13

Page 2: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

@rhodesjasongithub.com/jasonrhodesnotrobotic.com

Saturday, March 2, 13

Page 3: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Terrible design buried under a mountain of spaghetti code

Reading through [WordPress code] is like jabbing red-hot fire pokeys into your eyes.

BEHOLD WORDPRESS, DESTROYER OF CPUS

remote shell with cms on side, aka: shit

shit plugins

WordPress is for cat pictures and diary entries.

code is crapcrapcrap

F$%@ THAT F$%@ THAT F$%@ THAT F$%@ THAT F$%@ THAT F$%@ THAT

WordPress is... just adequate

WordPress is for amateurs.

WordPress is... terrifyingly insecure.

No good default caching, it will kill your server if you don’t know what you’re doing

Stack Overflow spam questions

Not a “real” CMS and definitely not a “real” framework

WordPress, as described by various PHP developers

A really terrible database structure

Saturday, March 2, 13

Page 4: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

WORDPRESS IS NOT THE DEVIL

Saturday, March 2, 13

Page 5: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

WORDPRESS IS

PHPSaturday, March 2, 13

Page 6: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

WORDPRESS IS

CODESaturday, March 2, 13

Page 7: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

BETTER CODEBETTER PHPBETTER WORDPRESS

Saturday, March 2, 13

Page 8: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

THE WP HACKER’S GUIDE TO THE GALAXY

Saturday, March 2, 13

Page 9: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

+

Saturday, March 2, 13

Page 10: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 11: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 12: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 13: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

THE WP HACKER’S GUIDE TO THE GALAXY

Saturday, March 2, 13

Page 14: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

FOLDER STRUCTURE

Saturday, March 2, 13

Page 15: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

mysite /wp-admin /wp-content /wp-includes index.php wp-config.php wp-{etc}.php

Saturday, March 2, 13

Page 16: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

mysite index.php /wp

Saturday, March 2, 13

Page 17: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

WP GIANTS: MARK JAQUITH

Saturday, March 2, 13

Page 18: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 19: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 20: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 21: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

mysite /config /environments environment-config.php /public /content /wp index.php wp-config.php/vendor

Saturday, March 2, 13

Page 22: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 23: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 24: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

LET’S WRITE SOME PLUGIN CODE

Saturday, March 2, 13

Page 25: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 26: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

YES, PLUGINS(NOT FUNCTIONS.PHP)

Saturday, March 2, 13

Page 27: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 28: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

MUST USE PLUGINS

Saturday, March 2, 13

Page 29: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

/plugins cornify.php /batcache/themes/uploads

content

Saturday, March 2, 13

Page 30: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

/plugins cornify.php /batcache/themes/uploads

content/mu-plugins

Saturday, March 2, 13

Page 31: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 32: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Filters filter.Actions (usually) have side effects.

What’s the difference between actions and filters?

http://wp.smashingmagazine.com/2012/02/16/inside-wordpress-actions-filters/

Saturday, March 2, 13

Page 33: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

add_action(“action_name”, “function_name”);

CALLABLE

Saturday, March 2, 13

Page 34: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

array($object, “method_name”)

Saturday, March 2, 13

Page 35: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

LET’S USE OOP

Saturday, March 2, 13

Page 36: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

WP GIANTS: SCRIBU

Saturday, March 2, 13

Page 37: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 38: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 39: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

LET’S NAMESPACE

Saturday, March 2, 13

Page 40: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 41: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 42: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

‣ Load JS/CSS with enqueue functions

‣Write tests (PHPUnit and QUnit)

‣ Experiment with WP-CLI

‣ Fun with caching

‣ Use the APIs

‣ Deploy smart

MORE GOOD THINGS

Saturday, March 2, 13

Page 43: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

‣ Rewrite API‣ Settings API‣ Shortcode API‣ Theme Modification API‣ Theme Customization API‣ Transients API‣ Widgets API‣ XML-RPC WordPress API

‣ Database API‣ HTTP API‣ File Header API‣ Filesystem API‣ Metadata API‣ Options API‣ Plugin API‣ Quicktags API

Saturday, March 2, 13

Page 44: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

mysite current -> releases/1362181983 /releases /1362181983 /1362153455 /1362141927 /shared /config /files

Saturday, March 2, 13

Page 45: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13

Page 46: The WordPress Hacker's Guide to the \Galaxy() [@MidwestPHP]

Saturday, March 2, 13