Make WordPress Core

Ticket #41057: 41057-src-wp-includes-template.patch

File 41057-src-wp-includes-template.patch, 6.7 KB (added by Dency, 8 years ago)
  • src/wp-includes/template.php

     
    1616 *
    1717 * @since 1.5.0
    1818 *
    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 *
    2122 * @return string Full path to template file.
    2223 */
    2324function get_query_template( $type, $templates = array() ) {
    2425        $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
    2526
    26         if ( empty( $templates ) )
    27                 $templates = array("{$type}.php");
     27        if ( empty( $templates ) ) {
     28                $templates = array( "{$type}.php" );
     29        }
    2830
    2931        /**
    3032         * Filters the list of template filenames that are searched for when retrieving a template to use.
     
    5557         * @since 1.5.0
    5658         * @since 4.8.0 The `$type` and `$templates` parameters were added.
    5759         *
    58          * @param string $template  Path to the template. See locate_template().
    59          * @param string $type      Filename without extension.
    60          * @param array  $templates A list of template candidates, in descending order of priority.
     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.
    6163         */
    6264        return apply_filters( "{$type}_template", $template, $type, $templates );
    6365}
     
    7577 * @return string Full path to index template file.
    7678 */
    7779function get_index_template() {
    78         return get_query_template('index');
     80        return get_query_template( 'index' );
    7981}
    8082
    8183/**
     
    9193 * @return string Full path to 404 template file.
    9294 */
    9395function get_404_template() {
    94         return get_query_template('404');
     96        return get_query_template( '404' );
    9597}
    9698
    9799/**
     
    112114        $templates = array();
    113115
    114116        if ( count( $post_types ) == 1 ) {
    115                 $post_type = reset( $post_types );
     117                $post_type   = reset( $post_types );
    116118                $templates[] = "archive-{$post_type}.php";
    117119        }
    118120        $templates[] = 'archive.php';
     
    134136 */
    135137function get_post_type_archive_template() {
    136138        $post_type = get_query_var( 'post_type' );
    137         if ( is_array( $post_type ) )
     139        if ( is_array( $post_type ) ) {
    138140                $post_type = reset( $post_type );
     141        }
    139142
    140143        $obj = get_post_type_object( $post_type );
    141144        if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) {
     
    335338 * @return string Full path to date template file.
    336339 */
    337340function get_date_template() {
    338         return get_query_template('date');
     341        return get_query_template( 'date' );
    339342}
    340343
    341344/**
     
    369372 * @return string Full path to front page template file.
    370373 */
    371374function get_front_page_template() {
    372         $templates = array('front-page.php');
     375        $templates = array( 'front-page.php' );
    373376
    374377        return get_query_template( 'front_page', $templates );
    375378}
     
    403406 * @return string Full path to page template file.
    404407 */
    405408function get_page_template() {
    406         $id = get_queried_object_id();
     409        $id       = get_queried_object_id();
    407410        $template = get_page_template_slug();
    408         $pagename = get_query_var('pagename');
     411        $pagename = get_query_var( 'pagename' );
    409412
    410413        if ( ! $pagename && $id ) {
    411414                // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
    412415                $post = get_queried_object();
    413                 if ( $post )
     416                if ( $post ) {
    414417                        $pagename = $post->post_name;
     418                }
    415419        }
    416420
    417421        $templates = array();
    418         if ( $template && 0 === validate_file( $template ) )
     422        if ( $template && 0 === validate_file( $template ) ) {
    419423                $templates[] = $template;
     424        }
    420425        if ( $pagename ) {
    421426                $pagename_decoded = urldecode( $pagename );
    422427                if ( $pagename_decoded !== $pagename ) {
     
    424429                }
    425430                $templates[] = "page-{$pagename}.php";
    426431        }
    427         if ( $id )
     432        if ( $id ) {
    428433                $templates[] = "page-{$id}.php";
     434        }
    429435        $templates[] = 'page.php';
    430436
    431437        return get_query_template( 'page', $templates );
     
    444450 * @return string Full path to search template file.
    445451 */
    446452function get_search_template() {
    447         return get_query_template('search');
     453        return get_query_template( 'search' );
    448454}
    449455
    450456/**
     
    622628 * @since 2.7.0
    623629 *
    624630 * @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 *
    627634 * @return string The template filename if one is located.
    628635 */
    629 function locate_template($template_names, $load = false, $require_once = true ) {
     636function locate_template( $template_names, $load = false, $require_once = true ) {
    630637        $located = '';
    631638        foreach ( (array) $template_names as $template_name ) {
    632                 if ( !$template_name )
     639                if ( ! $template_name ) {
    633640                        continue;
    634                 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
     641                }
     642                if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
    635643                        $located = STYLESHEETPATH . '/' . $template_name;
    636644                        break;
    637                 } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
     645                } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
    638646                        $located = TEMPLATEPATH . '/' . $template_name;
    639647                        break;
    640648                } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
     
    643651                }
    644652        }
    645653
    646         if ( $load && '' != $located )
     654        if ( $load && '' != $located ) {
    647655                load_template( $located, $require_once );
     656        }
    648657
    649658        return $located;
    650659}
     
    658667 *
    659668 * @since 1.5.0
    660669 *
    661  * @global array      $posts
    662  * @global WP_Post    $post
    663  * @global bool       $wp_did_header
    664  * @global WP_Query   $wp_query
     670 * @global array $posts
     671 * @global WP_Post $post
     672 * @global bool $wp_did_header
     673 * @global WP_Query $wp_query
    665674 * @global WP_Rewrite $wp_rewrite
    666  * @global wpdb       $wpdb
    667  * @global string     $wp_version
    668  * @global WP         $wp
    669  * @global int        $id
     675 * @global wpdb $wpdb
     676 * @global string $wp_version
     677 * @global WP $wp
     678 * @global int $id
    670679 * @global WP_Comment $comment
    671  * @global int        $user_ID
     680 * @global int $user_ID
    672681 *
    673682 * @param string $_template_file Path to template file.
    674  * @param bool   $require_once  Whether to require_once or require. Default true.
     683 * @param bool $require_once Whether to require_once or require. Default true.
    675684 */
    676685function load_template( $_template_file, $require_once = true ) {
    677686        global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;