Move required theme files to sage/resources
* Resolves issue with WP only looking one-level deep for templates #1870 * get_template_dir() and related functions now point to sage/resources * Use collect() when assembling views paths * Update tree in README
This commit is contained in:
@@ -6,19 +6,24 @@ namespace App;
|
||||
* Add <body> classes
|
||||
*/
|
||||
add_filter('body_class', function (array $classes) {
|
||||
// Add page slug if it doesn't exist
|
||||
/** Add page slug if it doesn't exist */
|
||||
if (is_single() || is_page() && !is_front_page()) {
|
||||
if (!in_array(basename(get_permalink()), $classes)) {
|
||||
$classes[] = basename(get_permalink());
|
||||
}
|
||||
}
|
||||
|
||||
// Add class if sidebar is active
|
||||
/** Add class if sidebar is active */
|
||||
if (display_sidebar()) {
|
||||
$classes[] = 'sidebar-primary';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
/** Clean up class names for custom templates */
|
||||
$classes = array_map(function ($class) {
|
||||
return preg_replace(['/-blade(-php)?$/', '/^page-template-views/'], '', $class);
|
||||
}, $classes);
|
||||
|
||||
return array_filter($classes);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -31,31 +36,30 @@ add_filter('excerpt_more', function () {
|
||||
/**
|
||||
* Template Hierarchy should search for .blade.php files
|
||||
*/
|
||||
array_map(function ($type) {
|
||||
collect([
|
||||
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
|
||||
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
|
||||
])->map(function ($type) {
|
||||
add_filter("{$type}_template_hierarchy", function ($templates) {
|
||||
return call_user_func_array('array_merge', array_map(function ($template) {
|
||||
return collect($templates)->flatMap(function ($template) {
|
||||
$transforms = [
|
||||
'%^/?(resources/views)?/?%' => config('sage.disable_option_hack') ? 'resources/views/' : '',
|
||||
'%^/?(resources[\\/]views)?[\\/]?%' => '',
|
||||
'%(\.blade)?(\.php)?$%' => ''
|
||||
];
|
||||
$normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template);
|
||||
return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"];
|
||||
}, $templates));
|
||||
})->toArray();
|
||||
});
|
||||
}, [
|
||||
'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home',
|
||||
'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment'
|
||||
]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Render page using Blade
|
||||
*/
|
||||
add_filter('template_include', function ($template) {
|
||||
$data = array_reduce(get_body_class(), function ($data, $class) use ($template) {
|
||||
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
|
||||
return apply_filters("sage/template/{$class}/data", $data, $template);
|
||||
}, []);
|
||||
echo template($template, $data);
|
||||
|
||||
// Return a blank file to make WordPress happy
|
||||
return get_theme_file_path('index.php');
|
||||
}, PHP_INT_MAX);
|
||||
|
||||
Reference in New Issue
Block a user