diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 7d71c8c56963d..7a8abb2b6b176 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -6954,8 +6954,12 @@ function get_file_data( $file, $default_headers, $context = '' ) { $file_data = ''; } - // Make sure we catch CR-only line endings. - $file_data = str_replace( "\r", "\n", $file_data ); + // Make sure we catch CR-only line endings and strip PHP open/close tags. + $file_data = str_replace( + array( "\r", '' ), + array( "\n", '', '', '' ), + $file_data + ); /** * Filters extra file headers by context. diff --git a/tests/phpunit/data/formatting/file-header-short-open-tag.php b/tests/phpunit/data/formatting/file-header-short-open-tag.php new file mode 100644 index 0000000000000..b2353ea6a4502 --- /dev/null +++ b/tests/phpunit/data/formatting/file-header-short-open-tag.php @@ -0,0 +1 @@ + diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php index 9a29e4e67669a..1f416a8a74b64 100644 --- a/tests/phpunit/tests/file.php +++ b/tests/phpunit/tests/file.php @@ -95,6 +95,30 @@ public function test_get_file_data_with_php_open_tag_prefix() { } } + /** + * Tests that get_file_data() supports single-line headers with a 'Template Name' ); + $actual = get_file_data( DIR_TESTDATA . '/themedir1/page-templates/template-header.php', $headers ); + $this->assertSame( 'This Template Header Is On One Line', $actual['TemplateName'] ); + } + + /** + * Tests that get_file_data() supports single-line headers with a 'Template Name' ); + $actual = get_file_data( DIR_TESTDATA . '/formatting/file-header-short-open-tag.php', $headers ); + $this->assertSame( 'Short Tag Template', $actual['TemplateName'] ); + } + private function is_unique_writable_file( $path, $filename ) { $fullpath = $path . DIRECTORY_SEPARATOR . $filename;