wp/wp-includes/template-loader.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    22  * @since 3.5.0
    22  * @since 3.5.0
    23  *
    23  *
    24  * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true.
    24  * @param bool $exit Whether to exit without generating any content for 'HEAD' requests. Default true.
    25  */
    25  */
    26 if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) {
    26 if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) {
    27 	exit();
    27 	exit;
    28 }
    28 }
    29 
    29 
    30 // Process feeds and trackbacks even if not using themes.
    30 // Process feeds and trackbacks even if not using themes.
    31 if ( is_robots() ) :
    31 if ( is_robots() ) {
    32 	/**
    32 	/**
    33 	 * Fired when the template loader determines a robots.txt request.
    33 	 * Fired when the template loader determines a robots.txt request.
    34 	 *
    34 	 *
    35 	 * @since 2.1.0
    35 	 * @since 2.1.0
    36 	 */
    36 	 */
    37 	do_action( 'do_robots' );
    37 	do_action( 'do_robots' );
    38 	return;
    38 	return;
    39 elseif ( is_feed() ) :
    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() ) {
    40 	do_feed();
    48 	do_feed();
    41 	return;
    49 	return;
    42 elseif ( is_trackback() ) :
    50 } elseif ( is_trackback() ) {
    43 	include( ABSPATH . 'wp-trackback.php' );
    51 	require ABSPATH . 'wp-trackback.php';
    44 	return;
    52 	return;
    45 endif;
    53 }
    46 
    54 
    47 if ( wp_using_themes() ) :
    55 if ( wp_using_themes() ) {
    48 	$template = false;
    56 
    49 	if ( is_embed() && $template = get_embed_template() ) :
    57 	$tag_templates = array(
    50 	elseif ( is_404() && $template = get_404_template() ) :
    58 		'is_embed'             => 'get_embed_template',
    51 	elseif ( is_search() && $template = get_search_template() ) :
    59 		'is_404'               => 'get_404_template',
    52 	elseif ( is_front_page() && $template = get_front_page_template() ) :
    60 		'is_search'            => 'get_search_template',
    53 	elseif ( is_home() && $template = get_home_template() ) :
    61 		'is_front_page'        => 'get_front_page_template',
    54 	elseif ( is_privacy_policy() && $template = get_privacy_policy_template() ) :
    62 		'is_home'              => 'get_home_template',
    55 	elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
    63 		'is_privacy_policy'    => 'get_privacy_policy_template',
    56 	elseif ( is_tax() && $template = get_taxonomy_template() ) :
    64 		'is_post_type_archive' => 'get_post_type_archive_template',
    57 	elseif ( is_attachment() && $template = get_attachment_template() ) :
    65 		'is_tax'               => 'get_taxonomy_template',
    58 		remove_filter( 'the_content', 'prepend_attachment' );
    66 		'is_attachment'        => 'get_attachment_template',
    59 	elseif ( is_single() && $template = get_single_template() ) :
    67 		'is_single'            => 'get_single_template',
    60 	elseif ( is_page() && $template = get_page_template() ) :
    68 		'is_page'              => 'get_page_template',
    61 	elseif ( is_singular() && $template = get_singular_template() ) :
    69 		'is_singular'          => 'get_singular_template',
    62 	elseif ( is_category() && $template = get_category_template() ) :
    70 		'is_category'          => 'get_category_template',
    63 	elseif ( is_tag() && $template = get_tag_template() ) :
    71 		'is_tag'               => 'get_tag_template',
    64 	elseif ( is_author() && $template = get_author_template() ) :
    72 		'is_author'            => 'get_author_template',
    65 	elseif ( is_date() && $template = get_date_template() ) :
    73 		'is_date'              => 'get_date_template',
    66 	elseif ( is_archive() && $template = get_archive_template() ) :
    74 		'is_archive'           => 'get_archive_template',
    67 	else :
    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 ) {
    68 		$template = get_index_template();
    94 		$template = get_index_template();
    69 	endif;
    95 	}
       
    96 
    70 	/**
    97 	/**
    71 	 * Filters the path of the current template before including it.
    98 	 * Filters the path of the current template before including it.
    72 	 *
    99 	 *
    73 	 * @since 3.0.0
   100 	 * @since 3.0.0
    74 	 *
   101 	 *
    75 	 * @param string $template The path of the template to include.
   102 	 * @param string $template The path of the template to include.
    76 	 */
   103 	 */
    77 	if ( $template = apply_filters( 'template_include', $template ) ) {
   104 	$template = apply_filters( 'template_include', $template );
    78 		include( $template );
   105 	if ( $template ) {
       
   106 		include $template;
    79 	} elseif ( current_user_can( 'switch_themes' ) ) {
   107 	} elseif ( current_user_can( 'switch_themes' ) ) {
    80 		$theme = wp_get_theme();
   108 		$theme = wp_get_theme();
    81 		if ( $theme->errors() ) {
   109 		if ( $theme->errors() ) {
    82 			wp_die( $theme->errors() );
   110 			wp_die( $theme->errors() );
    83 		}
   111 		}
    84 	}
   112 	}
    85 	return;
   113 	return;
    86 endif;
   114 }