-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTheme.php
More file actions
118 lines (88 loc) · 2.35 KB
/
Theme.php
File metadata and controls
118 lines (88 loc) · 2.35 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?
namespace cw\wp;
class Theme{
use \cw\php\core\traits\Singleton;
public $header='';
public $footer='';
public function touchAfterPostUpdated($file = 'functions.php'){
if(!is_admin())
return $this;
$file = get_stylesheet_directory() . '/' . $file;
add_action( 'post_updated', function() use($file){
touch($file);
}, 10, 3 );
return $this;
}
public function addSupport($feature, $args=null){
add_action( 'after_setup_theme', function() use($feature, $args){
add_theme_support($feature, $args);
});
return $this;
}
public function loadTextDomain($key, $src){
add_action( 'after_setup_theme', function() use($key, $src){
load_theme_textdomain($key, $src);
});
return $this;
}
public function addBodyClass($class){
add_filter( 'body_class', function($classes) use($class){
if(is_callable($class))
$class = $class();
if($class)
$classes[] = $class;
return $classes;
} );
return $this;
}
public function conditional($action, $callable){
add_action($action, function() use($callable){
call_user_func($callable, $this);
});
return $this;
}
function addFooterContent($input) {
add_action( 'wp_footer', function() use($input){
if(is_callable($input))
echo $input();
else
echo $input;
}, 101 );
return $this;
}
function addFooterContentJs($input) {
$input = new \cw\php\js\expression\Wrapper($input);
return $this->addFooterContent($input);
}
function addHeaderContent($input) {
add_action( 'wp_head', function() use($input){
echo $input;
}, 101 );
return $this;
}
function addHeaderContentJs($input) {
$input = new \cw\php\js\expression\Wrapper($input);
return $this->addHeaderContent($input);
}
public function pageTemplate(){
return get_query_template('page');
}
public function postTemplate(){
return get_query_template('single');
}
public function parentTemplate($which){
return get_template_directory() . '/' .$which;
}
public function header($header=null){
if($header === null)
return $this->header;
$this->header = $header;
return $this;
}
public function footer($footer=null){
if($footer === null)
return $this->footer;
$this->footer = $footer;
return $this;
}
}