SlideShare a Scribd company logo
#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
Ad

Recommended

Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?
Edmund Turbin
 
Webcomponents are your frameworks best friend
Webcomponents are your frameworks best friend
Filip Bruun Bech-Larsen
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
Windzoon Technologies
 
Frameworks and webcomponents
Frameworks and webcomponents
Filip Bruun Bech-Larsen
 
A Day of REST
A Day of REST
Scott Taylor
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and Joomla
George Wilson
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React Ecosystem
Rami Sayar
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
Gil Fink
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Viktor Vogel
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
Untangling the web week 2 - SEO
Untangling the web week 2 - SEO
Derek Jacoby
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
daylerees
 
Untangling spring week1
Untangling spring week1
Derek Jacoby
 
Saving Time By Testing With Jest
Saving Time By Testing With Jest
Ben McCormick
 
Irb Tips and Tricks
Irb Tips and Tricks
John McCaffrey
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Geoff Varosky
 
Untangling the web week1
Untangling the web week1
Derek Jacoby
 
Windycityrails page performance
Windycityrails page performance
John McCaffrey
 
 Active Storage - Modern File Storage? 
 Active Storage - Modern File Storage? 
Michael Yagudaev
 
Untangling the web11
Untangling the web11
Derek Jacoby
 
Angular.js in XPages
Angular.js in XPages
Mark Roden
 
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Ricardo Wilkins
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5
Derek Jacoby
 
Widening your JavaScript Application
Widening your JavaScript Application
Alex McPherson
 
Java™ in Web 2.0
Java™ in Web 2.0
elliando dias
 
C# Async/Await Explained
C# Async/Await Explained
Jeremy Likness
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
Ivo Lukac
 
Wordpress development 101
Wordpress development 101
Commit Software Sh.p.k.
 
Wordpress as a framework
Wordpress as a framework
Aggelos Synadakis
 

More Related Content

What's hot (20)

Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Viktor Vogel
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
Untangling the web week 2 - SEO
Untangling the web week 2 - SEO
Derek Jacoby
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
daylerees
 
Untangling spring week1
Untangling spring week1
Derek Jacoby
 
Saving Time By Testing With Jest
Saving Time By Testing With Jest
Ben McCormick
 
Irb Tips and Tricks
Irb Tips and Tricks
John McCaffrey
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Geoff Varosky
 
Untangling the web week1
Untangling the web week1
Derek Jacoby
 
Windycityrails page performance
Windycityrails page performance
John McCaffrey
 
 Active Storage - Modern File Storage? 
 Active Storage - Modern File Storage? 
Michael Yagudaev
 
Untangling the web11
Untangling the web11
Derek Jacoby
 
Angular.js in XPages
Angular.js in XPages
Mark Roden
 
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Ricardo Wilkins
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5
Derek Jacoby
 
Widening your JavaScript Application
Widening your JavaScript Application
Alex McPherson
 
Java™ in Web 2.0
Java™ in Web 2.0
elliando dias
 
C# Async/Await Explained
C# Async/Await Explained
Jeremy Likness
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
Ivo Lukac
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Joomla! multiplied - How to run Multi-Sites - JandBeyond 2014
Viktor Vogel
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
Untangling the web week 2 - SEO
Untangling the web week 2 - SEO
Derek Jacoby
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
daylerees
 
Untangling spring week1
Untangling spring week1
Derek Jacoby
 
Saving Time By Testing With Jest
Saving Time By Testing With Jest
Ben McCormick
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Geoff Varosky
 
Untangling the web week1
Untangling the web week1
Derek Jacoby
 
Windycityrails page performance
Windycityrails page performance
John McCaffrey
 
 Active Storage - Modern File Storage? 
 Active Storage - Modern File Storage? 
Michael Yagudaev
 
Untangling the web11
Untangling the web11
Derek Jacoby
 
Angular.js in XPages
Angular.js in XPages
Mark Roden
 
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Ricardo Wilkins
 
Untangling - fall2017 - week5
Untangling - fall2017 - week5
Derek Jacoby
 
Widening your JavaScript Application
Widening your JavaScript Application
Alex McPherson
 
C# Async/Await Explained
C# Async/Await Explained
Jeremy Likness
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
Ivo Lukac
 

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

Wordpress development 101
Wordpress development 101
Commit Software Sh.p.k.
 
Wordpress as a framework
Wordpress as a framework
Aggelos Synadakis
 
Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]
SlipFire LLC.
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Jer Clarke
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
Michael McNeill
 
WordPress as an application framework
WordPress as an application framework
Dustin Filippini
 
Wordpress beyond blogging
Wordpress beyond blogging
Julien Minguely
 
Scaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise Apps
Mike Schinkel
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
TomAuger
 
Developing WordPress Plugins Using the MVC Methodology
Developing WordPress Plugins Using the MVC Methodology
Nate Allen
 
Bending word press to your will
Bending word press to your will
Tom Jenkins
 
The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesign
Maurizio Pelizzone
 
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
asbelaailaaj
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
Optimizing Your WordPress Site
Optimizing Your WordPress Site
Phil Buckley
 
WordPress as a CMS
WordPress as a CMS
Curtiss Grymala
 
Wordpress workflow for an agency world
Wordpress workflow for an agency world
Chris Lowe
 
eMusic: WordPress in the Enterprise
eMusic: WordPress in the Enterprise
Scott Taylor
 
Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]
SlipFire LLC.
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Jer Clarke
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
Michael McNeill
 
WordPress as an application framework
WordPress as an application framework
Dustin Filippini
 
Wordpress beyond blogging
Wordpress beyond blogging
Julien Minguely
 
Scaling Complexity in WordPress Enterprise Apps
Scaling Complexity in WordPress Enterprise Apps
Mike Schinkel
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
TomAuger
 
Developing WordPress Plugins Using the MVC Methodology
Developing WordPress Plugins Using the MVC Methodology
Nate Allen
 
Bending word press to your will
Bending word press to your will
Tom Jenkins
 
The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesign
Maurizio Pelizzone
 
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
asbelaailaaj
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
Optimizing Your WordPress Site
Optimizing Your WordPress Site
Phil Buckley
 
Wordpress workflow for an agency world
Wordpress workflow for an agency world
Chris Lowe
 
eMusic: WordPress in the Enterprise
eMusic: WordPress in the Enterprise
Scott Taylor
 
Ad

Recently uploaded (20)

ChatGPT_and_Its_Uses_Presentationss.pptx
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
BitRecover OST to PST Converter Software
BitRecover OST to PST Converter Software
antoniogosling01
 
inside the internet - understanding the TCP/IP protocol
inside the internet - understanding the TCP/IP protocol
shainweniton02
 
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
Topic 2 - Cloud Computing Basics,,,.pptx
Topic 2 - Cloud Computing Basics,,,.pptx
oneillp100
 
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
ragnaralpha7199
 
Logging and Automated Alerting Webinar.pdf
Logging and Automated Alerting Webinar.pdf
ControlCase
 
DDoS in India, presented at INNOG 8 by Dave Phelan
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
cybercrime investigation and digital forensics
cybercrime investigation and digital forensics
goverdhankumar137300
 
Almos Entirely Correct Mixing with Apps to Voting
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
BroadLink Cloud Service introduction.pdf
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
COMPUTER ETHICS AND CRIME.......................................................
COMPUTER ETHICS AND CRIME.......................................................
FOOLKUMARI
 
Transmission Control Protocol (TCP) and Starlink
Transmission Control Protocol (TCP) and Starlink
APNIC
 
Paper: The World Game (s) Great Redesign.pdf
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
history of internet in nepal Class-8 (sparsha).pptx
history of internet in nepal Class-8 (sparsha).pptx
SPARSH508080
 
Lecture 3.1 Analysing the Global Business Environment .pptx
Lecture 3.1 Analysing the Global Business Environment .pptx
shofalbsb
 
ChatGPT A.I. Powered Chatbot and Popularization.pdf
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
ChatGPT_and_Its_Uses_Presentationss.pptx
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
BitRecover OST to PST Converter Software
BitRecover OST to PST Converter Software
antoniogosling01
 
inside the internet - understanding the TCP/IP protocol
inside the internet - understanding the TCP/IP protocol
shainweniton02
 
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
Topic 2 - Cloud Computing Basics,,,.pptx
Topic 2 - Cloud Computing Basics,,,.pptx
oneillp100
 
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
Dark Web Presentation - 1.pdf about internet which will help you to get to kn...
ragnaralpha7199
 
Logging and Automated Alerting Webinar.pdf
Logging and Automated Alerting Webinar.pdf
ControlCase
 
DDoS in India, presented at INNOG 8 by Dave Phelan
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
cybercrime investigation and digital forensics
cybercrime investigation and digital forensics
goverdhankumar137300
 
Almos Entirely Correct Mixing with Apps to Voting
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
BroadLink Cloud Service introduction.pdf
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
COMPUTER ETHICS AND CRIME.......................................................
COMPUTER ETHICS AND CRIME.......................................................
FOOLKUMARI
 
Transmission Control Protocol (TCP) and Starlink
Transmission Control Protocol (TCP) and Starlink
APNIC
 
Paper: The World Game (s) Great Redesign.pdf
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
history of internet in nepal Class-8 (sparsha).pptx
history of internet in nepal Class-8 (sparsha).pptx
SPARSH508080
 
Lecture 3.1 Analysing the Global Business Environment .pptx
Lecture 3.1 Analysing the Global Business Environment .pptx
shofalbsb
 
ChatGPT A.I. Powered Chatbot and Popularization.pdf
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
Ad

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 [email protected] for access
  • 32. #complexwp | wplib.org | @mikeschinkel Questions?
  • 33. #complexwp | wplib.org | @mikeschinkel THANK YOU Mike Schinkel [email protected] about.me/mikeschinkel See also: www.slideshare.net/mikeschinkel