Make WordPress Core

Opened 6 years ago

Closed 19 months ago

#45880 closed defect (bug) (duplicate)

Twenty Seventeen: edit-form-blocks.php shows Warning when $editor_styles include blank element.

Reported by: atachibana's profile atachibana Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0.2
Component: Bundled Theme Keywords: has-patch
Focuses: Cc:

Description

Environment:

  • Windows 10 Japanese (64bit) UAC off
  • XAMPP for Windows 7.3 (PHP 7.3)
  • WordPress 5.0.2
  • Theme: Twenty Seventeen
  • Plugin: None

Reproduction:

  1. Setup WordPress on Windows (XAMPP environment).
  2. Select Twenty Seventeen Theme
  3. Select Japanese from Language Settings ('日本語')
  4. Select New Post ('投稿' > '新規追加')

You will see Warning messages are flushed twice with same message but different format, and editor screen is displayed (See attached images for real displayed strings)

Warning: file_get_contents(C:\xampp\htdocs\wordpress/wp-content/themes/twentyseventeen): failed to open stream:
Permission denied in C:\xampp\htdocs\wordpress\wp-admin\edit-form-blocks.php on line 200

This warning is not shown

  • if language is English, or
  • if theme is Twenty Nineteen or Twenty Sixteen, or
  • if Classic Editor

Attachments (4)

winja_17_error1.jpg (26.1 KB) - added by atachibana 6 years ago.
#1 shown warning
winja_17_error2.jpg (13.0 KB) - added by atachibana 6 years ago.
2nd shown warning
edit-form-blocks.diff (402 bytes) - added by atachibana 6 years ago.
Added string check
45880.diff (1.8 KB) - added by noisysocks 4 years ago.

Download all attachments as: .zip

Change History (8)

@atachibana
6 years ago

#1 shown warning

@atachibana
6 years ago

2nd shown warning

#1 @atachibana
6 years ago

The global variable $editor_styles in English settings has font information in 2nd element:

(
    [0] => assets/css/editor-style.css
    [1] => https://fonts.googleapis.com/css?family=Libre+Franklin%3A300%2C300i%2C400%2C400i%2C600%2C600i%2C800%2C800i&subset=latin%2Clatin-ext
)

But in Japanese environment no value.

(
    [0] => assets/css/editor-style.css
    [1] => 
)

This blank value failed at preg_match and reached the error point in below sentences at wp-admin/edit-form-blocks.php line 200.

if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
	foreach ( $editor_styles as $style ) {
		if ( preg_match( '~^(https?:)?//~', $style ) ) {
			$response = wp_remote_get( $style );
			if ( ! is_wp_error( $response ) ) {
				$styles[] = array(
					'css' => wp_remote_retrieve_body( $response ),
				);
			}
		} else {
			$file = get_theme_file_path( $style );
			if ( file_exists( $file ) ) {
				$styles[] = array(
					'css'     => file_get_contents( $file ),
					'baseURL' => get_theme_file_uri( $style ),
				);
			}
		}
	}
}

I'll investigate who set the global variable $editor_styles and why 2nd element is null only when Japanese Windows. It must be font settings issue...

#2 @atachibana
6 years ago

  • Component changed from Themes to Editor
  • Keywords has-patch added
  • Summary changed from Twenty Seventeen shows warning: file_get_contents when new post/page creation in Japanese Settings to edit-form-blocks.php shows Warning when $editor_styles include blank element.

This issue was common thing, not Windows nor Japanese related.

The global array variable $editor_styles keeps editor-style.css and font URI information as described in the above comment, but they might be blank string with some reason. Refer Twenty Seventeen's twentyseventeen_fonts_url().

Current edit-form-blocks.php assumes two elements of $editor_styles are not blank and causes this issue. String check should be included.

	foreach ( $editor_styles as $style ) {
		if ( preg_match( '~^(https?:)?//~', $style ) ) {
		    :
		// } else {            // OLD
		} elseif ( $style ) {  // NEW
		    :

@atachibana
6 years ago

Added string check

@noisysocks
4 years ago

#3 @noisysocks
4 years ago

  • Component changed from Editor to Bundled Theme

Thanks for reporting this @atachibana! I wasn't able to reproduce this by setting my language to Japanese, but I agree there's a logic error in the code you linked to.

Instead of checking that the string exists in edit-form-blocks.php, I think we should instead patch Twenty Seventeen so that it doesn't pass an array containing an empty string to add_editor_style().

45880.diff demonstrates what I mean.

#4 @sabernhardt
19 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Summary changed from edit-form-blocks.php shows Warning when $editor_styles include blank element. to Twenty Seventeen: edit-form-blocks.php shows Warning when $editor_styles include blank element.

Duplicate of #45739.

It seems this was already fixed for any themes with an empty stylesheet in [45619].

Note: See TracTickets for help on using tickets.