WordPress.org

Make WordPress Core

Ticket #40969: 40969.7.diff

File 40969.7.diff, 2.9 KB (added by SergeyBiryukov, 21 months ago)
  • src/wp-includes/general-template.php

     
    1616 * "special".
    1717 *
    1818 * @since 1.5.0
     19 * @since 5.4.0 A return value was added.
    1920 *
    2021 * @param string $name The name of the specialised header.
     22 * @return void|false Void on success, false if the template does not exist.
    2123 */
    2224function get_header( $name = null ) {
    2325        /**
     
    3840
    3941        $templates[] = 'header.php';
    4042
    41         locate_template( $templates, true );
     43        if ( ! locate_template( $templates, true ) ) {
     44                return false;
     45        }
    4246}
    4347
    4448/**
     
    5155 * "special".
    5256 *
    5357 * @since 1.5.0
     58 * @since 5.4.0 A return value was added.
    5459 *
    5560 * @param string $name The name of the specialised footer.
     61 * @return void|false Void on success, false if the template does not exist.
    5662 */
    5763function get_footer( $name = null ) {
    5864        /**
     
    7379
    7480        $templates[] = 'footer.php';
    7581
    76         locate_template( $templates, true );
     82        if ( ! locate_template( $templates, true ) ) {
     83                return false;
     84        }
    7785}
    7886
    7987/**
     
    8694 * "special".
    8795 *
    8896 * @since 1.5.0
     97 * @since 5.4.0 A return value was added.
    8998 *
    9099 * @param string $name The name of the specialised sidebar.
     100 * @return void|false Void on success, false if the template does not exist.
    91101 */
    92102function get_sidebar( $name = null ) {
    93103        /**
     
    108118
    109119        $templates[] = 'sidebar.php';
    110120
    111         locate_template( $templates, true );
     121        if ( ! locate_template( $templates, true ) ) {
     122                return false;
     123        }
    112124}
    113125
    114126/**
     
    128140 * "special".
    129141 *
    130142 * @since 3.0.0
     143 * @since 5.4.0 A return value was added.
    131144 *
    132145 * @param string $slug The slug name for the generic template.
    133146 * @param string $name The name of the specialised template.
     147 * @return void|false Void on success, false if the template does not exist.
    134148 */
    135149function get_template_part( $slug, $name = null ) {
    136150        /**
     
    165179         */
    166180        do_action( 'get_template_part', $slug, $name, $templates );
    167181
    168         locate_template( $templates, true, false );
     182        if ( ! locate_template( $templates, true, false ) ) {
     183                return false;
     184        }
    169185}
    170186
    171187/**
  • tests/phpunit/tests/general/template.php

     
    631631        /**
    632632         * @ticket 40969
    633633         */
    634         function test_get_template_part_returns_nothing() {
     634        function test_get_template_part_returns_nothing_on_success() {
    635635                ob_start();
    636636
    637637                // The `get_template_part()` function must not return anything
     
    642642                self::assertSame( 'Template Part', trim( $output ) );
    643643                self::assertSame( null, $part );
    644644        }
     645
     646        /**
     647         * @ticket 40969
     648         */
     649        function test_get_template_part_returns_false_on_failure() {
     650                self::assertSame( false, get_template_part( 'non-existing-template' ) );
     651        }
    645652}