-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateLoader.php
62 lines (51 loc) · 1.18 KB
/
TemplateLoader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
defined( 'ABSPATH' ) || exit;
/**
* Class TemplateLoader
* @package WPFactory\DeliveryTime
*/
class TemplateLoader {
/**
* Instance to call certain functions globally within the plugin.
*
* @var instance
*/
protected static $instance = null;
/**
* Ensures only one instance is loaded or can be loaded.
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Loads a template.
* @param string $template_name
* @param array $args
* @param string $template_path
* @param bool $echo
*
*/
public function get_template( $template_name, $args = array(), $template_path, $echo = false ) {
$output = null;
if(empty($args)) {
$args = array();
}
$template_path = $template_path . $template_name;
if ( file_exists( $template_path ) ) {
extract( $args ); // @codingStandardsIgnoreLine required for template.
ob_start();
include $template_path;
$output = ob_get_clean();
} else {
throw new \Exception( __( 'Specified path does not exist', 'dtw-customization' ) );
}
if ( $echo ) {
print $output;
} else {
return $output;
}
}
}