Ticket #11242: diff

File diff, 3.2 KB (added by holizz, 2 years ago)

Patch to add template_include filter

  • wp-includes/template-loader.php

     
    33 * Loads the correct template based on the visitor's url 
    44 * @package WordPress 
    55 */ 
     6$template = null; 
    67if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) { 
    78        do_action('template_redirect'); 
    89        if ( is_robots() ) { 
    910                do_action('do_robots'); 
    10                 return; 
    1111        } else if ( is_feed() ) { 
    1212                do_feed(); 
    13                 return; 
    1413        } else if ( is_trackback() ) { 
    15                 include(ABSPATH . 'wp-trackback.php'); 
    16                 return; 
     14                $template = ABSPATH . 'wp-trackback.php'; 
    1715        } else if ( is_404() && $template = get_404_template() ) { 
    18                 include($template); 
    19                 return; 
    2016        } else if ( is_search() && $template = get_search_template() ) { 
    21                 include($template); 
    22                 return; 
    2317        } else if ( is_tax() && $template = get_taxonomy_template()) { 
    24                 include($template); 
    25                 return; 
    2618        } else if ( is_home() && $template = get_home_template() ) { 
    27                 include($template); 
    28                 return; 
    2919        } else if ( is_attachment() && $template = get_attachment_template() ) { 
    3020                remove_filter('the_content', 'prepend_attachment'); 
    31                 include($template); 
    32                 return; 
    3321        } else if ( is_single() && $template = get_single_template() ) { 
    34                 include($template); 
    35                 return; 
    3622        } else if ( is_page() && $template = get_page_template() ) { 
    37                 include($template); 
    38                 return; 
    3923        } else if ( is_category() && $template = get_category_template()) { 
    40                 include($template); 
    41                 return; 
    4224        } else if ( is_tag() && $template = get_tag_template()) { 
    43                 include($template); 
    44                 return; 
    4525        } else if ( is_author() && $template = get_author_template() ) { 
    46                 include($template); 
    47                 return; 
    4826        } else if ( is_date() && $template = get_date_template() ) { 
    49                 include($template); 
    50                 return; 
    5127        } else if ( is_archive() && $template = get_archive_template() ) { 
    52                 include($template); 
    53                 return; 
    5428        } else if ( is_comments_popup() && $template = get_comments_popup_template() ) { 
    55                 include($template); 
    56                 return; 
    5729        } else if ( is_paged() && $template = get_paged_template() ) { 
    58                 include($template); 
    59                 return; 
    6030        } else if ( file_exists(TEMPLATEPATH . "/index.php") ) { 
    61                 include(TEMPLATEPATH . "/index.php"); 
    62                 return; 
     31                $template = TEMPLATEPATH . "/index.php"; 
    6332        } 
    6433} else { 
    6534        // Process feeds and trackbacks even if not using themes. 
    6635        if ( is_robots() ) { 
    6736                do_action('do_robots'); 
    68                 return; 
    6937        } else if ( is_feed() ) { 
    7038                do_feed(); 
    71                 return; 
    7239        } else if ( is_trackback() ) { 
    73                 include(ABSPATH . 'wp-trackback.php'); 
    74                 return; 
     40                $template = ABSPATH . 'wp-trackback.php'; 
    7541        } 
    7642} 
    7743 
    78 ?> 
    79  No newline at end of file 
     44if ($template != null) { 
     45        $template = apply_filters('template_include', $template); 
     46        if ($template != null) 
     47            include($template); 
     48} 
     49 
     50?> 
  • wp-includes/theme.php

     
    991991        if ( is_array($wp_query->query_vars) ) 
    992992                extract($wp_query->query_vars, EXTR_SKIP); 
    993993 
    994         require_once($_template_file); 
     994        $_template_file = apply_filters('template_include',$_template_file); 
     995        if ($_template_file != null) 
     996            require_once($_template_file); 
    995997} 
    996998 
    997999/**