diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index c806d46624..f8844d4625 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -535,7 +535,7 @@ final class WP_Theme implements ArrayAccess { * @since 3.4.0 * * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. - * @return string String on success, false on failure. + * @return string|bool String on success, false on failure. */ public function get( $header ) { if ( ! isset( $this->headers[ $header ] ) ) @@ -571,10 +571,13 @@ final class WP_Theme implements ArrayAccess { * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. * @param bool $markup Optional. Whether to mark up the header. Defaults to true. * @param bool $translate Optional. Whether to translate the header. Defaults to true. - * @return string Processed header, false on failure. + * @return string|bool Processed header, false on failure. */ public function display( $header, $markup = true, $translate = true ) { $value = $this->get( $header ); + if ( false === $value ) { + return false; + } if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) $translate = false; diff --git a/tests/phpunit/tests/theme/WPTheme.php b/tests/phpunit/tests/theme/WPTheme.php index 4dbad859d4..16e093a952 100644 --- a/tests/phpunit/tests/theme/WPTheme.php +++ b/tests/phpunit/tests/theme/WPTheme.php @@ -128,4 +128,15 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { function filter_theme_with_spaces() { return 'subdir/theme with spaces'; } + + /** + * @ticket 26873 + */ + function test_display_method_on_get_method_failure() { + $theme = new WP_Theme( 'nonexistent', $this->theme_root ); + $this->assertEquals( 'nonexistent', $theme->get( 'Name' ) ); + $this->assertFalse( $theme->get( 'AuthorURI' ) ); + $this->assertFalse( $theme->get( 'Tags' ) ); + $this->assertFalse( $theme->display( 'Tags' ) ); + } }