I experienced a conflict between Sage and a WPML and WooCommerce combination, where a translated product archive (specificly product_cat taxonomy page) wouldn't be wrapped in the base template. Just the template file contents would be executed without the master/base template. This could be solved by changeing the priority of the template_include filter for the wrapper to >100. I'm not sure if this is WooCommerce specific or if this would be the case for any translated taxonomy when using WPML.
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Roots\Sage\Wrapper;
|
|
|
|
/**
|
|
* Theme wrapper
|
|
*
|
|
* @link https://roots.io/sage/docs/theme-wrapper/
|
|
* @link http://scribu.net/wordpress/theme-wrappers.html
|
|
*/
|
|
|
|
function template_path() {
|
|
return SageWrapping::$main_template;
|
|
}
|
|
|
|
function sidebar_path() {
|
|
return new SageWrapping('templates/sidebar.php');
|
|
}
|
|
|
|
class SageWrapping {
|
|
// Stores the full path to the main template file
|
|
public static $main_template;
|
|
|
|
// Basename of template file
|
|
public $slug;
|
|
|
|
// Array of templates
|
|
public $templates;
|
|
|
|
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
|
public static $base;
|
|
|
|
public function __construct($template = 'base.php') {
|
|
$this->slug = basename($template, '.php');
|
|
$this->templates = [$template];
|
|
|
|
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('sage/wrap_' . $this->slug, $this->templates);
|
|
return locate_template($this->templates);
|
|
}
|
|
|
|
public static function wrap($main) {
|
|
// Check for other filters returning null
|
|
if (!is_string($main)) {
|
|
return $main;
|
|
}
|
|
|
|
self::$main_template = $main;
|
|
self::$base = basename(self::$main_template, '.php');
|
|
|
|
if (self::$base === 'index') {
|
|
self::$base = false;
|
|
}
|
|
|
|
return new SageWrapping();
|
|
}
|
|
}
|
|
add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 109);
|