-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathviews.php
More file actions
49 lines (34 loc) · 951 Bytes
/
views.php
File metadata and controls
49 lines (34 loc) · 951 Bytes
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
<?php
class SimTermView
{
public static function render($slug, $variables=array(), $name = null)
{
global $wp_query;
$template = self::searchTemplate($slug, $name);
if ( is_array( $wp_query->query_vars ) )
{
extract( $wp_query->query_vars, EXTR_SKIP );
}
extract($variables);
ob_start();
if ( $template )
require( $template ); /* load_template just requires or require_once the file extracting wp_query vars */
return ob_get_clean();
}
private static function searchTemplate($slug, $name)
{
$templateNames = array();
$path = plugin_dir_path(__FILE__).'/views/';
if (isset($name))
$templateNames[] = "{$slug}-{$name}.php";
$templateNames[] = "{$slug}.php";
foreach ( (array) $templateNames as $template )
{
if (!$template)
continue;
if (file_exists($path . '/' . $template))
return $path . '/' . $template;
}
return false;
}
};