Developing WordPress for the Future Pt. 2
Continuing the discussion from the first installment of Friendly WordPress Development, from contributing blogger, Lucy Beer. We get deeper into API usage techniques in part two, so take notes and feel free to give us some feedback in the comments.
Don’t Reinvent The Wheel – There’s a WordPress API For That
WordPress has a number of APIs which can make your life easier *and* help make your theme or plugin future-proof, extendable and just, you know, better. Before you go trying to invent things from scratch, see if WordPress provides specialized functions you can tap into first. The WordPress API’s often have characteristics like data sanitization built in, making your code more secure by default, which is a good thing. Familiarize yourself with the Codex page to discover time and code saving API’s.
The Power of the Plugin
WordPress’ system of hooks, actions and filters will get you far. They are listed as part of the *Plugin* API, but even if you are developing a custom theme you will be able to make use of them.
They allow you to modify all kinds of things about WordPress functionality without actually hacking WordPress core files (a huge no-no). Jeffrey Zinn has a great intro presentation on how to get started with these:
Once you understand these concepts, a whole new world of possibilities opens up to you.
Consider: Theme vs Plugin
When building a custom theme, whether for a client or for commercial / general release, it’s important to consider whether some of the functionality you want to include should be included in the theme, or incorporated as a plugin. The most common examples of features found in themes that would serve their function and the site better as plugins are custom post types and shortcodes. There’s a whole debate around this and I recommend you get caught up on the ins and outs by reading Justin Tadlock’s recent post on the topic:
Keep it Lean
I’ve seen many a theme suffer from enormous bloat because they include literally 5 different slider options in the theme! Now while you might think this is great for the end user since they have so much to choose from, it’s not. This is an overly complicated admin experience, creates more possibility for conflicts with other plugins and makes it nearly impossible for future developers to maintain these options.
A good rule of thumb for keeping your theme lean is to stick to the “Recommended or Required Plugins” approach. This is where, upon installation, the user sees a notification letting them know which plugins should also be added. The user can then choose which to turn on or off. Those features then become portable should the user decide to change themes. One way of implementing this is using the TGM Plugin Activation library.
These tips are just scratching the surface of best practices, but hopefully you are convinced it’s worth your time. The effort you take as a developer to implement these has a real world impact on the user’s experience with WordPress, and therefore its continued sustainability.
About the Author: Lucy Beer is a web and WordPress consultant focused on making WordPress accessible to the beginner and a powerful development platform for the advanced user. Lucy runs Web Training Wheels and can be found speaking around the country or on Twitter.