templates/ -> resources/views/

This commit is contained in:
Ben Word
2017-04-03 18:26:26 -06:00
parent 0fab46fe14
commit 700a556c02
25 changed files with 41 additions and 38 deletions

View File

@@ -60,10 +60,10 @@ array_map(function ($file) use ($sage_error) {
/**
* Here's what's happening with these hooks:
* 1. WordPress initially detects theme in themes/sage
* 2. Upon activation, we tell WordPress that the theme is actually in themes/sage/templates
* 2. Upon activation, we tell WordPress that the theme is actually in themes/sage/resources/views
* 3. When we call get_template_directory() or get_template_directory_uri(), we point it back to themes/sage
*
* We do this so that the Template Hierarchy will look in themes/sage/templates for core WordPress themes
* We do this so that the Template Hierarchy will look in themes/sage/resources/views for core WordPress themes
* But functions.php, style.css, and index.php are all still located in themes/sage
*
* This is not compatible with the WordPress Customizer theme preview prior to theme activation
@@ -72,16 +72,16 @@ array_map(function ($file) use ($sage_error) {
* get_stylesheet_directory() -> /srv/www/example.com/current/web/app/themes/sage
* locate_template()
* ├── STYLESHEETPATH -> /srv/www/example.com/current/web/app/themes/sage
* └── TEMPLATEPATH -> /srv/www/example.com/current/web/app/themes/sage/templates
* └── TEMPLATEPATH -> /srv/www/example.com/current/web/app/themes/sage/resources/views
*/
if (is_customize_preview() && isset($_GET['theme'])) {
$sage_error(__('Theme must be activated prior to using the customizer.', 'sage'));
}
add_filter('template', function ($stylesheet) {
return dirname($stylesheet);
return dirname(dirname($stylesheet));
});
if (basename($stylesheet = get_option('template')) !== 'templates') {
update_option('template', "{$stylesheet}/templates");
if (basename($stylesheet = get_option('template')) !== 'resources/views') {
update_option('template', "{$stylesheet}/resources/views");
wp_redirect($_SERVER['REQUEST_URI']);
exit();
}