|
6 | 6 | Author: Miika Arponen & Ville Siltala / Geniem Oy
|
7 | 7 | Author URI: http://www.geniem.com
|
8 | 8 | License: GPLv3
|
9 |
| -Version: 1.15.0 |
| 9 | +Version: 1.15.1 |
10 | 10 | */
|
11 | 11 |
|
12 | 12 | final class DustPress {
|
@@ -68,17 +68,12 @@ protected function __construct() {
|
68 | 68 | // Create a DustPHP instance
|
69 | 69 | $this->dust = new Dust\Dust();
|
70 | 70 |
|
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 |
| - |
79 | 71 | // Dust template paths will be stored here so the filesystem has to be scanned only once.
|
80 | 72 | $this->templates = [];
|
81 | 73 |
|
| 74 | + $this->add_theme_paths(); |
| 75 | + $this->add_core_paths(); |
| 76 | + |
82 | 77 | // Find and include Dust helpers from DustPress plugin
|
83 | 78 | $paths = [
|
84 | 79 | __DIR__ . '/helpers',
|
@@ -1521,23 +1516,61 @@ private function register_autoloaders() {
|
1521 | 1516 | * @return array list of paths to look in
|
1522 | 1517 | */
|
1523 | 1518 | private function get_template_paths( $append ) {
|
1524 |
| - $templatepaths = $this->paths; |
| 1519 | + $tag = $append ? 'dustpress/' . $append : ''; |
1525 | 1520 |
|
1526 |
| - if ( isset( $append ) ) { |
1527 |
| - array_walk( $templatepaths, function( &$path ) use ( $append ) { |
1528 |
| - $path .= DIRECTORY_SEPARATOR . $append; |
1529 |
| - }); |
1530 |
| - } |
| 1521 | + $return = apply_filters( $tag, [] ); |
1531 | 1522 |
|
1532 |
| - $templatepaths[] = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $append; |
| 1523 | + return $return; |
| 1524 | + } |
1533 | 1525 |
|
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; |
1535 | 1551 |
|
1536 |
| - if ( $tag ) { |
1537 |
| - $return = apply_filters( $tag, $templatepaths ); |
| 1552 | + return $paths; |
| 1553 | + }, 1000, 1 ); |
1538 | 1554 | }
|
| 1555 | + } |
1539 | 1556 |
|
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 | + } |
1541 | 1574 | }
|
1542 | 1575 |
|
1543 | 1576 | /**
|
|
0 commit comments