Move theme wrapper into separate file

This commit is contained in:
Ben Word
2013-06-23 12:15:08 -05:00
parent ccb79488c9
commit 4aa4be182b
3 changed files with 53 additions and 52 deletions

52
lib/wrapper.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
/**
* Theme wrapper
*
* @link http://scribu.net/wordpress/theme-wrappers.html
*/
function roots_template_path() {
return Roots_Wrapping::$main_template;
}
function roots_sidebar_path() {
return Roots_Wrapping::sidebar();
}
class Roots_Wrapping {
// Stores the full path to the main template file
static $main_template;
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
static $base;
static function wrap($template) {
self::$main_template = $template;
self::$base = substr(basename(self::$main_template), 0, -4);
if (self::$base === 'index') {
self::$base = false;
}
$templates = array('base.php');
if (self::$base) {
array_unshift($templates, sprintf('base-%s.php', self::$base));
}
$templates = apply_filters('roots_wrap_base', $templates);
return locate_template($templates);
}
static function sidebar() {
$templates = array('templates/sidebar.php');
if (self::$base) {
array_unshift($templates, sprintf('templates/sidebar-%s.php', self::$base));
}
$templates = apply_filters('roots_wrap_sidebar', $templates);
return locate_template($templates);
}
}
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);