author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Loads the correct template based on the visitor's url |
|
9 | 4 |
* |
0 | 5 |
* @package WordPress |
6 |
*/ |
|
9 | 7 |
if ( wp_using_themes() ) { |
0 | 8 |
/** |
9 |
* Fires before determining which template to load. |
|
10 |
* |
|
5 | 11 |
* @since 1.5.0 |
0 | 12 |
*/ |
13 |
do_action( 'template_redirect' ); |
|
9 | 14 |
} |
0 | 15 |
|
16 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* Filters whether to allow 'HEAD' requests to generate content. |
0 | 18 |
* |
19 |
* Provides a significant performance bump by exiting before the page |
|
20 |
* content loads for 'HEAD' requests. See #14348. |
|
21 |
* |
|
22 |
* @since 3.5.0 |
|
23 |
* |
|
24 |
* @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true. |
|
25 |
*/ |
|
9 | 26 |
if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) { |
16 | 27 |
exit; |
9 | 28 |
} |
0 | 29 |
|
30 |
// Process feeds and trackbacks even if not using themes. |
|
16 | 31 |
if ( is_robots() ) { |
0 | 32 |
/** |
33 |
* Fired when the template loader determines a robots.txt request. |
|
34 |
* |
|
35 |
* @since 2.1.0 |
|
36 |
*/ |
|
37 |
do_action( 'do_robots' ); |
|
38 |
return; |
|
16 | 39 |
} elseif ( is_favicon() ) { |
40 |
/** |
|
41 |
* Fired when the template loader determines a favicon.ico request. |
|
42 |
* |
|
43 |
* @since 5.4.0 |
|
44 |
*/ |
|
45 |
do_action( 'do_favicon' ); |
|
46 |
return; |
|
47 |
} elseif ( is_feed() ) { |
|
0 | 48 |
do_feed(); |
49 |
return; |
|
16 | 50 |
} elseif ( is_trackback() ) { |
51 |
require ABSPATH . 'wp-trackback.php'; |
|
0 | 52 |
return; |
16 | 53 |
} |
54 |
||
55 |
if ( wp_using_themes() ) { |
|
0 | 56 |
|
16 | 57 |
$tag_templates = array( |
58 |
'is_embed' => 'get_embed_template', |
|
59 |
'is_404' => 'get_404_template', |
|
60 |
'is_search' => 'get_search_template', |
|
61 |
'is_front_page' => 'get_front_page_template', |
|
62 |
'is_home' => 'get_home_template', |
|
63 |
'is_privacy_policy' => 'get_privacy_policy_template', |
|
64 |
'is_post_type_archive' => 'get_post_type_archive_template', |
|
65 |
'is_tax' => 'get_taxonomy_template', |
|
66 |
'is_attachment' => 'get_attachment_template', |
|
67 |
'is_single' => 'get_single_template', |
|
68 |
'is_page' => 'get_page_template', |
|
69 |
'is_singular' => 'get_singular_template', |
|
70 |
'is_category' => 'get_category_template', |
|
71 |
'is_tag' => 'get_tag_template', |
|
72 |
'is_author' => 'get_author_template', |
|
73 |
'is_date' => 'get_date_template', |
|
74 |
'is_archive' => 'get_archive_template', |
|
75 |
); |
|
76 |
$template = false; |
|
77 |
||
78 |
// Loop through each of the template conditionals, and find the appropriate template file. |
|
79 |
foreach ( $tag_templates as $tag => $template_getter ) { |
|
80 |
if ( call_user_func( $tag ) ) { |
|
81 |
$template = call_user_func( $template_getter ); |
|
82 |
} |
|
83 |
||
84 |
if ( $template ) { |
|
85 |
if ( 'is_attachment' === $tag ) { |
|
86 |
remove_filter( 'the_content', 'prepend_attachment' ); |
|
87 |
} |
|
88 |
||
89 |
break; |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
if ( ! $template ) { |
|
0 | 94 |
$template = get_index_template(); |
16 | 95 |
} |
96 |
||
0 | 97 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* Filters the path of the current template before including it. |
0 | 99 |
* |
100 |
* @since 3.0.0 |
|
101 |
* |
|
102 |
* @param string $template The path of the template to include. |
|
103 |
*/ |
|
16 | 104 |
$template = apply_filters( 'template_include', $template ); |
105 |
if ( $template ) { |
|
106 |
include $template; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
} elseif ( current_user_can( 'switch_themes' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
$theme = wp_get_theme(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
if ( $theme->errors() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
wp_die( $theme->errors() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
} |
0 | 113 |
return; |
16 | 114 |
} |