Escolar Documentos
Profissional Documentos
Cultura Documentos
Model-View-Controller
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
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
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.
readme.txt
Readme.txt helps people nd your
plugin
Folder Structure
You can organize your plugin with a Rails-style folder structure. Everything can be found easily
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:
Options Mechanism
The Options Model is serialized and stored via get_options:
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
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
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"
Q &A
Twitter: @blairwilli Website: http://blairwilliams.com Get These Slides Here: http://makewpplugins.com