### Eclipse Workspace Patch 1.0
#P wordpress-trunk
Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 12600)
+++ wp-includes/theme.php	(working copy)
@@ -953,7 +953,7 @@
  *
  * @param array $template_names Array of template files to search for in priority order.
  * @param bool $load If true the template file will be loaded if it is found.
- * @return string The template filename if one is located.
+ * @return string The template filename if one is located, empty string if none is located
  */
 function locate_template($template_names, $load = false) {
 	if (!is_array($template_names))
@@ -987,13 +987,16 @@
  *
  * @param string $_template_file Path to template file.
  */
-function load_template($_template_file) {
+function load_template( $_template_file ) {
 	global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
 
 	if ( is_array($wp_query->query_vars) )
 		extract($wp_query->query_vars, EXTR_SKIP);
 
-	require_once($_template_file);
+	if ( $_template_file = apply_filters( 'template_load', $_template_file ) ) {
+		include $_template_file;
+		do_action( 'template_loaded', $_template_file );
+	}
 }
 
 /**
Index: wp-includes/template-loader.php
===================================================================
--- wp-includes/template-loader.php	(revision 12600)
+++ wp-includes/template-loader.php	(working copy)
@@ -3,76 +3,65 @@
  * Loads the correct template based on the visitor's url
  * @package WordPress
  */
-if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
+$template = '';
+
+if ( $flag_themes = ( defined( 'WP_USE_THEMES' ) && constant( 'WP_USE_THEMES' ) ) ) 
 	do_action('template_redirect');
-	if ( is_robots() ) {
-		do_action('do_robots');
-		return;
-	} else if ( is_feed() ) {
-		do_feed();
-		return;
-	} else if ( is_trackback() ) {
-		include(ABSPATH . 'wp-trackback.php');
-		return;
-	} else if ( is_404() && $template = get_404_template() ) {
-		include($template);
-		return;
-	} else if ( is_search() && $template = get_search_template() ) {
-		include($template);
-		return;
-	} else if ( is_tax() && $template = get_taxonomy_template()) {
-		include($template);
-		return;
-	} else if ( is_home() && $template = get_home_template() ) {
-		include($template);
-		return;
-	} else if ( is_attachment() && $template = get_attachment_template() ) {
-		remove_filter('the_content', 'prepend_attachment');
-		include($template);
-		return;
-	} else if ( is_single() && $template = get_single_template() ) {
-		include($template);
-		return;
-	} else if ( is_page() && $template = get_page_template() ) {
-		include($template);
-		return;
-	} else if ( is_category() && $template = get_category_template()) {
-		include($template);
-		return;
-	} else if ( is_tag() && $template = get_tag_template()) {
-		include($template);
-		return;
-	} else if ( is_author() && $template = get_author_template() ) {
-		include($template);
-		return;
-	} else if ( is_date() && $template = get_date_template() ) {
-		include($template);
-		return;
-	} else if ( is_archive() && $template = get_archive_template() ) {
-		include($template);
-		return;
-	} else if ( is_comments_popup() && $template = get_comments_popup_template() ) {
-		include($template);
-		return;
-	} else if ( is_paged() && $template = get_paged_template() ) {
-		include($template);
-		return;
-	} else if ( file_exists(TEMPLATEPATH . "/index.php") ) {
-		include(TEMPLATEPATH . "/index.php");
-		return;
+
+/* default actions regardless of wether themes are used or not */
+if ( is_robots() ) {
+	do_action('do_robots');
+	return;
+} else if ( is_feed() ) {
+	do_feed();
+	return;
+} else if ( is_trackback() ) {
+	$template = ABSPATH . 'wp-trackback.php';
+}
+
+/* do themes-template if themes are used */
+if ( $flag_themes && $template == '') {	
+	
+	$themes_template_config = array(
+		'404'            => array(  ),
+		'search'         => array(  ),
+		'tax' 		     => array(  ),
+		'home' 		     => array(  ),
+		'attachment'     => array( 'remove_filter' => array( 'the_content', 'prepend_attachment' ) ),		
+		'single'         => array(  ),
+		'page'           => array(  ),
+		'category'       => array(  ),
+		'tag'            => array(  ),
+		'author'         => array(  ),
+		'date'           => array(  ),
+		'archive'        => array(  ),
+		'comments_popup' => array(  ),
+		'paged'          => array(  ),
+	);
+	
+	$themes_template_config = apply_filters('template_include_config', $themes_template_config);
+	
+	foreach ($themes_template_config as $name => $config) {
+		$is_query     = sprintf('is_%s'          , $name);
+		$get_template = sprintf('get_%s_template', $name); 
+		if ( $wp_query->$is_query && $template = $get_template() ) {
+			if ( isset( $config['remove_filter'] ) )
+				remove_filter($config['remove_filter'][0], $config['remove_filter'][1]);
+			break;
+		}
 	}
-} else {
-	// Process feeds and trackbacks even if not using themes.
-	if ( is_robots() ) {
-		do_action('do_robots');
-		return;
-	} else if ( is_feed() ) {
-		do_feed();
-		return;
-	} else if ( is_trackback() ) {
-		include(ABSPATH . 'wp-trackback.php');
-		return;
-	}
+		
+	unset( $themes_template_config, $is_query, $get_template );
+		
+	if ( $template == '' && file_exists(TEMPLATEPATH . "/index.php") )
+		$template = TEMPLATEPATH . "/index.php";
 }
 
+unset( $flag_themes );
+
+if ( $template = apply_filters('template_include', $template) ) {
+	include $template;
+	do_action('template_included', $template);
+}
+
 ?>
\ No newline at end of file
