author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Template loading functions. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Retrieve path to a template |
|
11 |
* |
|
12 |
* Used to quickly retrieve the path of a template without including the file |
|
13 |
* extension. It will also check the parent theme, if the file exists, with |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* the use of locate_template(). Allows for more generic template location |
0 | 15 |
* without the use of the other get_*_template() functions. |
16 |
* |
|
17 |
* @since 1.5.0 |
|
18 |
* |
|
18 | 19 |
* @param string $type Filename without extension. |
20 |
* @param string[] $templates An optional list of template candidates. |
|
5 | 21 |
* @return string Full path to template file. |
0 | 22 |
*/ |
23 |
function get_query_template( $type, $templates = array() ) { |
|
24 |
$type = preg_replace( '|[^a-z0-9-]+|', '', $type ); |
|
25 |
||
9 | 26 |
if ( empty( $templates ) ) { |
27 |
$templates = array( "{$type}.php" ); |
|
28 |
} |
|
0 | 29 |
|
30 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* Filters the list of template filenames that are searched for when retrieving a template to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* |
18 | 33 |
* The dynamic portion of the hook name, `$type`, refers to the filename -- minus the file |
34 |
* extension and any non-alphanumeric characters delimiting words -- of the file to load. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* The last element in the array should always be the fallback template for this query type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* |
18 | 37 |
* Possible hook names include: |
38 |
* |
|
39 |
* - `404_template_hierarchy` |
|
40 |
* - `archive_template_hierarchy` |
|
41 |
* - `attachment_template_hierarchy` |
|
42 |
* - `author_template_hierarchy` |
|
43 |
* - `category_template_hierarchy` |
|
44 |
* - `date_template_hierarchy` |
|
45 |
* - `embed_template_hierarchy` |
|
46 |
* - `frontpage_template_hierarchy` |
|
47 |
* - `home_template_hierarchy` |
|
48 |
* - `index_template_hierarchy` |
|
49 |
* - `page_template_hierarchy` |
|
50 |
* - `paged_template_hierarchy` |
|
51 |
* - `privacypolicy_template_hierarchy` |
|
52 |
* - `search_template_hierarchy` |
|
53 |
* - `single_template_hierarchy` |
|
54 |
* - `singular_template_hierarchy` |
|
55 |
* - `tag_template_hierarchy` |
|
56 |
* - `taxonomy_template_hierarchy` |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* @since 4.7.0 |
0 | 59 |
* |
18 | 60 |
* @param string[] $templates A list of template candidates, in descending order of priority. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
$templates = apply_filters( "{$type}_template_hierarchy", $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
$template = locate_template( $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
|
18 | 66 |
$template = locate_block_template( $template, $type, $templates ); |
67 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* Filters the path of the queried template by type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* The dynamic portion of the hook name, `$type`, refers to the filename -- minus the file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* extension and any non-alphanumeric characters delimiting words -- of the file to load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* This hook also applies to various types of files loaded as part of the Template Hierarchy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* |
18 | 75 |
* Possible hook names include: |
76 |
* |
|
77 |
* - `404_template` |
|
78 |
* - `archive_template` |
|
79 |
* - `attachment_template` |
|
80 |
* - `author_template` |
|
81 |
* - `category_template` |
|
82 |
* - `date_template` |
|
83 |
* - `embed_template` |
|
84 |
* - `frontpage_template` |
|
85 |
* - `home_template` |
|
86 |
* - `index_template` |
|
87 |
* - `page_template` |
|
88 |
* - `paged_template` |
|
89 |
* - `privacypolicy_template` |
|
90 |
* - `search_template` |
|
91 |
* - `single_template` |
|
92 |
* - `singular_template` |
|
93 |
* - `tag_template` |
|
94 |
* - `taxonomy_template` |
|
0 | 95 |
* |
5 | 96 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* @since 4.8.0 The `$type` and `$templates` parameters were added. |
0 | 98 |
* |
18 | 99 |
* @param string $template Path to the template. See locate_template(). |
100 |
* @param string $type Sanitized filename without extension. |
|
101 |
* @param string[] $templates A list of template candidates, in descending order of priority. |
|
0 | 102 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
return apply_filters( "{$type}_template", $template, $type, $templates ); |
0 | 104 |
} |
105 |
||
106 |
/** |
|
107 |
* Retrieve path of index template in current or parent template. |
|
108 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'index'. |
5 | 111 |
* |
0 | 112 |
* @since 3.0.0 |
113 |
* |
|
5 | 114 |
* @see get_query_template() |
115 |
* |
|
116 |
* @return string Full path to index template file. |
|
0 | 117 |
*/ |
118 |
function get_index_template() { |
|
9 | 119 |
return get_query_template( 'index' ); |
0 | 120 |
} |
121 |
||
122 |
/** |
|
123 |
* Retrieve path of 404 template in current or parent template. |
|
124 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* and {@see '$type_template'} dynamic hooks, where `$type` is '404'. |
5 | 127 |
* |
0 | 128 |
* @since 1.5.0 |
129 |
* |
|
5 | 130 |
* @see get_query_template() |
131 |
* |
|
132 |
* @return string Full path to 404 template file. |
|
0 | 133 |
*/ |
134 |
function get_404_template() { |
|
9 | 135 |
return get_query_template( '404' ); |
0 | 136 |
} |
137 |
||
138 |
/** |
|
139 |
* Retrieve path of archive template in current or parent template. |
|
140 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'archive'. |
5 | 143 |
* |
0 | 144 |
* @since 1.5.0 |
145 |
* |
|
5 | 146 |
* @see get_query_template() |
147 |
* |
|
148 |
* @return string Full path to archive template file. |
|
0 | 149 |
*/ |
150 |
function get_archive_template() { |
|
151 |
$post_types = array_filter( (array) get_query_var( 'post_type' ) ); |
|
152 |
||
153 |
$templates = array(); |
|
154 |
||
155 |
if ( count( $post_types ) == 1 ) { |
|
9 | 156 |
$post_type = reset( $post_types ); |
0 | 157 |
$templates[] = "archive-{$post_type}.php"; |
158 |
} |
|
159 |
$templates[] = 'archive.php'; |
|
160 |
||
161 |
return get_query_template( 'archive', $templates ); |
|
162 |
} |
|
163 |
||
164 |
/** |
|
165 |
* Retrieve path of post type archive template in current or parent template. |
|
166 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'archive'. |
5 | 169 |
* |
0 | 170 |
* @since 3.7.0 |
171 |
* |
|
5 | 172 |
* @see get_archive_template() |
173 |
* |
|
174 |
* @return string Full path to archive template file. |
|
0 | 175 |
*/ |
176 |
function get_post_type_archive_template() { |
|
177 |
$post_type = get_query_var( 'post_type' ); |
|
9 | 178 |
if ( is_array( $post_type ) ) { |
0 | 179 |
$post_type = reset( $post_type ); |
9 | 180 |
} |
0 | 181 |
|
182 |
$obj = get_post_type_object( $post_type ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) { |
0 | 184 |
return ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} |
0 | 186 |
|
187 |
return get_archive_template(); |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* Retrieve path of author template in current or parent template. |
|
192 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* 1. author-{nicename}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* 2. author-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* 3. author.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
* 1. author-john.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* 2. author-1.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* 3. author.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'author'. |
5 | 207 |
* |
0 | 208 |
* @since 1.5.0 |
209 |
* |
|
5 | 210 |
* @see get_query_template() |
211 |
* |
|
212 |
* @return string Full path to author template file. |
|
0 | 213 |
*/ |
214 |
function get_author_template() { |
|
215 |
$author = get_queried_object(); |
|
216 |
||
217 |
$templates = array(); |
|
218 |
||
5 | 219 |
if ( $author instanceof WP_User ) { |
0 | 220 |
$templates[] = "author-{$author->user_nicename}.php"; |
221 |
$templates[] = "author-{$author->ID}.php"; |
|
222 |
} |
|
223 |
$templates[] = 'author.php'; |
|
224 |
||
225 |
return get_query_template( 'author', $templates ); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Retrieve path of category template in current or parent template. |
|
230 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
* 1. category-{slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
* 2. category-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* 3. category.php |
0 | 236 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* 1. category-news.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* 2. category-2.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* 3. category.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'category'. |
5 | 245 |
* |
0 | 246 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* @since 4.7.0 The decoded form of `category-{slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* template hierarchy when the category slug contains multibyte characters. |
0 | 249 |
* |
5 | 250 |
* @see get_query_template() |
251 |
* |
|
252 |
* @return string Full path to category template file. |
|
0 | 253 |
*/ |
254 |
function get_category_template() { |
|
255 |
$category = get_queried_object(); |
|
256 |
||
257 |
$templates = array(); |
|
258 |
||
259 |
if ( ! empty( $category->slug ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
$slug_decoded = urldecode( $category->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
if ( $slug_decoded !== $category->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
$templates[] = "category-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
0 | 266 |
$templates[] = "category-{$category->slug}.php"; |
267 |
$templates[] = "category-{$category->term_id}.php"; |
|
268 |
} |
|
269 |
$templates[] = 'category.php'; |
|
270 |
||
271 |
return get_query_template( 'category', $templates ); |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Retrieve path of tag template in current or parent template. |
|
276 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* 1. tag-{slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
* 2. tag-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
* 3. tag.php |
0 | 282 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* 1. tag-wordpress.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
* 2. tag-3.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* 3. tag.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'tag'. |
5 | 291 |
* |
0 | 292 |
* @since 2.3.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
* @since 4.7.0 The decoded form of `tag-{slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
* template hierarchy when the tag slug contains multibyte characters. |
0 | 295 |
* |
5 | 296 |
* @see get_query_template() |
297 |
* |
|
298 |
* @return string Full path to tag template file. |
|
0 | 299 |
*/ |
300 |
function get_tag_template() { |
|
301 |
$tag = get_queried_object(); |
|
302 |
||
303 |
$templates = array(); |
|
304 |
||
305 |
if ( ! empty( $tag->slug ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
$slug_decoded = urldecode( $tag->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
if ( $slug_decoded !== $tag->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
$templates[] = "tag-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
|
0 | 312 |
$templates[] = "tag-{$tag->slug}.php"; |
313 |
$templates[] = "tag-{$tag->term_id}.php"; |
|
314 |
} |
|
315 |
$templates[] = 'tag.php'; |
|
316 |
||
317 |
return get_query_template( 'tag', $templates ); |
|
318 |
} |
|
319 |
||
320 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* Retrieve path of custom taxonomy term template in current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* The hierarchy for this template looks like: |
0 | 324 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* 1. taxonomy-{taxonomy_slug}-{term_slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* 2. taxonomy-{taxonomy_slug}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
* 3. taxonomy.php |
0 | 328 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* An example of this is: |
0 | 330 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
* 1. taxonomy-location-texas.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* 2. taxonomy-location.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* 3. taxonomy.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'taxonomy'. |
5 | 337 |
* |
0 | 338 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* template hierarchy when the term slug contains multibyte characters. |
0 | 341 |
* |
5 | 342 |
* @see get_query_template() |
343 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
* @return string Full path to custom taxonomy term template file. |
0 | 345 |
*/ |
346 |
function get_taxonomy_template() { |
|
347 |
$term = get_queried_object(); |
|
348 |
||
349 |
$templates = array(); |
|
350 |
||
351 |
if ( ! empty( $term->slug ) ) { |
|
352 |
$taxonomy = $term->taxonomy; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
$slug_decoded = urldecode( $term->slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
if ( $slug_decoded !== $term->slug ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
$templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
|
0 | 359 |
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; |
360 |
$templates[] = "taxonomy-$taxonomy.php"; |
|
361 |
} |
|
362 |
$templates[] = 'taxonomy.php'; |
|
363 |
||
364 |
return get_query_template( 'taxonomy', $templates ); |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Retrieve path of date template in current or parent template. |
|
369 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'date'. |
5 | 372 |
* |
0 | 373 |
* @since 1.5.0 |
374 |
* |
|
5 | 375 |
* @see get_query_template() |
376 |
* |
|
377 |
* @return string Full path to date template file. |
|
0 | 378 |
*/ |
379 |
function get_date_template() { |
|
9 | 380 |
return get_query_template( 'date' ); |
0 | 381 |
} |
382 |
||
383 |
/** |
|
384 |
* Retrieve path of home template in current or parent template. |
|
385 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'home'. |
0 | 388 |
* |
389 |
* @since 1.5.0 |
|
390 |
* |
|
5 | 391 |
* @see get_query_template() |
392 |
* |
|
393 |
* @return string Full path to home template file. |
|
0 | 394 |
*/ |
395 |
function get_home_template() { |
|
396 |
$templates = array( 'home.php', 'index.php' ); |
|
397 |
||
398 |
return get_query_template( 'home', $templates ); |
|
399 |
} |
|
400 |
||
401 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* Retrieve path of front page template in current or parent template. |
0 | 403 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'frontpage'. |
0 | 406 |
* |
407 |
* @since 3.0.0 |
|
408 |
* |
|
5 | 409 |
* @see get_query_template() |
410 |
* |
|
411 |
* @return string Full path to front page template file. |
|
0 | 412 |
*/ |
413 |
function get_front_page_template() { |
|
9 | 414 |
$templates = array( 'front-page.php' ); |
415 |
||
416 |
return get_query_template( 'frontpage', $templates ); |
|
417 |
} |
|
0 | 418 |
|
9 | 419 |
/** |
420 |
* Retrieve path of Privacy Policy page template in current or parent template. |
|
421 |
* |
|
422 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
|
423 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'privacypolicy'. |
|
424 |
* |
|
425 |
* @since 5.2.0 |
|
426 |
* |
|
427 |
* @see get_query_template() |
|
428 |
* |
|
429 |
* @return string Full path to privacy policy template file. |
|
430 |
*/ |
|
431 |
function get_privacy_policy_template() { |
|
432 |
$templates = array( 'privacy-policy.php' ); |
|
433 |
||
434 |
return get_query_template( 'privacypolicy', $templates ); |
|
0 | 435 |
} |
436 |
||
437 |
/** |
|
438 |
* Retrieve path of page template in current or parent template. |
|
439 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* 1. {Page Template}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* 2. page-{page_name}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* 3. page-{id}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* 4. page.php |
0 | 446 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* 1. page-templates/full-width.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* 2. page-about.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* 3. page-4.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* 4. page.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'page'. |
5 | 456 |
* |
0 | 457 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* @since 4.7.0 The decoded form of `page-{page_name}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* template hierarchy when the page name contains multibyte characters. |
0 | 460 |
* |
5 | 461 |
* @see get_query_template() |
462 |
* |
|
463 |
* @return string Full path to page template file. |
|
0 | 464 |
*/ |
465 |
function get_page_template() { |
|
9 | 466 |
$id = get_queried_object_id(); |
0 | 467 |
$template = get_page_template_slug(); |
9 | 468 |
$pagename = get_query_var( 'pagename' ); |
0 | 469 |
|
470 |
if ( ! $pagename && $id ) { |
|
16 | 471 |
// If a static page is set as the front page, $pagename will not be set. |
472 |
// Retrieve it from the queried object. |
|
0 | 473 |
$post = get_queried_object(); |
9 | 474 |
if ( $post ) { |
0 | 475 |
$pagename = $post->post_name; |
9 | 476 |
} |
0 | 477 |
} |
478 |
||
479 |
$templates = array(); |
|
9 | 480 |
if ( $template && 0 === validate_file( $template ) ) { |
0 | 481 |
$templates[] = $template; |
9 | 482 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
if ( $pagename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
$pagename_decoded = urldecode( $pagename ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
if ( $pagename_decoded !== $pagename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
$templates[] = "page-{$pagename_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
$templates[] = "page-{$pagename}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
} |
9 | 490 |
if ( $id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
$templates[] = "page-{$id}.php"; |
9 | 492 |
} |
0 | 493 |
$templates[] = 'page.php'; |
494 |
||
495 |
return get_query_template( 'page', $templates ); |
|
496 |
} |
|
497 |
||
498 |
/** |
|
499 |
* Retrieve path of search template in current or parent template. |
|
500 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'search'. |
5 | 503 |
* |
0 | 504 |
* @since 1.5.0 |
505 |
* |
|
5 | 506 |
* @see get_query_template() |
507 |
* |
|
508 |
* @return string Full path to search template file. |
|
0 | 509 |
*/ |
510 |
function get_search_template() { |
|
9 | 511 |
return get_query_template( 'search' ); |
0 | 512 |
} |
513 |
||
514 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* Retrieve path of single template in current or parent template. Applies to single Posts, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
* single Attachments, and single custom post types. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* 1. {Post Type Template}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* 2. single-{post_type}-{post_name}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* 3. single-{post_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* 4. single.php |
0 | 524 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* 1. templates/full-width.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* 2. single-post-hello-world.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* 3. single-post.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* 4. single.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'single'. |
5 | 534 |
* |
0 | 535 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* @since 4.4.0 `single-{post_type}-{post_name}.php` was added to the top of the template hierarchy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* @since 4.7.0 The decoded form of `single-{post_type}-{post_name}.php` was added to the top of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* template hierarchy when the post name contains multibyte characters. |
9 | 539 |
* @since 4.7.0 `{Post Type Template}.php` was added to the top of the template hierarchy. |
0 | 540 |
* |
5 | 541 |
* @see get_query_template() |
542 |
* |
|
543 |
* @return string Full path to single template file. |
|
0 | 544 |
*/ |
545 |
function get_single_template() { |
|
546 |
$object = get_queried_object(); |
|
547 |
||
548 |
$templates = array(); |
|
549 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
if ( ! empty( $object->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
$template = get_page_template_slug( $object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
if ( $template && 0 === validate_file( $template ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
$templates[] = $template; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
$name_decoded = urldecode( $object->post_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
if ( $name_decoded !== $object->post_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
$templates[] = "single-{$object->post_type}-{$name_decoded}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
$templates[] = "single-{$object->post_type}-{$object->post_name}.php"; |
0 | 562 |
$templates[] = "single-{$object->post_type}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
|
9 | 565 |
$templates[] = 'single.php'; |
0 | 566 |
|
567 |
return get_query_template( 'single', $templates ); |
|
568 |
} |
|
569 |
||
570 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* Retrieves an embed template path in the current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* 1. embed-{post_type}-{post_format}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* 2. embed-{post_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* 3. embed.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* An example of this is: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
* 1. embed-post-audio.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
* 2. embed-post.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
* 3. embed.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'embed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
* @see get_query_template() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
* @return string Full path to embed template file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
function get_embed_template() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
$object = get_queried_object(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
$templates = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
if ( ! empty( $object->post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
$post_format = get_post_format( $object ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
if ( $post_format ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
$templates[] = "embed-{$object->post_type}-{$post_format}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
$templates[] = "embed-{$object->post_type}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
606 |
|
9 | 607 |
$templates[] = 'embed.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
return get_query_template( 'embed', $templates ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
* Retrieves the path of the singular template in current or parent template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'singular'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @see get_query_template() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @return string Full path to singular template file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
function get_singular_template() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
return get_query_template( 'singular' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
/** |
0 | 629 |
* Retrieve path of attachment template in current or parent template. |
630 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* The hierarchy for this template looks like: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* 1. {mime_type}-{sub_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* 2. {sub_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* 3. {mime_type}.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* 4. attachment.php |
0 | 637 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* An example of this is: |
0 | 639 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* 1. image-jpeg.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* 2. jpeg.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
* 3. image.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* 4. attachment.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* and {@see '$type_template'} dynamic hooks, where `$type` is 'attachment'. |
5 | 647 |
* |
0 | 648 |
* @since 2.0.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* @since 4.3.0 The order of the mime type logic was reversed so the hierarchy is more logical. |
0 | 650 |
* |
5 | 651 |
* @see get_query_template() |
652 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
* @global array $posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* |
5 | 655 |
* @return string Full path to attachment template file. |
0 | 656 |
*/ |
657 |
function get_attachment_template() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
$attachment = get_queried_object(); |
0 | 659 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
$templates = array(); |
0 | 661 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
if ( $attachment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
} |
0 | 668 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
if ( ! empty( $subtype ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
$templates[] = "{$type}-{$subtype}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
$templates[] = "{$subtype}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
$templates[] = "{$type}.php"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$templates[] = 'attachment.php'; |
0 | 676 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
return get_query_template( 'attachment', $templates ); |
0 | 678 |
} |
679 |
||
680 |
/** |
|
681 |
* Retrieve the name of the highest priority template file that exists. |
|
682 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
* Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* so that themes which inherit from a parent theme can just overload one file. |
0 | 685 |
* |
686 |
* @since 2.7.0 |
|
16 | 687 |
* @since 5.5.0 The `$args` parameter was added. |
0 | 688 |
* |
689 |
* @param string|array $template_names Template file(s) to search for, in order. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* @param bool $load If true the template file will be loaded if it is found. |
16 | 691 |
* @param bool $require_once Whether to require_once or require. Has no effect if `$load` is false. |
692 |
* Default true. |
|
693 |
* @param array $args Optional. Additional arguments passed to the template. |
|
694 |
* Default empty array. |
|
0 | 695 |
* @return string The template filename if one is located. |
696 |
*/ |
|
16 | 697 |
function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) { |
0 | 698 |
$located = ''; |
699 |
foreach ( (array) $template_names as $template_name ) { |
|
9 | 700 |
if ( ! $template_name ) { |
0 | 701 |
continue; |
9 | 702 |
} |
703 |
if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { |
|
0 | 704 |
$located = STYLESHEETPATH . '/' . $template_name; |
705 |
break; |
|
9 | 706 |
} elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { |
0 | 707 |
$located = TEMPLATEPATH . '/' . $template_name; |
708 |
break; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
$located = ABSPATH . WPINC . '/theme-compat/' . $template_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
break; |
0 | 712 |
} |
713 |
} |
|
714 |
||
16 | 715 |
if ( $load && '' !== $located ) { |
716 |
load_template( $located, $require_once, $args ); |
|
9 | 717 |
} |
0 | 718 |
|
719 |
return $located; |
|
720 |
} |
|
721 |
||
722 |
/** |
|
723 |
* Require the template file with WordPress environment. |
|
724 |
* |
|
725 |
* The globals are set up for the template file to ensure that the WordPress |
|
726 |
* environment is available from within the function. The query variables are |
|
727 |
* also available. |
|
728 |
* |
|
729 |
* @since 1.5.0 |
|
16 | 730 |
* @since 5.5.0 The `$args` parameter was added. |
0 | 731 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
* @global array $posts |
16 | 733 |
* @global WP_Post $post Global post object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
* @global bool $wp_did_header |
16 | 735 |
* @global WP_Query $wp_query WordPress Query object. |
736 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
737 |
* @global wpdb $wpdb WordPress database abstraction object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
* @global string $wp_version |
16 | 739 |
* @global WP $wp Current WordPress environment instance. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* @global int $id |
16 | 741 |
* @global WP_Comment $comment Global comment object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
* @global int $user_ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
* |
0 | 744 |
* @param string $_template_file Path to template file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
* @param bool $require_once Whether to require_once or require. Default true. |
16 | 746 |
* @param array $args Optional. Additional arguments passed to the template. |
747 |
* Default empty array. |
|
0 | 748 |
*/ |
16 | 749 |
function load_template( $_template_file, $require_once = true, $args = array() ) { |
0 | 750 |
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
751 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
if ( is_array( $wp_query->query_vars ) ) { |
9 | 753 |
/* |
754 |
* This use of extract() cannot be removed. There are many possible ways that |
|
755 |
* templates could depend on variables that it creates existing, and no way to |
|
756 |
* detect and deprecate it. |
|
757 |
* |
|
758 |
* Passing the EXTR_SKIP flag is the safest option, ensuring globals and |
|
759 |
* function variables cannot be overwritten. |
|
760 |
*/ |
|
761 |
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
|
0 | 762 |
extract( $wp_query->query_vars, EXTR_SKIP ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
} |
0 | 764 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
if ( isset( $s ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
$s = esc_attr( $s ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
if ( $require_once ) { |
16 | 770 |
require_once $_template_file; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
} else { |
16 | 772 |
require $_template_file; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
} |
0 | 774 |
} |