Software Reuse• What is it? Creating code that can be usedacross several projects. Using existing softwareto create new software.• Why is it Important?• It saves time• It’s easier to test• It allows you to focus on more advancedparts of a project.
Principles of Reuse• DesignYour Code• Layout functions, classes, page templates beforehand!• Generalize Where Possible• Recognize when you’re reusing code snippets• Document & Test Thoroughly!• Testing will ensure your code works beforeimplementing it 5, 10, or 20 times
DefineYour Needs• We all have different needs!• I’ll talk about mine. Keep yours in mind.• EvaluateYour Process• ReviewYour Code• What do you do over and over?• Look for the same code across recentprojects!
DefineYour Needs (my needs)• Plugable CSS• Constants for Theme & Image URLS• Common WordPress functionality (menus,sidebars, CPTs, etc.)• Most Common theme templates (header, footer,page, index)• Common Folders• Lightweight
Now What?• You know what you needs. Now what?• Before you code, see what’s out there!• Can a plugin or other theme fulfill yourneeds?• Is there already some theme you use as astarting point?
What’s Out There (themes)• Thematic• Thesis• Carrington• Genesis• Atahualpa
What’s Out There (Plugins)• OptionTree• Custom Post Type UI• Royal Slider• Contact Form 7
Building the Framework• What to do, what to do...
DesigningYour Code• I noticed I was doing a couple of things over and over• Copy K2• Rip out stuff I didnt use• Replace it with my standard template• Modify• Eventually, I would just copy the last theme I created• I took my common components and created myframework
Necessary Files• Style.css• Functions.php• Index.php• That’s it! WordPress will fill in the blankswith only these.
Recommended Files• All Necessary files• header.php & footer.php• page.php• single.php• A Custom Post Type generator/template• A theme options generator/template• search.php• archive.php• sidebar.php
My CSS• Single Sheet• Compressed normalize.css• Some base styles• Standard HTML5 Elements• Basic Navigation CSS• Mobile first approach• Basic Media Queries• Any common classes and IE Fixes
My Functions• Constants to use throughout the whole theme:define( TEMPPATH, get_bloginfo(stylesheet_directory));define( IMAGES, TEMPPATH. "/images");• Calls to include:• Nav Menus• Sidebars (2)• Custom functions I use across multiple themes(like attachments function from earlier)
• As a Child Theme:• Cleaner• Easier to update• Can overwrite any page• As a Boilerplate:• One off jobs you don’t plan on updating• Largely customized jobs where you want toreuse only parts of the framework.2 Ways to Use Framework
As a Child Theme• Allows you to create themes that will automatically getupdated when you update your framework• Bug Fixes• Additional Functionality• General Theme Updates• Overwrites• No need to hack together/delete. Import and overwrite!
As a Boilerplate• Did this for a while!• This project started to serve as a simpleboilerplate for me• Use for one-off projects• Projects you wont have control over after initiallaunch• Projects that will be deeply different structurally
Which Should I Use?• Cliche Answer: It Depends!• As with most things in our field, there is no be-all-end-all answer.• Consider the project at hand and make the callthere.• Practically speaking, a child theme of yourframework will likely work most of the time.
Some Tips• Test it thoroughly• You will use this a lot, so make sure things workas expected across multiple browsers• Improve and update it• As you grow as a developer, your needs willchange. Make sure your framework changes withyou.
Some Tips (cont)• Dont get complacent• Do let your growth stagnate because youre usinga framework.• Stay up on new features, best practices, etc.• Let others try it out• See how other people use it and get feedback.