]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/template-loader.php
WordPress 4.4.2-scripts
[autoinstalls/wordpress.git] / wp-includes / template-loader.php
1 <?php
2 /**
3  * Loads the correct template based on the visitor's url
4  * @package WordPress
5  */
6 if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
7         /**
8          * Fires before determining which template to load.
9          *
10          * @since 1.5.0
11          */
12         do_action( 'template_redirect' );
13
14 /**
15  * Filter whether to allow 'HEAD' requests to generate content.
16  *
17  * Provides a significant performance bump by exiting before the page
18  * content loads for 'HEAD' requests. See #14348.
19  *
20  * @since 3.5.0
21  *
22  * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true.
23  */
24 if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) )
25         exit();
26
27 // Process feeds and trackbacks even if not using themes.
28 if ( is_robots() ) :
29         /**
30          * Fired when the template loader determines a robots.txt request.
31          *
32          * @since 2.1.0
33          */
34         do_action( 'do_robots' );
35         return;
36 elseif ( is_feed() ) :
37         do_feed();
38         return;
39 elseif ( is_trackback() ) :
40         include( ABSPATH . 'wp-trackback.php' );
41         return;
42 elseif ( is_embed() ) :
43         $template = ABSPATH . WPINC . '/embed-template.php';
44
45         /**
46          * Filter the template used for embedded posts.
47          *
48          * @since 4.4.0
49          *
50          * @param string $template Path to the template file.
51          */
52         $template = apply_filters( 'embed_template', $template );
53
54         include ( $template );
55         return;
56 endif;
57
58 if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
59         $template = false;
60         if     ( is_404()            && $template = get_404_template()            ) :
61         elseif ( is_search()         && $template = get_search_template()         ) :
62         elseif ( is_front_page()     && $template = get_front_page_template()     ) :
63         elseif ( is_home()           && $template = get_home_template()           ) :
64         elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
65         elseif ( is_tax()            && $template = get_taxonomy_template()       ) :
66         elseif ( is_attachment()     && $template = get_attachment_template()     ) :
67                 remove_filter('the_content', 'prepend_attachment');
68         elseif ( is_single()         && $template = get_single_template()         ) :
69         elseif ( is_page()           && $template = get_page_template()           ) :
70         elseif ( is_singular()       && $template = get_singular_template()       ) :
71         elseif ( is_category()       && $template = get_category_template()       ) :
72         elseif ( is_tag()            && $template = get_tag_template()            ) :
73         elseif ( is_author()         && $template = get_author_template()         ) :
74         elseif ( is_date()           && $template = get_date_template()           ) :
75         elseif ( is_archive()        && $template = get_archive_template()        ) :
76         elseif ( is_comments_popup() && $template = get_comments_popup_template() ) :
77         elseif ( is_paged()          && $template = get_paged_template()          ) :
78         else :
79                 $template = get_index_template();
80         endif;
81         /**
82          * Filter the path of the current template before including it.
83          *
84          * @since 3.0.0
85          *
86          * @param string $template The path of the template to include.
87          */
88         if ( $template = apply_filters( 'template_include', $template ) )
89                 include( $template );
90         return;
91 endif;