wp/wp-includes/template-loader.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Loads the correct template based on the visitor's url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
	 * Fires before determining which template to load.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
	 * @since 1.5.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
	do_action( 'template_redirect' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
 * Filters whether to allow 'HEAD' requests to generate content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * Provides a significant performance bump by exiting before the page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * content loads for 'HEAD' requests. See #14348.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
// Process feeds and trackbacks even if not using themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
if ( is_robots() ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * Fired when the template loader determines a robots.txt request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	do_action( 'do_robots' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
elseif ( is_feed() ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	do_feed();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
elseif ( is_trackback() ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	include( ABSPATH . 'wp-trackback.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	$template = false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
	if     ( is_embed()          && $template = get_embed_template()          ) :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    47
	elseif ( is_404()            && $template = get_404_template()            ) :
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	elseif ( is_search()         && $template = get_search_template()         ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	elseif ( is_front_page()     && $template = get_front_page_template()     ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	elseif ( is_home()           && $template = get_home_template()           ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	elseif ( is_tax()            && $template = get_taxonomy_template()       ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	elseif ( is_attachment()     && $template = get_attachment_template()     ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		remove_filter('the_content', 'prepend_attachment');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	elseif ( is_single()         && $template = get_single_template()         ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	elseif ( is_page()           && $template = get_page_template()           ) :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
	elseif ( is_singular()       && $template = get_singular_template()       ) :
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	elseif ( is_category()       && $template = get_category_template()       ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	elseif ( is_tag()            && $template = get_tag_template()            ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	elseif ( is_author()         && $template = get_author_template()         ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	elseif ( is_date()           && $template = get_date_template()           ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	elseif ( is_archive()        && $template = get_archive_template()        ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		$template = get_index_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    67
	 * Filters the path of the current template before including it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 * @param string $template The path of the template to include.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
	if ( $template = apply_filters( 'template_include', $template ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		include( $template );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
	} elseif ( current_user_can( 'switch_themes' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
		$theme = wp_get_theme();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
		if ( $theme->errors() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
			wp_die( $theme->errors() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
endif;