Skip to content

Commit

Permalink
Fixed a bug which prevented partials in theme from overriding core pa…
Browse files Browse the repository at this point in the history
…rtials
  • Loading branch information
Miika Arponen committed May 25, 2018
1 parent 1db385b commit 7d34e21
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.15.1] - 2018-05-25

### Fixed
- A bug which prevented partials in theme from overriding core partials.

## [1.15.0] - 2018-05-09

### Added
Expand Down
73 changes: 53 additions & 20 deletions dustpress.php
Expand Up @@ -6,7 +6,7 @@
Author: Miika Arponen & Ville Siltala / Geniem Oy
Author URI: http://www.geniem.com
License: GPLv3
Version: 1.15.0
Version: 1.15.1
*/

final class DustPress {
Expand Down Expand Up @@ -68,17 +68,12 @@ protected function __construct() {
// Create a DustPHP instance
$this->dust = new Dust\Dust();

// Set paths for where to look for partials and models
$this->paths = [
get_stylesheet_directory(),
get_template_directory()
];

$this->paths = array_values( array_unique( $this->paths ) );

// Dust template paths will be stored here so the filesystem has to be scanned only once.
$this->templates = [];

$this->add_theme_paths();
$this->add_core_paths();

// Find and include Dust helpers from DustPress plugin
$paths = [
__DIR__ . '/helpers',
Expand Down Expand Up @@ -1521,23 +1516,61 @@ private function register_autoloaders() {
* @return array list of paths to look in
*/
private function get_template_paths( $append ) {
$templatepaths = $this->paths;
$tag = $append ? 'dustpress/' . $append : '';

if ( isset( $append ) ) {
array_walk( $templatepaths, function( &$path ) use ( $append ) {
$path .= DIRECTORY_SEPARATOR . $append;
});
}
$return = apply_filters( $tag, [] );

$templatepaths[] = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $append;
return $return;
}

$tag = $append ? 'dustpress' . DIRECTORY_SEPARATOR . $append : false;
/**
* Add themes to template paths array
*
* @type function
* @date 25/05/2018
* @since 1.15.1
*
* @return void
*/
private function add_theme_paths() {
foreach ( [ 'models', 'partials' ] as $target ) {
add_filter( 'dustpress/' . $target, function( $paths ) use ( $target ) {
// Set paths for where to look for partials and models
$theme_paths = [
get_stylesheet_directory(),
get_template_directory()
];

$theme_paths = array_values( array_unique( $theme_paths ) );

array_walk( $theme_paths, function( &$path ) use ( $target ) {
$path .= DIRECTORY_SEPARATOR . $target;
});

$paths = $theme_paths + $paths;

if ( $tag ) {
$return = apply_filters( $tag, $templatepaths );
return $paths;
}, 1000, 1 );
}
}

return $return;
/**
* Add core path to template paths array
*
* @type function
* @date 25/05/2018
* @since 1.15.1
*
* @return void
*/
private function add_core_paths() {
foreach ( [ 'models', 'partials' ] as $target ) {
add_filter( 'dustpress/' . $target, function( $paths ) use ( $target ) {
$paths[] = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $target;

return $paths;
}, 1, 1 );
}
}

/**
Expand Down

0 comments on commit 7d34e21

Please sign in to comment.