forked from wp-media/template-loader-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.php
43 lines (35 loc) · 791 Bytes
/
Loader.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
<?php
namespace WPMedia\TemplateLoader;
class Loader {
/**
* The directory for custom templates.
*
* @var string template_dir
*/
private $template_dir;
/**
* Loader constructor.
*
* @param string $template_dir The directory for custom templates.
*/
public function __construct( $template_dir ) {
$this->template_dir = $template_dir;
}
/**
* Load a custom template.
*
* @since 1.0
*
* @param string $template The current WP Template path.
*
* @return string Path to the custom template to load instead.
*/
public function load_template( $template ) {
global $post;
$test_template = get_post_meta( $post->ID, '_test_template', true );
if ( ! $test_template ) {
return $template;
}
return $this->template_dir . $test_template;
}
}