Changeset 48209
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r48199 r48209 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 ) { … … 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 … … 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 ) { … … 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 … … 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 ) { … … 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 … … 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 ) { … … 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 -
trunk/tests/phpunit/tests/general/template.php
r47288 r48209 632 632 * @ticket 40969 633 633 */ 634 function test_get_template_part_returns_nothing() { 635 ob_start(); 634 function test_get_header_returns_nothing_on_success() { 635 $this->expectOutputRegex( '/Header/' ); 636 637 // The `get_header()` function must not return anything 638 // due to themes in the wild that may echo its return value. 639 $this->assertNull( get_header() ); 640 } 641 642 /** 643 * @ticket 40969 644 */ 645 function test_get_footer_returns_nothing_on_success() { 646 $this->expectOutputRegex( '/Footer/' ); 647 648 // The `get_footer()` function must not return anything 649 // due to themes in the wild that may echo its return value. 650 $this->assertNull( get_footer() ); 651 } 652 653 /** 654 * @ticket 40969 655 */ 656 function test_get_sidebar_returns_nothing_on_success() { 657 $this->expectOutputRegex( '/Sidebar/' ); 658 659 // The `get_sidebar()` function must not return anything 660 // due to themes in the wild that may echo its return value. 661 $this->assertNull( get_sidebar() ); 662 } 663 664 /** 665 * @ticket 40969 666 */ 667 function test_get_template_part_returns_nothing_on_success() { 668 $this->expectOutputRegex( '/Template Part/' ); 636 669 637 670 // The `get_template_part()` function must not return anything 638 671 // due to themes in the wild that echo its return value. 639 $part = get_template_part( 'template', 'part' ); 640 $output = ob_get_clean(); 641 642 self::assertSame( 'Template Part', trim( $output ) ); 643 self::assertSame( null, $part ); 672 $this->assertNull( get_template_part( 'template', 'part' ) ); 673 } 674 675 /** 676 * @ticket 40969 677 */ 678 function test_get_template_part_returns_false_on_failure() { 679 $this->assertFalse( get_template_part( 'non-existing-template' ) ); 644 680 } 645 681 }
Note: See TracChangeset
for help on using the changeset viewer.