HighEdWeb becomes Digital Collegium on Nov. 1. Discover the new brand

Categories
2016 Conference

Stop Repeating Yourself: Modularized WordPress Development

Jim Barnes
Web Applications Developer, University of Central Florida
Jo Dickson
Web Applications Programmer, University of Central Florida
https://2016reg.highedweb.org/psessions/detail/691667c1-72fe-4974-8f23-18efc701eb87

Jim and Jo’s office is supporting 36 sites using the same core code, but copying WordPress themes across sites.  Most functionality is defined a common theme, with limited plugins. New projects are developed as complete sites, not just themes, so the content can inform the look and functionality.

Some of the technologies that are critical to this kind of development
Custom post types: Provide registration logic, name generation, shortcode registration, metaboxes, and fields. Advantages include simplified development, maximum customization, centralized code base, CSS and JS are minified and combined, and no plugin bloat. Disadvantages include repeating yourself (with cloned themes), duplicating features and styles, decentralized bug fixing, data loss if you change the custom post types in the theme, and it’s just not a best practice.

Let’s apply D.R.Y. principles…Don’t Repeat Yourself!

Best practices: Themes should provide look and feel, and your plugins should provide functionality and data structure

Some challenges with best practices include dependency management, plugin bloat, and more work to deliver minified assets.

So, how do we stop repeating ourselves?

Move custom theme functionalities into plugins. Separate theme functionality from plugin functionality. Layout, styles, and presentation configuration belong in the theme. Functionality, data definition, and data configuration belong in plugins.

Plugins need to work out of the box, but themes should be able to inform or override plugins with customizations as necessary. Actions, filters, as SASS attachment points help do this.

Don’t build plugins to reinvent the wheel. If there’s already a contributed plugin that does what you need, be sure to do a full code review before going into production.

Some tips:
Avoid unnecessary dependencies
Use simple plugin detection — if a plugin is not installed, it can’t work!
Themes should focus on layout, styling, and content.
Ensure that themes fail gracefully, if they have to fail.

The templating tool Yeoman can help modularize layout customizations, adjust SASS variables, choose page templates, and more.

Advantages of modularization:
More effective maintenance and upgrade cycles
Even more rapid development of new themes
Distributed functionality and standard styles
Increased consistency across sites

Challenges of modularization:
Upfront development time
More documenting and testing is required
Site-drive to product driven culture shift
It’s a lot of work, at first!

Code for their project is available at https://github.com/UCF/

Share this: