Don't use require_once for get_template_part(). fixes #12958.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14075 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-04-11 17:26:03 +00:00
parent 4975bf8ed8
commit 3c5115f15f
2 changed files with 16 additions and 8 deletions

View File

@ -103,6 +103,9 @@ function get_sidebar( $name = null ) {
* specialised part will be included. If the theme contains no {slug}.php file
* then no template will be included.
*
* The template is included using require, not require_once, so you may include the
* same template part multiple times.
*
* For the parameter, if the file is called "{slug}-special.php" then specify
* "special".
*
@ -122,7 +125,7 @@ function get_template_part( $slug, $name = null ) {
$templates[] = "{$slug}.php";
locate_template($templates, true);
locate_template($templates, true, false);
}
/**

View File

@ -986,9 +986,10 @@ function get_comments_popup_template() {
*
* @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.
* @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
* @return string The template filename if one is located.
*/
function locate_template($template_names, $load = false) {
function locate_template($template_names, $load = false, $require_once = true ) {
if ( !is_array($template_names) )
return '';
@ -1004,13 +1005,13 @@ function locate_template($template_names, $load = false) {
}
if ( $load && '' != $located )
load_template($located);
load_template( $located, $require_once );
return $located;
}
/**
* Require once the template file with WordPress environment.
* Require the template file with WordPress environment.
*
* The globals are set up for the template file to ensure that the WordPress
* environment is available from within the function. The query variables are
@ -1019,14 +1020,18 @@ function locate_template($template_names, $load = false) {
* @since 1.5.0
*
* @param string $_template_file Path to template file.
* @param bool $require_once Whether to require_once or require. Default true.
*/
function load_template($_template_file) {
function load_template( $_template_file, $require_once = true ) {
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);
if ( is_array( $wp_query->query_vars ) )
extract( $wp_query->query_vars, EXTR_SKIP );
require_once($_template_file);
if ( $require_once )
require_once( $_template_file );
else
require( $_template_file );
}
/**