Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r40964 r42343  
    2424    $type = preg_replace( '|[^a-z0-9-]+|', '', $type );
    2525
    26     if ( empty( $templates ) )
    27         $templates = array("{$type}.php");
     26    if ( empty( $templates ) ) {
     27        $templates = array( "{$type}.php" );
     28    }
    2829
    2930    /**
     
    7677 */
    7778function get_index_template() {
    78     return get_query_template('index');
     79    return get_query_template( 'index' );
    7980}
    8081
     
    9293 */
    9394function get_404_template() {
    94     return get_query_template('404');
     95    return get_query_template( '404' );
    9596}
    9697
     
    113114
    114115    if ( count( $post_types ) == 1 ) {
    115         $post_type = reset( $post_types );
     116        $post_type   = reset( $post_types );
    116117        $templates[] = "archive-{$post_type}.php";
    117118    }
     
    135136function get_post_type_archive_template() {
    136137    $post_type = get_query_var( 'post_type' );
    137     if ( is_array( $post_type ) )
     138    if ( is_array( $post_type ) ) {
    138139        $post_type = reset( $post_type );
     140    }
    139141
    140142    $obj = get_post_type_object( $post_type );
     
    336338 */
    337339function get_date_template() {
    338     return get_query_template('date');
     340    return get_query_template( 'date' );
    339341}
    340342
     
    370372 */
    371373function get_front_page_template() {
    372     $templates = array('front-page.php');
     374    $templates = array( 'front-page.php' );
    373375
    374376    return get_query_template( 'front_page', $templates );
     
    404406 */
    405407function get_page_template() {
    406     $id = get_queried_object_id();
     408    $id       = get_queried_object_id();
    407409    $template = get_page_template_slug();
    408     $pagename = get_query_var('pagename');
     410    $pagename = get_query_var( 'pagename' );
    409411
    410412    if ( ! $pagename && $id ) {
    411413        // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
    412414        $post = get_queried_object();
    413         if ( $post )
     415        if ( $post ) {
    414416            $pagename = $post->post_name;
    415     }
    416 
    417     $templates = array();
    418     if ( $template && 0 === validate_file( $template ) )
     417        }
     418    }
     419
     420    $templates = array();
     421    if ( $template && 0 === validate_file( $template ) ) {
    419422        $templates[] = $template;
     423    }
    420424    if ( $pagename ) {
    421425        $pagename_decoded = urldecode( $pagename );
     
    425429        $templates[] = "page-{$pagename}.php";
    426430    }
    427     if ( $id )
     431    if ( $id ) {
    428432        $templates[] = "page-{$id}.php";
     433    }
    429434    $templates[] = 'page.php';
    430435
     
    445450 */
    446451function get_search_template() {
    447     return get_query_template('search');
     452    return get_query_template( 'search' );
    448453}
    449454
     
    499504    }
    500505
    501     $templates[] = "single.php";
     506    $templates[] = 'single.php';
    502507
    503508    return get_query_template( 'single', $templates );
     
    541546    }
    542547
    543     $templates[] = "embed.php";
     548    $templates[] = 'embed.php';
    544549
    545550    return get_query_template( 'embed', $templates );
     
    627632 * @return string The template filename if one is located.
    628633 */
    629 function locate_template($template_names, $load = false, $require_once = true ) {
     634function locate_template( $template_names, $load = false, $require_once = true ) {
    630635    $located = '';
    631636    foreach ( (array) $template_names as $template_name ) {
    632         if ( !$template_name )
     637        if ( ! $template_name ) {
    633638            continue;
    634         if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
     639        }
     640        if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
    635641            $located = STYLESHEETPATH . '/' . $template_name;
    636642            break;
    637         } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
     643        } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
    638644            $located = TEMPLATEPATH . '/' . $template_name;
    639645            break;
     
    644650    }
    645651
    646     if ( $load && '' != $located )
     652    if ( $load && '' != $located ) {
    647653        load_template( $located, $require_once );
     654    }
    648655
    649656    return $located;
Note: See TracChangeset for help on using the changeset viewer.