diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index 82c138cef7..92bd32f683 100644
|
a
|
b
|
|
| 16 | 16 | * "special". |
| 17 | 17 | * |
| 18 | 18 | * @since 1.5.0 |
| | 19 | * @since 5.5.0 A return value was added. |
| 19 | 20 | * |
| 20 | 21 | * @param string $name The name of the specialised header. |
| | 22 | * @return void|false Void on success, false if the template does not exist. |
| 21 | 23 | */ |
| 22 | 24 | function get_header( $name = null ) { |
| 23 | 25 | /** |
| … |
… |
function get_header( $name = null ) { |
| 38 | 40 | |
| 39 | 41 | $templates[] = 'header.php'; |
| 40 | 42 | |
| 41 | | locate_template( $templates, true ); |
| | 43 | if ( ! locate_template( $templates, true ) ) { |
| | 44 | return false; |
| | 45 | } |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | 48 | /** |
| … |
… |
function get_header( $name = null ) { |
| 51 | 55 | * "special". |
| 52 | 56 | * |
| 53 | 57 | * @since 1.5.0 |
| | 58 | * @since 5.5.0 A return value was added. |
| 54 | 59 | * |
| 55 | 60 | * @param string $name The name of the specialised footer. |
| | 61 | * @return void|false Void on success, false if the template does not exist. |
| 56 | 62 | */ |
| 57 | 63 | function get_footer( $name = null ) { |
| 58 | 64 | /** |
| … |
… |
function get_footer( $name = null ) { |
| 73 | 79 | |
| 74 | 80 | $templates[] = 'footer.php'; |
| 75 | 81 | |
| 76 | | locate_template( $templates, true ); |
| | 82 | if ( ! locate_template( $templates, true ) ) { |
| | 83 | return false; |
| | 84 | } |
| 77 | 85 | } |
| 78 | 86 | |
| 79 | 87 | /** |
| … |
… |
function get_footer( $name = null ) { |
| 86 | 94 | * "special". |
| 87 | 95 | * |
| 88 | 96 | * @since 1.5.0 |
| | 97 | * @since 5.5.0 A return value was added. |
| 89 | 98 | * |
| 90 | 99 | * @param string $name The name of the specialised sidebar. |
| | 100 | * @return void|false Void on success, false if the template does not exist. |
| 91 | 101 | */ |
| 92 | 102 | function get_sidebar( $name = null ) { |
| 93 | 103 | /** |
| … |
… |
function get_sidebar( $name = null ) { |
| 108 | 118 | |
| 109 | 119 | $templates[] = 'sidebar.php'; |
| 110 | 120 | |
| 111 | | locate_template( $templates, true ); |
| | 121 | if ( ! locate_template( $templates, true ) ) { |
| | 122 | return false; |
| | 123 | } |
| 112 | 124 | } |
| 113 | 125 | |
| 114 | 126 | /** |
| … |
… |
function get_sidebar( $name = null ) { |
| 128 | 140 | * "special". |
| 129 | 141 | * |
| 130 | 142 | * @since 3.0.0 |
| | 143 | * @since 5.5.0 A return value was added. |
| 131 | 144 | * |
| 132 | 145 | * @param string $slug The slug name for the generic template. |
| 133 | 146 | * @param string $name The name of the specialised template. |
| | 147 | * @return void|false Void on success, false if the template does not exist. |
| 134 | 148 | */ |
| 135 | 149 | function get_template_part( $slug, $name = null ) { |
| 136 | 150 | /** |
| … |
… |
function get_template_part( $slug, $name = null ) { |
| 165 | 179 | */ |
| 166 | 180 | do_action( 'get_template_part', $slug, $name, $templates ); |
| 167 | 181 | |
| 168 | | locate_template( $templates, true, false ); |
| | 182 | if ( ! locate_template( $templates, true, false ) ) { |
| | 183 | return false; |
| | 184 | } |
| 169 | 185 | } |
| 170 | 186 | |
| 171 | 187 | /** |
diff --git a/tests/phpunit/data/themedir1/default/footer.php b/tests/phpunit/data/themedir1/default/footer.php
new file mode 100644
index 0000000000..e36f7f7118
diff --git a/tests/phpunit/data/themedir1/default/header.php b/tests/phpunit/data/themedir1/default/header.php
new file mode 100644
index 0000000000..74fcd1a347
diff --git a/tests/phpunit/data/themedir1/default/sidebar.php b/tests/phpunit/data/themedir1/default/sidebar.php
new file mode 100644
index 0000000000..96438493b6
diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php
index 170a86d9f9..de1be4f0b7 100644
|
a
|
b
|
class Tests_General_Template extends WP_UnitTestCase { |
| 631 | 631 | /** |
| 632 | 632 | * @ticket 40969 |
| 633 | 633 | */ |
| 634 | | function test_get_template_part_returns_nothing() { |
| 635 | | ob_start(); |
| | 634 | function test_get_template_part_returns_nothing_on_success() { |
| | 635 | $this->expectOutputRegex( '/^Template Part$/' ); |
| 636 | 636 | |
| 637 | 637 | // The `get_template_part()` function must not return anything |
| 638 | 638 | // due to themes in the wild that echo its return value. |
| 639 | | $part = get_template_part( 'template', 'part' ); |
| 640 | | $output = ob_get_clean(); |
| | 639 | $this->assertNull( get_template_part( 'template', 'part' ) ); |
| | 640 | } |
| | 641 | |
| | 642 | /** |
| | 643 | * @ticket 40969 |
| | 644 | */ |
| | 645 | function test_get_template_part_returns_false_on_failure() { |
| | 646 | $this->assertFalse( get_template_part( 'non-existing-template' ) ); |
| | 647 | } |
| | 648 | |
| | 649 | /** |
| | 650 | * @ticket 40969 |
| | 651 | */ |
| | 652 | function test_get_header_returns_nothing_on_success() { |
| | 653 | $this->expectOutputRegex( '/^Header$/' ); |
| | 654 | |
| | 655 | // The `get_header()` function must not return anything |
| | 656 | // due to themes in the wild that may echo its return value. |
| | 657 | $this->assertNull( get_header() ); |
| | 658 | } |
| | 659 | |
| | 660 | /** |
| | 661 | * @ticket 40969 |
| | 662 | */ |
| | 663 | function test_get_footer_returns_nothing_on_success() { |
| | 664 | $this->expectOutputRegex( '/^Footer$/' ); |
| | 665 | |
| | 666 | // The `get_footer()` function must not return anything |
| | 667 | // due to themes in the wild that may echo its return value. |
| | 668 | $this->assertNull( get_footer() ); |
| | 669 | } |
| | 670 | |
| | 671 | /** |
| | 672 | * @ticket 40969 |
| | 673 | */ |
| | 674 | function test_get_sidebar_returns_nothing_on_success() { |
| | 675 | $this->expectOutputRegex( '/^Sidebar$/' ); |
| 641 | 676 | |
| 642 | | self::assertSame( 'Template Part', trim( $output ) ); |
| 643 | | self::assertSame( null, $part ); |
| | 677 | // The `get_sidebar()` function must not return anything |
| | 678 | // due to themes in the wild that may echo its return value. |
| | 679 | $this->assertNull( get_sidebar() ); |
| 644 | 680 | } |
| 645 | 681 | } |