Ticket #11242: 11242.patch

File 11242.patch, 5.5 KB (added by hakre, 2 years ago)

Updated and Improved Patch

  • wp-includes/theme.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    953953 * 
    954954 * @param array $template_names Array of template files to search for in priority order. 
    955955 * @param bool $load If true the template file will be loaded if it is found. 
    956  * @return string The template filename if one is located. 
     956 * @return string The template filename if one is located, empty string if none is located 
    957957 */ 
    958958function locate_template($template_names, $load = false) { 
    959959        if (!is_array($template_names)) 
     
    987987 * 
    988988 * @param string $_template_file Path to template file. 
    989989 */ 
    990 function load_template($_template_file) { 
     990function load_template( $_template_file ) { 
    991991        global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 
    992992 
    993993        if ( is_array($wp_query->query_vars) ) 
    994994                extract($wp_query->query_vars, EXTR_SKIP); 
    995995 
    996         require_once($_template_file); 
     996        if ( $_template_file = apply_filters( 'template_load', $_template_file ) ) { 
     997                include $_template_file; 
     998                do_action( 'template_loaded', $_template_file ); 
     999        } 
    9971000} 
    9981001 
    9991002/** 
  • wp-includes/template-loader.php

     
    33 * Loads the correct template based on the visitor's url 
    44 * @package WordPress 
    55 */ 
    6 if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) { 
     6$template = ''; 
     7 
     8if ( $flag_themes = ( defined( 'WP_USE_THEMES' ) && constant( 'WP_USE_THEMES' ) ) )  
    79        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() ) { 
    30                 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; 
     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        $template = ABSPATH . 'wp-trackback.php'; 
     20} 
     21 
     22/* do themes-template if themes are used */ 
     23if ( $flag_themes && $template == '') {  
     24         
     25        $themes_template_config = array( 
     26                '404'            => array(  ), 
     27                'search'         => array(  ), 
     28                'tax'                => array(  ), 
     29                'home'               => array(  ), 
     30                'attachment'     => array( 'remove_filter' => array( 'the_content', 'prepend_attachment' ) ),            
     31                'single'         => array(  ), 
     32                'page'           => array(  ), 
     33                'category'       => array(  ), 
     34                'tag'            => array(  ), 
     35                'author'         => array(  ), 
     36                'date'           => array(  ), 
     37                'archive'        => array(  ), 
     38                'comments_popup' => array(  ), 
     39                'paged'          => array(  ), 
     40        ); 
     41         
     42        $themes_template_config = apply_filters('template_include_config', $themes_template_config); 
     43         
     44        foreach ($themes_template_config as $name => $config) { 
     45                $is_query     = sprintf('is_%s'          , $name); 
     46                $get_template = sprintf('get_%s_template', $name);  
     47                if ( $wp_query->$is_query && $template = $get_template() ) { 
     48                        if ( isset( $config['remove_filter'] ) ) 
     49                                remove_filter($config['remove_filter'][0], $config['remove_filter'][1]); 
     50                        break; 
     51                } 
    6352        } 
    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         } 
     53                 
     54        unset( $themes_template_config, $is_query, $get_template ); 
     55                 
     56        if ( $template == '' && file_exists(TEMPLATEPATH . "/index.php") ) 
     57                $template = TEMPLATEPATH . "/index.php"; 
    7658} 
    7759 
     60unset( $flag_themes ); 
     61 
     62if ( $template = apply_filters('template_include', $template) ) { 
     63        include $template; 
     64        do_action('template_included', $template); 
     65} 
     66 
    7867?> 
     68 No newline at end of file