forked from zamoose/themehookalliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tha-theme-hooks.php
264 lines (228 loc) · 5.6 KB
/
tha-theme-hooks.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
/**
* Theme Hook Alliance hook stub list.
*
* @package themehookalliance
* @version 1.0-draft
* @since 1.0-draft
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/**
* Define the version of THA support, in case that becomes useful down the road.
*/
define( 'THA_HOOKS_VERSION', '1.0-draft' );
/**
* Themes and Plugins can check for tha_hooks using current_theme_supports( 'tha_hooks', $hook )
* to determine whether a theme declares itself to support this specific hook type.
*
* Example:
* <code>
* // Declare support for all hook types
* add_theme_support( 'tha_hooks', array( 'all' ) );
*
* // Declare support for certain hook types only
* add_theme_support( 'tha_hooks', array( 'header', 'content', 'footer' ) );
* </code>
*/
add_theme_support( 'tha_hooks', array(
/**
* As a Theme developer, use the 'all' parameter, to declare support for all
* hook types.
* Please make sure you then actually reference all the hooks in this file,
* Plugin developers depend on it!
*/
'all',
/**
* Themes can also choose to only support certain hook types.
* Please make sure you then actually reference all the hooks in this type
* family.
*
* When the 'all' parameter was set, specific hook types do not need to be
* added explicitly.
*/
'html',
'body',
'head',
'header',
'content',
'entry',
'comments',
'sidebars',
'sidebar',
'footer',
/**
* If/when WordPress Core implements similar methodology, Themes and Plugins
* will be able to check whether the version of THA supplied by the theme
* supports Core hooks.
*/
//'core',
) );
/**
* Determines, whether the specific hook type is actually supported.
*
* Plugin developers should always check for the support of a <strong>specific</strong>
* hook type before hooking a callback function to a hook of this type.
*
* Example:
* <code>
* if ( current_theme_supports( 'tha_hooks', 'header' ) )
* add_action( 'tha_head_top', 'prefix_header_top' );
* </code>
*
* @param bool $bool true
* @param array $args The hook type being checked
* @param array $registered All registered hook types
*
* @return bool
*/
function tha_current_theme_supports( $bool, $args, $registered ) {
return in_array( $args[0], $registered[0] ) || in_array( 'all', $registered[0] );
}
add_filter( 'current_theme_supports-tha_hooks', 'tha_current_theme_supports', 10, 3 );
/**
* HTML <html> hook
* Special case, useful for <DOCTYPE>, etc.
* $tha_supports[] = 'html;
*/
function tha_html_before() {
do_action( 'tha_html_before' );
}
/**
* HTML <body> hooks
* $tha_supports[] = 'body';
*/
function tha_body_top() {
do_action( 'tha_body_top' );
}
function tha_body_bottom() {
do_action( 'tha_body_bottom' );
}
/**
* HTML <head> hooks
*
* $tha_supports[] = 'head';
*/
function tha_head_top() {
do_action( 'tha_head_top' );
}
function tha_head_bottom() {
do_action( 'tha_head_bottom' );
}
/**
* Semantic <header> hooks
*
* $tha_supports[] = 'header';
*/
function tha_header_before() {
do_action( 'tha_header_before' );
}
function tha_header_after() {
do_action( 'tha_header_after' );
}
function tha_header_top() {
do_action( 'tha_header_top' );
}
function tha_header_bottom() {
do_action( 'tha_header_bottom' );
}
/**
* Semantic <content> hooks
*
* $tha_supports[] = 'content';
*/
function tha_content_before() {
do_action( 'tha_content_before' );
}
function tha_content_after() {
do_action( 'tha_content_after' );
}
function tha_content_top() {
do_action( 'tha_content_top' );
}
function tha_content_bottom() {
do_action( 'tha_content_bottom' );
}
function tha_content_while_before() {
do_action( 'tha_content_while_before' );
}
function tha_content_while_after() {
do_action( 'tha_content_while_after' );
}
/**
* Semantic <entry> hooks
*
* $tha_supports[] = 'entry';
*/
function tha_entry_before() {
do_action( 'tha_entry_before' );
}
function tha_entry_after() {
do_action( 'tha_entry_after' );
}
function tha_entry_content_before() {
do_action( 'tha_entry_content_before' );
}
function tha_entry_content_after() {
do_action( 'tha_entry_content_after' );
}
function tha_entry_top() {
do_action( 'tha_entry_top' );
}
function tha_entry_bottom() {
do_action( 'tha_entry_bottom' );
}
/**
* Comments block hooks
*
* $tha_supports[] = 'comments';
*/
function tha_comments_before() {
do_action( 'tha_comments_before' );
}
function tha_comments_after() {
do_action( 'tha_comments_after' );
}
/**
* Semantic <sidebar> hooks
*
* $tha_supports[] = 'sidebar';
*/
function tha_sidebars_before() {
do_action( 'tha_sidebars_before' );
}
function tha_sidebars_after() {
do_action( 'tha_sidebars_after' );
}
function tha_sidebar_top() {
do_action( 'tha_sidebar_top' );
}
function tha_sidebar_bottom() {
do_action( 'tha_sidebar_bottom' );
}
/**
* Semantic <footer> hooks
*
* $tha_supports[] = 'footer';
*/
function tha_footer_before() {
do_action( 'tha_footer_before' );
}
function tha_footer_after() {
do_action( 'tha_footer_after' );
}
function tha_footer_top() {
do_action( 'tha_footer_top' );
}
function tha_footer_bottom() {
do_action( 'tha_footer_bottom' );
}