retlehs/roots — pull request #179 by mwrather (2011-11-26 08:08:41+00:00)
Title: Get the best of both worlds: require_once and locate_template

A while back, all the template files included at the beginning of `functions.php` were switched to the format

```locate_template('inc/roots-somefile.php', true, true);```

so that child themes could override them. This fit neatly into my theme development workflow, since I could override what I needed in the `childtheme/inc/` directory, and I didn't have to worry about merging changes from upstream into my customized child theme.

In retlehs/roots@0d537df73e587e070f04fb98a91507888942ac8b the method was reverted to require_once because of "unexpected behavior" -- I'm guessing that `locate_template()` has problems with variable scope.

But can't we have the best of both worlds? `locate_template()` doesn't have to be used to actually include the php script; the default behavior is search `STYLESHEETPATH` and then `TEMPLATEPATH` for a script and return the filename as a string. One could format all the statements in the form:

```require_once locate_template('inc/roots-somefile.php');```

and both have predictable variable scope *and* make it easy to override files.

Credit for the idea: http://wordpress.stackexchange.com/questions/4462/passing-variables-through-locate-template