WordPress.org

Make WordPress Core

Changeset 44725


Ignore:
Timestamp:
02/06/2019 06:36:49 PM (7 months ago)
Author:
desrosj
Message:

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

Because the names of the get_header(), get_footer(), get_sidebar(), and get_template_part() functions indicate that a value is returned, some plugins and themes already have echo get_template_part() in their codebase. Adding a return value to these functions using the approach in [44678] will cause the two unintended side effects of unexpected content being sent to the browser, and accidental path disclosure.

Reverts [44678].

Props davidbinda.
See #40969.

File:
1 edited

Legend:

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

    r44678 r44725  
    1717 *
    1818 * @since 1.5.0
    19  * @since 5.1.0 Added the return value.
    2019 *
    2120 * @param string $name The name of the specialised header.
    22  * @return string The template filename if one is located.
    2321 */
    2422function get_header( $name = null ) {
     
    4139    $templates[] = 'header.php';
    4240
    43     return locate_template( $templates, true );
     41    locate_template( $templates, true );
    4442}
    4543
     
    5452 *
    5553 * @since 1.5.0
    56  * @since 5.1.0 Added the return value.
    5754 *
    5855 * @param string $name The name of the specialised footer.
    59  * @return string The template filename if one is located.
    6056 */
    6157function get_footer( $name = null ) {
     
    7874    $templates[] = 'footer.php';
    7975
    80     return locate_template( $templates, true );
     76    locate_template( $templates, true );
    8177}
    8278
     
    9187 *
    9288 * @since 1.5.0
    93  * @since 5.1.0 Added the return value.
    9489 *
    9590 * @param string $name The name of the specialised sidebar.
    96  * @return string The template filename if one is located.
    9791 */
    9892function get_sidebar( $name = null ) {
     
    115109    $templates[] = 'sidebar.php';
    116110
    117     return locate_template( $templates, true );
     111    locate_template( $templates, true );
    118112}
    119113
     
    135129 *
    136130 * @since 3.0.0
    137  * @since 5.1.0 Added the return value.
    138131 *
    139132 * @param string $slug The slug name for the generic template.
    140133 * @param string $name The name of the specialised template.
    141  * @return string The template filename if one is located.
    142134 */
    143135function get_template_part( $slug, $name = null ) {
     
    163155    $templates[] = "{$slug}.php";
    164156
    165     return locate_template( $templates, true, false );
     157    locate_template( $templates, true, false );
    166158}
    167159
Note: See TracChangeset for help on using the changeset viewer.