Make WordPress Core

Changeset 14075


Ignore:
Timestamp:
04/11/2010 05:26:03 PM (15 years ago)
Author:
nacin
Message:

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

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r14070 r14075  
    104104 * then no template will be included.
    105105 *
     106 * The template is included using require, not require_once, so you may include the
     107 * same template part multiple times.
     108 *
    106109 * For the parameter, if the file is called "{slug}-special.php" then specify
    107110 * "special".
     
    123126    $templates[] = "{$slug}.php";
    124127
    125     locate_template($templates, true);
     128    locate_template($templates, true, false);
    126129}
    127130
  • trunk/wp-includes/theme.php

    r13928 r14075  
    987987 * @param array $template_names Array of template files to search for in priority order.
    988988 * @param bool $load If true the template file will be loaded if it is found.
     989 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
    989990 * @return string The template filename if one is located.
    990991 */
    991 function locate_template($template_names, $load = false) {
     992function locate_template($template_names, $load = false, $require_once = true ) {
    992993    if ( !is_array($template_names) )
    993994        return '';
     
    10051006
    10061007    if ( $load && '' != $located )
    1007         load_template($located);
     1008        load_template( $located, $require_once );
    10081009
    10091010    return $located;
     
    10111012
    10121013/**
    1013  * Require once the template file with WordPress environment.
     1014 * Require the template file with WordPress environment.
    10141015 *
    10151016 * The globals are set up for the template file to ensure that the WordPress
     
    10201021 *
    10211022 * @param string $_template_file Path to template file.
    1022  */
    1023 function load_template($_template_file) {
     1023 * @param bool $require_once Whether to require_once or require. Default true.
     1024 */
     1025function load_template( $_template_file, $require_once = true ) {
    10241026    global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
    10251027
    1026     if ( is_array($wp_query->query_vars) )
    1027         extract($wp_query->query_vars, EXTR_SKIP);
    1028 
    1029     require_once($_template_file);
     1028    if ( is_array( $wp_query->query_vars ) )
     1029        extract( $wp_query->query_vars, EXTR_SKIP );
     1030
     1031    if ( $require_once )
     1032        require_once( $_template_file );
     1033    else
     1034        require( $_template_file );
    10301035}
    10311036
Note: See TracChangeset for help on using the changeset viewer.