SlideShare a Scribd company logo
1 of 33
#complexwp | wplib.org | @mikeschinkel
Developing Complex
WordPress Sites*
*Without Fear of Failure
Presenter: Mike Schinkel
WordCamp Raleigh 2015
#complexwp | wplib.org | @mikeschinkel
What to Expect
• Target Audience for the Talk
• Overview of Professional Workflow
• Use of Object Orientation
• Demo of code from a real-world project
• How to make it easy by using WPLib
#complexwp | wplib.org | @mikeschinkel
Prerequisites
• Experience building WordPress websites
• Comfortable developing in PHP
#complexwp | wplib.org | @mikeschinkel
About Me
• Self-Styled WordPress Architect
• Typical Work: $100k+ Agency Projects
• Many WordCamps, LoopConf
• WordPress is my 4th developer ecosystem
2006-2009: Drupal
1993-2006: Visual Basic
1986-1993: Clipper - a dBase Compiler
• Yada, yada
#complexwp | wplib.org | @mikeschinkel
Avoiding a WordPress
House of Cards
A.K.A. Avoiding
Kevin Spacey
#complexwp | wplib.org | @mikeschinkel
Best For Large Budget Projects
Where clients
just expect
us to:
#complexwp | wplib.org | @mikeschinkel
This approach NOT for "Tinkerers"
Who want to
fiddle with it after
you leave.
(And then yell at you
and ask for support
when they break it.)
#complexwp | wplib.org | @mikeschinkel
Disallow Adding of Plugins and
Themes in the Admin Consule
• Use a Custom
Theme
• Minimize 3rd
Party Plugins
#complexwp | wplib.org | @mikeschinkel
Use a Professional Workflow
● A Professional IDE
o PhpStorm+XDebug
● Version Control/Branching
o For Features, and
o For Bug Fixes
● A Deployment Process
o Development (Local)
o Test Server
o Staging Server
o Production Server
● See "Advanced WordPress Workflow”
o That is Micah Wood's talk, next session...
#complexwp | wplib.org | @mikeschinkel
Use an Intelligent Process
• Focus on Requirements
• Create clickable mockups using
moqups.com
• Then Architecture
• Decide on Post Types, Taxonomies, etc
• Separate Theming from
Architecture & Backend Coding
• Best if people with the different skills
are in the different roles
• Maximize “Deployable” Code
• User-entered Configuration Sux
#complexwp | wplib.org | @mikeschinkel
Use an Object Oriented Architecture
•Heard of MVC?
• Embrace Models and Views.
• And Items,
• And Lists,
• And Applications.
• And Helpers,
• And Templates,
• And Modules.
• More on those in a bit…
#complexwp | wplib.org | @mikeschinkel
Wherest thou Objects?
• Post Types
• Taxonomies
• User Roles
• And more!
#complexwp | wplib.org | @mikeschinkel
• Controllers = the "C" in MVC
• But Objects/Classes for
Routing != WordPress
• But you can usually hack it:
URL Routing In WordPress
http://tinyurl.com/wp-url-routing
WordPress handles the Controller (mostly)
#complexwp | wplib.org | @mikeschinkel
DEMO
Reviewing the Code of a
Real World Client Project
Warts and All
(see http://github/wplib for online examples)
#complexwp | wplib.org | @mikeschinkel
Make it easy with WPLib
• Designed for PHP Developers
• Assumes Persistent Cache
• Great for Building Reusable Code
#complexwp | wplib.org | @mikeschinkel
•It is Small
•Does not try to do that much
•Highly Consistent!
•Presents Structured Constraints
•Compatible with (all?) other Frameworks
•WPLib provides incremental value
•Can be used a little, or a lot
•Solves a problem no one else(?) is addressing
WPLib's Positive Attributes
#complexwp | wplib.org | @mikeschinkel
• One Application per site
• Provides root class for a site/app.
• Provides global but site-specific functionality, i.e.
$list = MyApp::get_featured_slide_list([$query]);
MyAPP::the_current_campaign_html();
$url = MyAPP::get_asset_url( 'images/visa-logo.png' );
if ( MyApp::is_featured_slider_enabled() ) {
//...
}
The Application Class
#complexwp | wplib.org | @mikeschinkel
Theme Class
• One Theme Class per theme
• Put your theme hooks here, e.g.
'wp_head'
'wp_enqueue_scripts'
• Location for theme global functionality, e.g.
$theme->the_ad_html();
$theme->the_slider_html();
• Lots of functionality in parent class, e.g.
$theme->the_header_html(); // same as get_header()
$theme->the_site_name();
$page_id = $theme->front_page_id();
#complexwp | wplib.org | @mikeschinkel
Model Classes
• Most of the “business logic" goes here.
• All the “facts” about a type of Item
• One per Item type
class MyApp_Story_Model extends WPLib_Post_Model {
function has_sponsor() {
$has = get_post_meta( $this->ID(), '_myapp_has_sponsor', true );
return 1 == intval( $has );
}
}
#complexwp | wplib.org | @mikeschinkel
View Classes
• Specific methods for outputting Item info
• One or more Views per Item type
• Maybe one View for HTML, one for JSON, etc.
• Most functionality needed in parent class
class MyApp_Featured_Slide_View extends WPLib_Post_View_Base {
function the_embed_code_html() {
echo $this->embed_code();
}
function the_embed_code_textarea() {
echo htmlspecialchars( $this->embed_code() );
}
}
#complexwp | wplib.org | @mikeschinkel
Item Classes
• Container for a Model and a View.
• ONLY class of Model+View+Item you actually use
• Most functionality in the parent class
• Rarely has much if any code
class MyApp_Campaign extends WPLib_Post_Base {
const POST_TYPE = MyApp_Campaigns::POST_TYPE;
const VAR_NAME = 'campaign';
}
#complexwp | wplib.org | @mikeschinkel
List Classes
• Smart arrays of Items
• Can be custom classes with use-case specific methods
• But usually you only need the Default List Class
foreach( MyApp_Featured_Slides::get_list() as $slide ) {
$slide->the_template( 'slide-card' );
}
// OR JUST:
MyApp_Featured_Slides::get_list()->the_template( 'slide-card' );
#complexwp | wplib.org | @mikeschinkel
Helper Classes
• Think of a Helper as "A List of Related Functions"
• Contributes Static Methods
• To your Application class
• We do the same for the WPLib class
• Enables making small, easy to learn APIs
• The Application class is the method "router"
• Helper Method names must be unique across an Application
• Better approach than a single "God" Class
• Allows for many smaller files
• Clearer source code organization
• Better source file management
#complexwp | wplib.org | @mikeschinkel
Helper Classes (cont'd)
class MyApp_Date_Range extends WPLib_Module_Base {
static $_post_types = array();
static function on_load() {
self::register_helper( __CLASS__, 'MyApp' );
}
static function register_date_range_post_type( $post_type ) {
self::$_post_types[ $post_type ] = $post_type;
}
static function date_range_post_types() {
return self::$_post_types;
}
}
MyApp_Date_Range::on_load();
//----------
MyApp::register_date_range_post_type( MyApp_Story::POST_TYPE );
print_r( MyApp::date_range_post_types() );
#complexwp | wplib.org | @mikeschinkel
Module Classes
• Provides Functionality
• Like a Plugin
• Designed for Developers
• Unlike a Plugin
• Designed to be small
• If one grows too big, split it up!
• Should be highly cohesive
• Group related functionality together
#complexwp | wplib.org | @mikeschinkel
• A Main "Entry Point" file
• Contains a main class
• Should hook all hooks needed on page load
• Optimized to load efficiently
• Zero or more /includes/ files
• One class per file
• Include files are autoloaded
• Architected to be Composible
• Reusability: Yeah Baby!
Module Classes (cont'd)
#complexwp | wplib.org | @mikeschinkel
WPLib Templates
• Like Template Parts
• Not template files like single.php, home.php, et. al.
• Typically scoped to an Item
• Or scoped to the Theme class ($theme)
• Or with no scope (called using MyApp::)
• Loaded by $item->the_template('part') method
• Templates in {theme}/templates/{part}.php
#complexwp | wplib.org | @mikeschinkel
Constraints are your Friends
• Templates should contain NO
implementation details
•Should contain ONLY site-specific HTML or
CSS and method calls.
•No WP_Query, no get_post_meta(), etc.
#complexwp | wplib.org | @mikeschinkel
• Contains NO site-specific HTML or CSS
•Auto-generate "the_" methods
•For rendering output
•Conventions for escaping output
•"_url"
•"_attr"
•"_html"
•suffix, etc.
View Methods
#complexwp | wplib.org | @mikeschinkel
A Few Well-Known Constants
•POST_TYPE
•Use to specify the post type in a Post Type Module.
•TAXONOMY
•Use to specify the taxonomy in a Taxonomy Module.
•ROLE
•Use to specify the user role in a User Role Module.
•VAR_NAME
•Use to specify an $item's auto assigned variable name in a template.
•INSTANCE_CLASS
•Use to specify the $item's class name in an MVI module class.
#complexwp | wplib.org | @mikeschinkel
To Learn More about WPLib
•Clone from GitHub, Review sample apps:
•github.com/wplib
•Visit wplib.org
•For Quick Start and other Docs
•Submit issues on GitHub:
•github.com/wplib/wplib/issues
•Ask questions on Twitter:
•@mikeschinkel / @wpscholar
•Discuss on Slack
•Ok: wordpress.slack.com (mikeschinkel/wpscholar)
•Best: thecodersguild.slack.com#wplib
•Email mike@newclarity.net for access
#complexwp | wplib.org | @mikeschinkel
Questions?
#complexwp | wplib.org | @mikeschinkel
THANK YOU
Mike Schinkel
mike@newclarity.net
about.me/mikeschinkel
See also:
www.slideshare.net/mikeschinkel

More Related Content

What's hot

Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 
Widening your JavaScript Application
Widening your JavaScript ApplicationWidening your JavaScript Application
Widening your JavaScript Application
Alex McPherson
 

What's hot (20)

Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 
Untangling the web week 2 - SEO
Untangling the web week 2 - SEOUntangling the web week 2 - SEO
Untangling the web week 2 - SEO
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
Untangling spring week1
Untangling spring week1Untangling spring week1
Untangling spring week1
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
Irb Tips and Tricks
Irb Tips and TricksIrb Tips and Tricks
Irb Tips and Tricks
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
 
Untangling the web week1
Untangling the web week1Untangling the web week1
Untangling the web week1
 
Windycityrails page performance
Windycityrails page performanceWindycityrails page performance
Windycityrails page performance
 
 Active Storage - Modern File Storage? 
 Active Storage - Modern File Storage?  Active Storage - Modern File Storage? 
 Active Storage - Modern File Storage? 
 
Untangling the web11
Untangling the web11Untangling the web11
Untangling the web11
 
Angular.js in XPages
Angular.js in XPagesAngular.js in XPages
Angular.js in XPages
 
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
SharePoint PowerShell for the Admin and Developer - A Venn Diagram ExperienceSharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5Untangling - fall2017 - week5
Untangling - fall2017 - week5
 
Widening your JavaScript Application
Widening your JavaScript ApplicationWidening your JavaScript Application
Widening your JavaScript Application
 
Java™ in Web 2.0
Java™ in Web 2.0Java™ in Web 2.0
Java™ in Web 2.0
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
 

Similar to Developing Complex WordPress Sites without Fear of Failure (with MVC)

The WordPress University
The WordPress UniversityThe WordPress University
The WordPress University
Stephanie Leary
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
Acquia
 
The things we found in your website
The things we found in your websiteThe things we found in your website
The things we found in your website
hernanibf
 

Similar to Developing Complex WordPress Sites without Fear of Failure (with MVC) (20)

Last Call Media Drupal 8 Case Study
Last Call Media Drupal 8 Case StudyLast Call Media Drupal 8 Case Study
Last Call Media Drupal 8 Case Study
 
The WordPress University
The WordPress UniversityThe WordPress University
The WordPress University
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2Ready. Set. Drupal! An Intro to Drupal 8, Part 2
Ready. Set. Drupal! An Intro to Drupal 8, Part 2
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 
Creating a Documentation Portal
Creating a Documentation PortalCreating a Documentation Portal
Creating a Documentation Portal
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper dive
 
Frontend as a first class citizen
Frontend as a first class citizenFrontend as a first class citizen
Frontend as a first class citizen
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesKeep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme Framework
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Drupal: an Overview
Drupal: an OverviewDrupal: an Overview
Drupal: an Overview
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
The things we found in your website
The things we found in your websiteThe things we found in your website
The things we found in your website
 

Recently uploaded

VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 

Recently uploaded (20)

VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 

Developing Complex WordPress Sites without Fear of Failure (with MVC)

  • 1. #complexwp | wplib.org | @mikeschinkel Developing Complex WordPress Sites* *Without Fear of Failure Presenter: Mike Schinkel WordCamp Raleigh 2015
  • 2. #complexwp | wplib.org | @mikeschinkel What to Expect • Target Audience for the Talk • Overview of Professional Workflow • Use of Object Orientation • Demo of code from a real-world project • How to make it easy by using WPLib
  • 3. #complexwp | wplib.org | @mikeschinkel Prerequisites • Experience building WordPress websites • Comfortable developing in PHP
  • 4. #complexwp | wplib.org | @mikeschinkel About Me • Self-Styled WordPress Architect • Typical Work: $100k+ Agency Projects • Many WordCamps, LoopConf • WordPress is my 4th developer ecosystem 2006-2009: Drupal 1993-2006: Visual Basic 1986-1993: Clipper - a dBase Compiler • Yada, yada
  • 5. #complexwp | wplib.org | @mikeschinkel Avoiding a WordPress House of Cards A.K.A. Avoiding Kevin Spacey
  • 6. #complexwp | wplib.org | @mikeschinkel Best For Large Budget Projects Where clients just expect us to:
  • 7. #complexwp | wplib.org | @mikeschinkel This approach NOT for "Tinkerers" Who want to fiddle with it after you leave. (And then yell at you and ask for support when they break it.)
  • 8. #complexwp | wplib.org | @mikeschinkel Disallow Adding of Plugins and Themes in the Admin Consule • Use a Custom Theme • Minimize 3rd Party Plugins
  • 9. #complexwp | wplib.org | @mikeschinkel Use a Professional Workflow ● A Professional IDE o PhpStorm+XDebug ● Version Control/Branching o For Features, and o For Bug Fixes ● A Deployment Process o Development (Local) o Test Server o Staging Server o Production Server ● See "Advanced WordPress Workflow” o That is Micah Wood's talk, next session...
  • 10. #complexwp | wplib.org | @mikeschinkel Use an Intelligent Process • Focus on Requirements • Create clickable mockups using moqups.com • Then Architecture • Decide on Post Types, Taxonomies, etc • Separate Theming from Architecture & Backend Coding • Best if people with the different skills are in the different roles • Maximize “Deployable” Code • User-entered Configuration Sux
  • 11. #complexwp | wplib.org | @mikeschinkel Use an Object Oriented Architecture •Heard of MVC? • Embrace Models and Views. • And Items, • And Lists, • And Applications. • And Helpers, • And Templates, • And Modules. • More on those in a bit…
  • 12. #complexwp | wplib.org | @mikeschinkel Wherest thou Objects? • Post Types • Taxonomies • User Roles • And more!
  • 13. #complexwp | wplib.org | @mikeschinkel • Controllers = the "C" in MVC • But Objects/Classes for Routing != WordPress • But you can usually hack it: URL Routing In WordPress http://tinyurl.com/wp-url-routing WordPress handles the Controller (mostly)
  • 14. #complexwp | wplib.org | @mikeschinkel DEMO Reviewing the Code of a Real World Client Project Warts and All (see http://github/wplib for online examples)
  • 15. #complexwp | wplib.org | @mikeschinkel Make it easy with WPLib • Designed for PHP Developers • Assumes Persistent Cache • Great for Building Reusable Code
  • 16. #complexwp | wplib.org | @mikeschinkel •It is Small •Does not try to do that much •Highly Consistent! •Presents Structured Constraints •Compatible with (all?) other Frameworks •WPLib provides incremental value •Can be used a little, or a lot •Solves a problem no one else(?) is addressing WPLib's Positive Attributes
  • 17. #complexwp | wplib.org | @mikeschinkel • One Application per site • Provides root class for a site/app. • Provides global but site-specific functionality, i.e. $list = MyApp::get_featured_slide_list([$query]); MyAPP::the_current_campaign_html(); $url = MyAPP::get_asset_url( 'images/visa-logo.png' ); if ( MyApp::is_featured_slider_enabled() ) { //... } The Application Class
  • 18. #complexwp | wplib.org | @mikeschinkel Theme Class • One Theme Class per theme • Put your theme hooks here, e.g. 'wp_head' 'wp_enqueue_scripts' • Location for theme global functionality, e.g. $theme->the_ad_html(); $theme->the_slider_html(); • Lots of functionality in parent class, e.g. $theme->the_header_html(); // same as get_header() $theme->the_site_name(); $page_id = $theme->front_page_id();
  • 19. #complexwp | wplib.org | @mikeschinkel Model Classes • Most of the “business logic" goes here. • All the “facts” about a type of Item • One per Item type class MyApp_Story_Model extends WPLib_Post_Model { function has_sponsor() { $has = get_post_meta( $this->ID(), '_myapp_has_sponsor', true ); return 1 == intval( $has ); } }
  • 20. #complexwp | wplib.org | @mikeschinkel View Classes • Specific methods for outputting Item info • One or more Views per Item type • Maybe one View for HTML, one for JSON, etc. • Most functionality needed in parent class class MyApp_Featured_Slide_View extends WPLib_Post_View_Base { function the_embed_code_html() { echo $this->embed_code(); } function the_embed_code_textarea() { echo htmlspecialchars( $this->embed_code() ); } }
  • 21. #complexwp | wplib.org | @mikeschinkel Item Classes • Container for a Model and a View. • ONLY class of Model+View+Item you actually use • Most functionality in the parent class • Rarely has much if any code class MyApp_Campaign extends WPLib_Post_Base { const POST_TYPE = MyApp_Campaigns::POST_TYPE; const VAR_NAME = 'campaign'; }
  • 22. #complexwp | wplib.org | @mikeschinkel List Classes • Smart arrays of Items • Can be custom classes with use-case specific methods • But usually you only need the Default List Class foreach( MyApp_Featured_Slides::get_list() as $slide ) { $slide->the_template( 'slide-card' ); } // OR JUST: MyApp_Featured_Slides::get_list()->the_template( 'slide-card' );
  • 23. #complexwp | wplib.org | @mikeschinkel Helper Classes • Think of a Helper as "A List of Related Functions" • Contributes Static Methods • To your Application class • We do the same for the WPLib class • Enables making small, easy to learn APIs • The Application class is the method "router" • Helper Method names must be unique across an Application • Better approach than a single "God" Class • Allows for many smaller files • Clearer source code organization • Better source file management
  • 24. #complexwp | wplib.org | @mikeschinkel Helper Classes (cont'd) class MyApp_Date_Range extends WPLib_Module_Base { static $_post_types = array(); static function on_load() { self::register_helper( __CLASS__, 'MyApp' ); } static function register_date_range_post_type( $post_type ) { self::$_post_types[ $post_type ] = $post_type; } static function date_range_post_types() { return self::$_post_types; } } MyApp_Date_Range::on_load(); //---------- MyApp::register_date_range_post_type( MyApp_Story::POST_TYPE ); print_r( MyApp::date_range_post_types() );
  • 25. #complexwp | wplib.org | @mikeschinkel Module Classes • Provides Functionality • Like a Plugin • Designed for Developers • Unlike a Plugin • Designed to be small • If one grows too big, split it up! • Should be highly cohesive • Group related functionality together
  • 26. #complexwp | wplib.org | @mikeschinkel • A Main "Entry Point" file • Contains a main class • Should hook all hooks needed on page load • Optimized to load efficiently • Zero or more /includes/ files • One class per file • Include files are autoloaded • Architected to be Composible • Reusability: Yeah Baby! Module Classes (cont'd)
  • 27. #complexwp | wplib.org | @mikeschinkel WPLib Templates • Like Template Parts • Not template files like single.php, home.php, et. al. • Typically scoped to an Item • Or scoped to the Theme class ($theme) • Or with no scope (called using MyApp::) • Loaded by $item->the_template('part') method • Templates in {theme}/templates/{part}.php
  • 28. #complexwp | wplib.org | @mikeschinkel Constraints are your Friends • Templates should contain NO implementation details •Should contain ONLY site-specific HTML or CSS and method calls. •No WP_Query, no get_post_meta(), etc.
  • 29. #complexwp | wplib.org | @mikeschinkel • Contains NO site-specific HTML or CSS •Auto-generate "the_" methods •For rendering output •Conventions for escaping output •"_url" •"_attr" •"_html" •suffix, etc. View Methods
  • 30. #complexwp | wplib.org | @mikeschinkel A Few Well-Known Constants •POST_TYPE •Use to specify the post type in a Post Type Module. •TAXONOMY •Use to specify the taxonomy in a Taxonomy Module. •ROLE •Use to specify the user role in a User Role Module. •VAR_NAME •Use to specify an $item's auto assigned variable name in a template. •INSTANCE_CLASS •Use to specify the $item's class name in an MVI module class.
  • 31. #complexwp | wplib.org | @mikeschinkel To Learn More about WPLib •Clone from GitHub, Review sample apps: •github.com/wplib •Visit wplib.org •For Quick Start and other Docs •Submit issues on GitHub: •github.com/wplib/wplib/issues •Ask questions on Twitter: •@mikeschinkel / @wpscholar •Discuss on Slack •Ok: wordpress.slack.com (mikeschinkel/wpscholar) •Best: thecodersguild.slack.com#wplib •Email mike@newclarity.net for access
  • 32. #complexwp | wplib.org | @mikeschinkel Questions?
  • 33. #complexwp | wplib.org | @mikeschinkel THANK YOU Mike Schinkel mike@newclarity.net about.me/mikeschinkel See also: www.slideshare.net/mikeschinkel