Skip to content

Commit 7d34e21

Browse files
author
Miika Arponen
committed
Fixed a bug which prevented partials in theme from overriding core partials
1 parent 1db385b commit 7d34e21

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [1.15.1] - 2018-05-25
8+
9+
### Fixed
10+
- A bug which prevented partials in theme from overriding core partials.
11+
712
## [1.15.0] - 2018-05-09
813

914
### Added

dustpress.php

+53-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Author: Miika Arponen & Ville Siltala / Geniem Oy
77
Author URI: http://www.geniem.com
88
License: GPLv3
9-
Version: 1.15.0
9+
Version: 1.15.1
1010
*/
1111

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

71-
// Set paths for where to look for partials and models
72-
$this->paths = [
73-
get_stylesheet_directory(),
74-
get_template_directory()
75-
];
76-
77-
$this->paths = array_values( array_unique( $this->paths ) );
78-
7971
// Dust template paths will be stored here so the filesystem has to be scanned only once.
8072
$this->templates = [];
8173

74+
$this->add_theme_paths();
75+
$this->add_core_paths();
76+
8277
// Find and include Dust helpers from DustPress plugin
8378
$paths = [
8479
__DIR__ . '/helpers',
@@ -1521,23 +1516,61 @@ private function register_autoloaders() {
15211516
* @return array list of paths to look in
15221517
*/
15231518
private function get_template_paths( $append ) {
1524-
$templatepaths = $this->paths;
1519+
$tag = $append ? 'dustpress/' . $append : '';
15251520

1526-
if ( isset( $append ) ) {
1527-
array_walk( $templatepaths, function( &$path ) use ( $append ) {
1528-
$path .= DIRECTORY_SEPARATOR . $append;
1529-
});
1530-
}
1521+
$return = apply_filters( $tag, [] );
15311522

1532-
$templatepaths[] = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $append;
1523+
return $return;
1524+
}
15331525

1534-
$tag = $append ? 'dustpress' . DIRECTORY_SEPARATOR . $append : false;
1526+
/**
1527+
* Add themes to template paths array
1528+
*
1529+
* @type function
1530+
* @date 25/05/2018
1531+
* @since 1.15.1
1532+
*
1533+
* @return void
1534+
*/
1535+
private function add_theme_paths() {
1536+
foreach ( [ 'models', 'partials' ] as $target ) {
1537+
add_filter( 'dustpress/' . $target, function( $paths ) use ( $target ) {
1538+
// Set paths for where to look for partials and models
1539+
$theme_paths = [
1540+
get_stylesheet_directory(),
1541+
get_template_directory()
1542+
];
1543+
1544+
$theme_paths = array_values( array_unique( $theme_paths ) );
1545+
1546+
array_walk( $theme_paths, function( &$path ) use ( $target ) {
1547+
$path .= DIRECTORY_SEPARATOR . $target;
1548+
});
1549+
1550+
$paths = $theme_paths + $paths;
15351551

1536-
if ( $tag ) {
1537-
$return = apply_filters( $tag, $templatepaths );
1552+
return $paths;
1553+
}, 1000, 1 );
15381554
}
1555+
}
15391556

1540-
return $return;
1557+
/**
1558+
* Add core path to template paths array
1559+
*
1560+
* @type function
1561+
* @date 25/05/2018
1562+
* @since 1.15.1
1563+
*
1564+
* @return void
1565+
*/
1566+
private function add_core_paths() {
1567+
foreach ( [ 'models', 'partials' ] as $target ) {
1568+
add_filter( 'dustpress/' . $target, function( $paths ) use ( $target ) {
1569+
$paths[] = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $target;
1570+
1571+
return $paths;
1572+
}, 1, 1 );
1573+
}
15411574
}
15421575

15431576
/**

0 commit comments

Comments
 (0)