Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", '<?php', '<?', '?>' ),
array( "\n", '', '', '' ),
$file_data
);

/**
* Filters extra file headers by context.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<? # Template Name: Short Tag Template ?>
24 changes: 24 additions & 0 deletions tests/phpunit/tests/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <?php open tag.
*
* @ticket 42517
* @covers ::get_file_data
*/
public function test_get_file_data_with_single_line_php_open_tag() {
$headers = array( 'TemplateName' => '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 <? short open tag.
*
* @ticket 42517
* @covers ::get_file_data
*/
public function test_get_file_data_with_single_line_short_open_tag() {
$headers = array( 'TemplateName' => '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;

Expand Down
Loading