Skip to content

Commit

Permalink
Theme activation updates 'stylesheet' option instead of 'template'
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t committed Nov 7, 2016
1 parent 8c9ba05 commit fb19145
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
17 changes: 8 additions & 9 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
* We do this so that the Template Hierarchy will look in themes/sage/templates for core WordPress themes
* But functions.php, style.css, and index.php are all still located in themes/sage
*
* themes/sage/index.php also contains some self-correcting code, just in case the template option gets reset
* get_template_directory() -> /srv/www/example.com/current/web/app/themes/sage
* 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
*/
add_filter('stylesheet', function ($stylesheet) {
add_filter('template', function ($stylesheet) {
return dirname($stylesheet);
});
add_action('after_switch_theme', function () {
$stylesheet = get_option('stylesheet');
$stylesheet = get_option('template');
if (basename($stylesheet) !== 'templates') {
update_option('stylesheet', $stylesheet . '/templates');
update_option('template', $stylesheet . '/templates');
}
});
add_action('customize_render_section', function ($section) {
if ($section->type === 'themes') {
$section->title = wp_get_theme(basename(__DIR__))->display('Name');
}
}, 10, 2);

/**
* Sage includes
Expand Down
5 changes: 1 addition & 4 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?php

if (defined('ABSPATH')) {
update_option('template', get_option('template') . '/templates');
}
die("Kind Regards,\nRoots");
include __DIR__ . '/templates/index.php';
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function template_part($template, array $context = [], $layout = 'base')
function asset_path($filename)
{
static $manifest;
isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json');
isset($manifest) || $manifest = new JsonManifest(get_stylesheet_directory() . '/' . Asset::$dist . '/assets.json');
return (string) new Asset($filename, $manifest);
}

Expand Down

0 comments on commit fb19145

Please sign in to comment.