Está en la página 1de 35

Pimp Your WP Plugin

What is a PMP (aka Pimp)?


PMP stands for Platform Modifying Plugin Technically all plugins modify the WordPress platform but PMPs do so on a larger scale.

PMPs Can Give You More Attention


Since PMPs give WordPress signicant new features, they can also drive more attention to you.

PMPs can make you Money


You need substantial features in your plugin if youre planning on charging for it

You Can Build a PMP!


Ive got a system for rapidly developing and deploying signicantly large plugins. Thats what this presentation is all about!

What Will Your PMP Do?


Talk about ideas on your blog Visit WordPress forums Google Keyword Research Scratch Your Own Itch

Mockup Your Plugin


Wireframe Your GUI & DB Dont waste time - just hand
draw your wireframes

Model-View-Controller

MVC Is Nothing New



Java (Struts & Spring) Ruby on Rails PHP (CakePHP, Symfony & Others) C++ (QT) Python (Django) Perl (Catalyst) Objective-C (iPhone, iPad, OSX)

Why MVC?

It can make a larger code-base more manageable It can make it easier to write more stable code It can make it easier to pinpoint bugs and performance bottlenecks It can make your plugin easier to read and therefore extend-able by other developers It can make it easier to re-use your code

A Lightweight MVC works well in WP


You cant use an MVC framework
within a WordPress plugin

You have to build your own

MVC Overview
The Model: Database & Calculations The View: Presentation (HTML/CSS) The Controller: Routing / Glues the Model & View Together

The Model
Your Interface with the Database Wraps CRUD functions Wraps all SQL Used to Objectify Database Tables Calculations & Business Logic

The View
Your Presentation Layer This is where your HTML/CSS and other
presentation technologies reside

Only uses Basic Logic Controller loads the View

The Controller
Controls Data Flow Between Model & View Routes User Requests & Responses Controller Constructors typically contain
WP Hooks so when they are loaded, hooks are initialized.

Other WP MVC Classes


Helper Classes Methods that render common display
elements

Widget Classes Built in WP Widgets can easily be folded


into this type of structure

Important Parts of Your Plugin

readme.txt
Readme.txt helps people nd your
plugin

Promote your plugin by loading


Notice section updated

readme.txt with applicable tags & a keyword rich description

Keep your Change Log & Upgrade

Folder Structure
You can organize your plugin with a Rails-style folder structure. Everything can be found easily

The Entry Point


Your main PHP le sets up your plugin environment:

Sets up important PATHs

and URLs Loads Option Objects Loads Your Plugins Globals Loads All Models, Controllers and Helpers Can Load Shortcodes

The AppController
This Controller has Special responsibilities:

Houses Installation Routines Routes Page / Post Requests Routes Standalone Requests Sets up Admin Menus Enqueues JS & CSS Files Loads i18n language les

The DB Model
This Model has Special responsibilities:

Stores your custom table


names for use in SQL Houses Your Database Upgrade Routines Houses Your Database Migration Routines Can include basic CRUD methods used by other Models

Options Mechanism
The Options Model is serialized and stored via get_options:

May contain all of the

options for your plugin Used in addition to a Controller & View to Store and Retrieve Options. Retrieved and Unserialized from the Database in your Entry Point PHP le

Utilities Models
These arent pure models -but are important. Utility Models can contain static methods which are utilized across your PMP.

Be a good Neighbor
Many WordPress users install a lot of plugins. Make sure your plugin isnt more of a problem than a solution.

Testing
WordPress can run in a variety of Make sure theres an easy way for
users to report bugs make this easier) environments so testing can be hard

Write & Run Unit tests (MVC can

Memory Management
XDebug TPC Memory Plugin Use good memory management practices
to begin with -- like using references.

Database Calls
DB Writes can be expensive Try to use built in WordPress storage
functions rst

WPDB Proler Plugin: MySQL Proler

Fix Your Programs Execution Time


Simplify Your code Limit your plugins network access
(API calls, etc) your plugin

Avoid bottlenecks in critical parts of

Deploying Your Plugin

Create a Deployment Process for Your PMP


Write down a simple process in a
Text le

Make sure the process is Repeatable Command Line can make this easier
-- Really

SVN Tools
Windows: TortoiseSVN Mac: TextMate or Versions Command Line SVN

My Deployment Procedure

cd ~/deploy/mycoolplugin svn up mate trunk/readme.txt trunk/mycoolplugin.php rsync -r --exclude=.svn trunk/ tags/0.0.xx svn add tags/0.0.xx svn ci -m "0.0.xx Release of My Cool Plugin"

Now Its Time for Some WordPress Pimpn!

Q &A
Twitter: @blairwilli Website: http://blairwilliams.com Get These Slides Here: http://makewpplugins.com