Make WordPress Core

Ticket #11242: ticket_11242_patch3.diff

File ticket_11242_patch3.diff, 4.3 KB (added by ptahdunbar, 15 years ago)
  • wp-includes/template-loader.php

     
    11<?php
    22/**
    3  * Loads the correct template based on the visitor's url
     3 * Loads the correct template based on the url requested.
     4 *
    45 * @package WordPress
    56 */
    6 if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
    7         do_action('template_redirect');
    8         if ( is_robots() ) {
    9                 do_action('do_robots');
    10                 return;
    11         } else if ( is_feed() ) {
    12                 do_feed();
    13                 return;
    14         } else if ( is_trackback() ) {
    15                 include(ABSPATH . 'wp-trackback.php');
    16                 return;
    17         } else if ( is_404() && $template = get_404_template() ) {
    18                 include($template);
    19                 return;
    20         } else if ( is_search() && $template = get_search_template() ) {
    21                 include($template);
    22                 return;
    23         } else if ( is_tax() && $template = get_taxonomy_template()) {
    24                 include($template);
    25                 return;
    26         } else if ( is_home() && $template = get_home_template() ) {
    27                 include($template);
    28                 return;
    29         } else if ( is_attachment() && $template = get_attachment_template() ) {
     7
     8if ( $flag_themes = ( defined( 'WP_USE_THEMES' ) && constant( 'WP_USE_THEMES' ) ) )
     9        do_action( 'template_redirect' );
     10
     11/* Default actions regardless of wether themes are used or not */
     12if ( is_robots() ) {
     13        do_action( 'do_robots' );
     14        return;
     15} else if ( is_feed() ) {
     16        do_feed();
     17        return;
     18} else if ( is_trackback() ) {
     19        include( ABSPATH . 'wp-trackback.php' );
     20        return;
     21}
     22
     23/* Load the template if themes are used */
     24if ( $flag_themes ) {
     25        if ( is_404()                    && $template = get_404_template()            ) :
     26        elseif ( is_search()         && $template = get_search_template()         ) :
     27        elseif ( is_tax()            && $template = get_taxonomy_template()       ) :
     28        elseif ( is_home()           && $template = get_home_template()           ) :
     29        elseif ( is_attachment()     && $template = get_attachment_template()     ) :
    3030                remove_filter('the_content', 'prepend_attachment');
    31                 include($template);
    32                 return;
    33         } else if ( is_single() && $template = get_single_template() ) {
    34                 include($template);
    35                 return;
    36         } else if ( is_page() && $template = get_page_template() ) {
    37                 include($template);
    38                 return;
    39         } else if ( is_category() && $template = get_category_template()) {
    40                 include($template);
    41                 return;
    42         } else if ( is_tag() && $template = get_tag_template()) {
    43                 include($template);
    44                 return;
    45         } else if ( is_author() && $template = get_author_template() ) {
    46                 include($template);
    47                 return;
    48         } else if ( is_date() && $template = get_date_template() ) {
    49                 include($template);
    50                 return;
    51         } else if ( is_archive() && $template = get_archive_template() ) {
    52                 include($template);
    53                 return;
    54         } else if ( is_comments_popup() && $template = get_comments_popup_template() ) {
    55                 include($template);
    56                 return;
    57         } else if ( is_paged() && $template = get_paged_template() ) {
    58                 include($template);
    59                 return;
    60         } else if ( file_exists(TEMPLATEPATH . "/index.php") ) {
    61                 include(TEMPLATEPATH . "/index.php");
    62                 return;
    63         }
    64 } else {
    65         // Process feeds and trackbacks even if not using themes.
    66         if ( is_robots() ) {
    67                 do_action('do_robots');
    68                 return;
    69         } else if ( is_feed() ) {
    70                 do_feed();
    71                 return;
    72         } else if ( is_trackback() ) {
    73                 include(ABSPATH . 'wp-trackback.php');
    74                 return;
    75         }
     31        elseif ( is_single()         && $template = get_single_template()         ) :
     32        elseif ( is_page()           && $template = get_page_template()           ) :
     33        elseif ( is_category()       && $template = get_category_template()       ) :
     34        elseif ( is_tag()            && $template = get_tag_template()            ) :
     35        elseif ( is_author()         && $template = get_author_template()         ) :
     36        elseif ( is_date()           && $template = get_date_template()           ) :
     37        elseif ( is_archive()        && $template = get_archive_template()        ) :
     38        elseif ( is_comments_popup() && $template = get_comments_popup_template() ) :
     39        elseif ( is_paged()          && $template = get_paged_template()          ) :
     40        elseif ( file_exists(TEMPLATEPATH . '/index.php') ) :
     41                $template = TEMPLATEPATH . '/index.php';
     42        endif;
    7643}
    7744
     45unset( $flag_themes );
     46
     47if ( $template = apply_filters('template_include', $template) ) {
     48        include( $template );
     49        do_action( 'template_loaded', $template );
     50        return;
     51}
     52
    7853?>
     54 No newline at end of file