WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#45880 new defect (bug)

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

Reported by: atachibana Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.0.2
Component: Editor 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 (3)

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

Download all attachments as: .zip

Change History (5)

@atachibana
6 months ago

#1 shown warning

@atachibana
6 months ago

2nd shown warning

#1 @atachibana
6 months 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 months 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 months ago

Added string check

Note: See TracTickets for help on using tickets.