WordPress.org

Make WordPress Core

Changeset 44678


Ignore:
Timestamp:
01/21/2019 09:59:44 PM (6 months ago)
Author:
pento
Message:

Themes: Return the value of locate_template() in functions that call it.

The get_header(), get_footer(), get_sidebar(), and get_template_part() functions all call locate_template() as their final action, which returns the name of the template being loaded. Returning this value helps handle problems with templates being loaded.

Props tferry.
Fixes #40969.

File:
1 edited

Legend:

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

    r44644 r44678  
    1717 *
    1818 * @since 1.5.0
     19 * @since 5.1.0 Added the return value.
    1920 *
    2021 * @param string $name The name of the specialised header.
     22 * @return string The template filename if one is located.
    2123 */
    2224function get_header( $name = null ) {
     
    3941    $templates[] = 'header.php';
    4042
    41     locate_template( $templates, true );
     43    return locate_template( $templates, true );
    4244}
    4345
     
    5254 *
    5355 * @since 1.5.0
     56 * @since 5.1.0 Added the return value.
    5457 *
    5558 * @param string $name The name of the specialised footer.
     59 * @return string The template filename if one is located.
    5660 */
    5761function get_footer( $name = null ) {
     
    7478    $templates[] = 'footer.php';
    7579
    76     locate_template( $templates, true );
     80    return locate_template( $templates, true );
    7781}
    7882
     
    8791 *
    8892 * @since 1.5.0
     93 * @since 5.1.0 Added the return value.
    8994 *
    9095 * @param string $name The name of the specialised sidebar.
     96 * @return string The template filename if one is located.
    9197 */
    9298function get_sidebar( $name = null ) {
     
    109115    $templates[] = 'sidebar.php';
    110116
    111     locate_template( $templates, true );
     117    return locate_template( $templates, true );
    112118}
    113119
     
    129135 *
    130136 * @since 3.0.0
     137 * @since 5.1.0 Added the return value.
    131138 *
    132139 * @param string $slug The slug name for the generic template.
    133140 * @param string $name The name of the specialised template.
     141 * @return string The template filename if one is located.
    134142 */
    135143function get_template_part( $slug, $name = null ) {
     
    155163    $templates[] = "{$slug}.php";
    156164
    157     locate_template( $templates, true, false );
     165    return locate_template( $templates, true, false );
    158166}
    159167
Note: See TracChangeset for help on using the changeset viewer.