33
Ye ole WordPress for Big Budgets a.k.a Using WordPress for Complex Enterprise Applications #wpfbb

Scaling Complexity in WordPress Enterprise Apps

Embed Size (px)

Citation preview

Ye ole WordPress for Big Budgets

a.k.a Using WordPress for Complex

Enterprise Applications

#wpfbb

The Slide Added After Presentation

To the designers whose sensibilities I offended for using Papyrus, I apologize sincerely.

I am not a designer and do not recognize these

things. I blame Apple and Keynote.

We Champion WordPress for the Lords (Agencies)

who service the Kings (Larger Organizations)

- Mike Schinkel - @mikeschinkelManaging Partner

NewClarity Consulting LLC

About Me?

Show of Hands?

Developer of Locked-down Client Site?

Internal Developer of Corporate Sites

Developer of Vertical Market Products

None of the above?

What Means Enterprise?Performance & Scalability?

Security Concerns?

Rapid Development?

Professional Workflow?

Scaling Complexity?

Or Big Company Politics?!?

This Talk:

Scaling Complexity

Schinkel’s Law

The Code Quality, Maintainability

and Extensibility of a WordPress Theme (or Plugin) is

inversely proportional to how visually impressive it is.

A Tale of Two WordPresses

In Days of Yor

WordPress was Just a Blog

Themes were Just Templates

Sites were Built by Adding Plugins

And Cowboy Coders Ruled the Land

Then the Settlers Came

They Wanted Sites for Business

Agencies Emerged to Serve Them

Designers Envisioned Great Designs

And the Settlers Wanted it Now

But the Cowboy Coders Failed Them All

New Sheriffs Are in Town

They are Cleaning up Bad Practices

They are Requiring Version Control and Multi-server Deployment Processes

And they Separate Concerns in Code

All while Respecting the Townsfolk

Are Best Practices Always Best?

i.e. “No Post Types in a Theme!”

Agency-built Sites:

Do Not Need to Switch

Custom Themes!

So Let’s Slay Another

Sacred Cow

Death to “The Loop”

Yeah: It’s LoopConf. I Get the Irony.

Instead: Use anMV* Approach

(Inspired by the Backbone library for Javascript)

Models & Views: For each Post Type

For each Taxonomy

For each User Role

For Comments

And more….

“List” Classes wrap

WP_Query

      $partners  =  new  WP_Query(  array(               ‘post_type’  =>  ‘lp_person’,       ‘order’       =>  ‘asc’       ‘orderby’     =>  ‘title’       ‘meta_key’    =>  ‘_position’,       ‘meta_value’=>  ‘partner’,       ‘posts_per_page’  =>  99,     ));?>     <ul  id=“partner-­‐list”>       <?php  while  ($partners-­‐>have_posts()):       $partners-­‐>the_post();  ?>     <li><a  href=“<?php  get_permalink();  ?>”>               <?php  the_title();  ?></a></li>         <?php  endwhile;  ?></ul>  

Typical Theme Code

      <ul  id=“partner-­‐list”>  !   <?php       foreach  (LawPress::partner_list()  as  $partner):     ?>             <li><?php  $partner-­‐>the_title_link();  ?></li>      !   <?php       endforeach;       ?>  !   </ul>  

MV* Theme Code

      $person  =  new  LawPress_Person(  $post  );     <h1><?php  $person-­‐>the_fullname();  ?></h1>     <?php  $person-­‐>the_template(‘person-­‐contact’);  ?>         <div  class=“bio”>       <?php  $person-­‐>the_content_html();  ?>     </div>     <div  class=“team-­‐list”>     <?php         $person-­‐>team_list()-­‐>the_template(‘team-­‐link’);     ?>     </div>  

Full Visibility for Themers

   !   <div  id=“<?php  $article-­‐>the_slug_attr();  ?>”>        !     <h1><?php  $article-­‐>the_title();  ?></h1>  !     <?php  $article-­‐>the_content_html();  ?>  !     <img  src=“<?php  $article-­‐>the_image_url();  ?>”      !   </div>  !

Suffixes Define Escape

Convention-Driven Escaping _attr() => esc_attr()

_html() => wp_kses_post()

_link() => wp_kses_post()

_url() => esc_url()

(none) => esc_html()

Automatic View Methods

Define a Model method slug()

to automatically get a

View method the_slug_attr()

with automatic escaping!

Benefits of MV* Business Logic in the Model

Repetitive HTML in Views

Simple, Easy-to-read Templates

Easier Fragment Caching

Automated Testing (mostly)

Benefits, cont’d Fewer Global Variable Bugs

Fewer Hook Side-effect Bugs

Separates Team Member Concerns

HTML/CSS vs. Javascript vs. PHP/MySQL

Enables Reusable Modules

Techniques in use at:

Dell

Coca-Cola

Internally

But you ask, How?!?

Announcing WPLib

Based on~5 Years Experience

WPLib An Architecture, not an MVC Plugin

A “Foundation Library” to support the architecture.

Built for Coders, not for End-users or “Sitebuilders”

Available Now Open Source - GPLv2

On github.com/wplib

Docs are on wplib.org

WPLib Goal: Adoption among Agencies

Curated Reusable Modules

Enable Faster Implementation of Complex Sites