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

Scaling Complexity in WordPress Enterprise Apps

Jul 16, 2015

Download

Technology

Mike Schinkel
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scaling Complexity in WordPress Enterprise Apps

Ye ole WordPress for Big Budgets

a.k.a Using WordPress for Complex

Enterprise Applications

#wpfbb

Page 2: Scaling Complexity in WordPress Enterprise Apps

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.

Page 3: Scaling Complexity in WordPress Enterprise Apps

We Champion WordPress for the Lords (Agencies)

who service the Kings (Larger Organizations)

- Mike Schinkel - @mikeschinkelManaging Partner

NewClarity Consulting LLC

About Me?

Page 4: Scaling Complexity in WordPress Enterprise Apps

Show of Hands?

Developer of Locked-down Client Site?

Internal Developer of Corporate Sites

Developer of Vertical Market Products

None of the above?

Page 5: Scaling Complexity in WordPress Enterprise Apps

What Means Enterprise?Performance & Scalability?

Security Concerns?

Rapid Development?

Professional Workflow?

Scaling Complexity?

Or Big Company Politics?!?

Page 6: Scaling Complexity in WordPress Enterprise Apps

This Talk:

Scaling Complexity

Page 7: Scaling Complexity in WordPress Enterprise Apps

Schinkel’s Law

The Code Quality, Maintainability

and Extensibility of a WordPress Theme (or Plugin) is

inversely proportional to how visually impressive it is.

Page 8: Scaling Complexity in WordPress Enterprise Apps

A Tale of Two WordPresses

Page 9: Scaling Complexity in WordPress Enterprise Apps

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

Page 10: Scaling Complexity in WordPress Enterprise Apps

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

Page 11: Scaling Complexity in WordPress Enterprise Apps

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

Page 12: Scaling Complexity in WordPress Enterprise Apps

Are Best Practices Always Best?

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

Page 13: Scaling Complexity in WordPress Enterprise Apps

Agency-built Sites:

Do Not Need to Switch

Custom Themes!

Page 14: Scaling Complexity in WordPress Enterprise Apps

So Let’s Slay Another

Sacred Cow

Page 15: Scaling Complexity in WordPress Enterprise Apps

Death to “The Loop”

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

Page 16: Scaling Complexity in WordPress Enterprise Apps

Instead: Use anMV* Approach

(Inspired by the Backbone library for Javascript)

Page 17: Scaling Complexity in WordPress Enterprise Apps

Models & Views: For each Post Type

For each Taxonomy

For each User Role

For Comments

And more….

Page 18: Scaling Complexity in WordPress Enterprise Apps

“List” Classes wrap

WP_Query

Page 19: Scaling Complexity in WordPress Enterprise Apps

      $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

Page 20: Scaling Complexity in WordPress Enterprise Apps

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

MV* Theme Code

Page 21: Scaling Complexity in WordPress Enterprise Apps

      $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

Page 22: Scaling Complexity in WordPress Enterprise Apps

   !   <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

Page 23: Scaling Complexity in WordPress Enterprise Apps

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

_html() => wp_kses_post()

_link() => wp_kses_post()

_url() => esc_url()

(none) => esc_html()

Page 24: Scaling Complexity in WordPress Enterprise Apps

Automatic View Methods

Define a Model method slug()

to automatically get a

View method the_slug_attr()

with automatic escaping!

Page 25: Scaling Complexity in WordPress Enterprise Apps

Benefits of MV* Business Logic in the Model

Repetitive HTML in Views

Simple, Easy-to-read Templates

Easier Fragment Caching

Automated Testing (mostly)

Page 26: Scaling Complexity in WordPress Enterprise Apps

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

Page 27: Scaling Complexity in WordPress Enterprise Apps

Techniques in use at:

Dell

Coca-Cola

Internally

Page 28: Scaling Complexity in WordPress Enterprise Apps

But you ask, How?!?

Page 29: Scaling Complexity in WordPress Enterprise Apps

Announcing WPLib

Based on~5 Years Experience

Page 30: Scaling Complexity in WordPress Enterprise Apps

WPLib An Architecture, not an MVC Plugin

A “Foundation Library” to support the architecture.

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

Page 31: Scaling Complexity in WordPress Enterprise Apps

Available Now Open Source - GPLv2

On github.com/wplib

Docs are on wplib.org

Page 32: Scaling Complexity in WordPress Enterprise Apps

WPLib Goal: Adoption among Agencies

Curated Reusable Modules

Enable Faster Implementation of Complex Sites

Page 33: Scaling Complexity in WordPress Enterprise Apps

Thank [email protected]

@mikeschinkel