Ticket #41057: 41057-src-wp-includes-template.patch
File 41057-src-wp-includes-template.patch, 6.7 KB (added by , 8 years ago) |
---|
-
src/wp-includes/template.php
16 16 * 17 17 * @since 1.5.0 18 18 * 19 * @param string $type Filename without extension. 20 * @param array $templates An optional list of template candidates 19 * @param string $type Filename without extension. 20 * @param array $templates An optional list of template candidates 21 * 21 22 * @return string Full path to template file. 22 23 */ 23 24 function get_query_template( $type, $templates = array() ) { 24 25 $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); 25 26 26 if ( empty( $templates ) ) 27 $templates = array("{$type}.php"); 27 if ( empty( $templates ) ) { 28 $templates = array( "{$type}.php" ); 29 } 28 30 29 31 /** 30 32 * Filters the list of template filenames that are searched for when retrieving a template to use. … … 55 57 * @since 1.5.0 56 58 * @since 4.8.0 The `$type` and `$templates` parameters were added. 57 59 * 58 * @param string $template 59 * @param string $type 60 * @param array 60 * @param string $template Path to the template. See locate_template(). 61 * @param string $type Filename without extension. 62 * @param array $templates A list of template candidates, in descending order of priority. 61 63 */ 62 64 return apply_filters( "{$type}_template", $template, $type, $templates ); 63 65 } … … 75 77 * @return string Full path to index template file. 76 78 */ 77 79 function get_index_template() { 78 return get_query_template( 'index');80 return get_query_template( 'index' ); 79 81 } 80 82 81 83 /** … … 91 93 * @return string Full path to 404 template file. 92 94 */ 93 95 function get_404_template() { 94 return get_query_template( '404');96 return get_query_template( '404' ); 95 97 } 96 98 97 99 /** … … 112 114 $templates = array(); 113 115 114 116 if ( count( $post_types ) == 1 ) { 115 $post_type = reset( $post_types );117 $post_type = reset( $post_types ); 116 118 $templates[] = "archive-{$post_type}.php"; 117 119 } 118 120 $templates[] = 'archive.php'; … … 134 136 */ 135 137 function get_post_type_archive_template() { 136 138 $post_type = get_query_var( 'post_type' ); 137 if ( is_array( $post_type ) ) 139 if ( is_array( $post_type ) ) { 138 140 $post_type = reset( $post_type ); 141 } 139 142 140 143 $obj = get_post_type_object( $post_type ); 141 144 if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) { … … 335 338 * @return string Full path to date template file. 336 339 */ 337 340 function get_date_template() { 338 return get_query_template( 'date');341 return get_query_template( 'date' ); 339 342 } 340 343 341 344 /** … … 369 372 * @return string Full path to front page template file. 370 373 */ 371 374 function get_front_page_template() { 372 $templates = array( 'front-page.php');375 $templates = array( 'front-page.php' ); 373 376 374 377 return get_query_template( 'front_page', $templates ); 375 378 } … … 403 406 * @return string Full path to page template file. 404 407 */ 405 408 function get_page_template() { 406 $id = get_queried_object_id();409 $id = get_queried_object_id(); 407 410 $template = get_page_template_slug(); 408 $pagename = get_query_var( 'pagename');411 $pagename = get_query_var( 'pagename' ); 409 412 410 413 if ( ! $pagename && $id ) { 411 414 // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object 412 415 $post = get_queried_object(); 413 if ( $post ) 416 if ( $post ) { 414 417 $pagename = $post->post_name; 418 } 415 419 } 416 420 417 421 $templates = array(); 418 if ( $template && 0 === validate_file( $template ) ) 422 if ( $template && 0 === validate_file( $template ) ) { 419 423 $templates[] = $template; 424 } 420 425 if ( $pagename ) { 421 426 $pagename_decoded = urldecode( $pagename ); 422 427 if ( $pagename_decoded !== $pagename ) { … … 424 429 } 425 430 $templates[] = "page-{$pagename}.php"; 426 431 } 427 if ( $id ) 432 if ( $id ) { 428 433 $templates[] = "page-{$id}.php"; 434 } 429 435 $templates[] = 'page.php'; 430 436 431 437 return get_query_template( 'page', $templates ); … … 444 450 * @return string Full path to search template file. 445 451 */ 446 452 function get_search_template() { 447 return get_query_template( 'search');453 return get_query_template( 'search' ); 448 454 } 449 455 450 456 /** … … 622 628 * @since 2.7.0 623 629 * 624 630 * @param string|array $template_names Template file(s) to search for, in order. 625 * @param bool $load If true the template file will be loaded if it is found. 626 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 631 * @param bool $load If true the template file will be loaded if it is found. 632 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. 633 * 627 634 * @return string The template filename if one is located. 628 635 */ 629 function locate_template( $template_names, $load = false, $require_once = true ) {636 function locate_template( $template_names, $load = false, $require_once = true ) { 630 637 $located = ''; 631 638 foreach ( (array) $template_names as $template_name ) { 632 if ( ! $template_name )639 if ( ! $template_name ) { 633 640 continue; 634 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { 641 } 642 if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { 635 643 $located = STYLESHEETPATH . '/' . $template_name; 636 644 break; 637 } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name) ) {645 } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { 638 646 $located = TEMPLATEPATH . '/' . $template_name; 639 647 break; 640 648 } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { … … 643 651 } 644 652 } 645 653 646 if ( $load && '' != $located ) 654 if ( $load && '' != $located ) { 647 655 load_template( $located, $require_once ); 656 } 648 657 649 658 return $located; 650 659 } … … 658 667 * 659 668 * @since 1.5.0 660 669 * 661 * @global array 662 * @global WP_Post 663 * @global bool 664 * @global WP_Query 670 * @global array $posts 671 * @global WP_Post $post 672 * @global bool $wp_did_header 673 * @global WP_Query $wp_query 665 674 * @global WP_Rewrite $wp_rewrite 666 * @global wpdb 667 * @global string 668 * @global WP 669 * @global int 675 * @global wpdb $wpdb 676 * @global string $wp_version 677 * @global WP $wp 678 * @global int $id 670 679 * @global WP_Comment $comment 671 * @global int 680 * @global int $user_ID 672 681 * 673 682 * @param string $_template_file Path to template file. 674 * @param bool $require_onceWhether to require_once or require. Default true.683 * @param bool $require_once Whether to require_once or require. Default true. 675 684 */ 676 685 function load_template( $_template_file, $require_once = true ) { 677 686 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;