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