WordPress Template System Override
|Reported by:||pearsonified||Owned by:|
|Severity:||normal||Keywords:||has-patch 2nd-opinion close|
As it's currently constructed (in version 3.0.4), the WordPress template loader (wp-includes/template-loader.php) is relatively inflexible. No matter how a theme operates, it's forced through the series of if-statements and template "fetches" defined in lines 23–41 of template-loader.php.
Fortunately, by making very simple modifications to this file, we can accommodate themes/frameworks/template systems that may have different (and, ideally, more efficient) ways of determining which template to show and how to show it.
This is sensible because developers only need the contents of $wp_query in order to determine which template to show. While the current workings of the WP template system include a lot of "convenience" functions, these unnecessary function calls could be skipped entirely by relying upon the $wp_query->is_[x] variables.
My proposal for a template system override is quite simple, and it introduces one new constant and one new hook into the core. The constant, WP_THEME_TEMPLATE, is a boolean value that theme developers should place in their functions.php file and set to TRUE only if they have defined their own template system. The hook, theme_template, is the "tie-in" point for the developer's template system.
The template-loader.php file must be modified to accommodate the constant and hook described above. Fortunately, this can be done in 4 lines of code, as evidenced by (new) lines 22–24 and line 48 in the attached template-loader.php file.
I like this template system solution because it does not affect any current themes, developers, or development practices. Despite this, it opens to door to innovation and places the dev community in a position to come up with mind-blowing new ways to handle template/theme functionality.
Change History (18)
- Keywords has-patch 2nd-opinion added; themes templates removed
- Milestone changed from Awaiting Review to Future Release
- Type changed from enhancement to feature request
comment:12 follow-up: ↓ 13 nacin — 3 years ago
- Milestone Future Release deleted
- Resolution set to worksforme
- Status changed from new to closed