Rework Roots_Wrapping class
Apply the wrapper to any template by creating a new instance.
This commit is contained in:
@@ -9,7 +9,7 @@ function roots_template_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function roots_sidebar_path() {
|
function roots_sidebar_path() {
|
||||||
return Roots_Wrapping::sidebar();
|
return Roots_Wrapping('templates/sidebar.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
class Roots_Wrapping {
|
class Roots_Wrapping {
|
||||||
@@ -19,34 +19,30 @@ class Roots_Wrapping {
|
|||||||
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
||||||
static $base;
|
static $base;
|
||||||
|
|
||||||
static function wrap($template) {
|
public function __construct($template='base.php') {
|
||||||
self::$main_template = $template;
|
$this->slug = basename($template, '.php');
|
||||||
|
$this->templates = array($template);
|
||||||
self::$base = substr(basename(self::$main_template), 0, -4);
|
|
||||||
|
if (self::$base) {
|
||||||
|
$str = substr($template, 0, -4);
|
||||||
|
array_unshift($this->templates, sprintf($str . '-%s.php', self::$base));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString() {
|
||||||
|
$this->templates = apply_filters('roots_wrap_' . $this->slug, $this->templates);
|
||||||
|
return locate_template($this->templates);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function wrap($main) {
|
||||||
|
self::$main_template = $main;
|
||||||
|
self::$base = basename(self::$main_template, '.php');
|
||||||
|
|
||||||
if (self::$base === 'index') {
|
if (self::$base === 'index') {
|
||||||
self::$base = false;
|
self::$base = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$templates = array('base.php');
|
return new Roots_Wrapping();
|
||||||
|
|
||||||
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);
|
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);
|
||||||
|
|||||||
Reference in New Issue
Block a user