Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#45221 closed defect (bug) (fixed)

Fix the TinyMCE init array in script-loader

Reported by: azaozz's profile azaozz Owned by: azaozz's profile azaozz
Milestone: 5.0 Priority: normal
Severity: normal Version: 5.0
Component: TinyMCE Keywords: has-patch commit dev-reviewed fixed-5.0
Focuses: Cc:

Description

The "TinyMCE init array" in script-loader mostly duplicates the "default" init array in class-wp-editor. However there are few differences that can cause regressions in themes and plugins.

  1. The init array is outputted by $scripts->localize() which is intended only for strings and the output is JSON encoded. This breaks some of the TinyMCE settings (added by plugins) as they must be raw js. For example the setting for init_instance_callback must be a "callable" js function, or it throws exception on loading.
  2. Currently in script-loader there is some code that does JSON decoding of the style_formats setting. However that may not be JSON encoded resulting in an JSON decode error and an empty string.

Attachments (1)

45221.diff (6.0 KB) - added by azaozz 6 years ago.

Download all attachments as: .zip

Change History (14)

@azaozz
6 years ago

#1 @azaozz
6 years ago

In 45221.diff:

  • Fix possible regressions when translating the init array from PHP to JS. TinyMCE expects "raw js" init object.
  • Fix removal of non-JSON encoded value for the style_formats setting.
  • Reformat the code to make it readable :)

The patch also copies the way the init array is outputted from class-wp-editor.php to script-loader.php. Perhaps it would be better to keep all of this in class-wp-editor.php instead of (partially) copying it to script-loader.php.

#2 @SergeyBiryukov
6 years ago

  • Summary changed from FIx the TInyMCE init array in script-loader to Fix the TinyMCE init array in script-loader

#3 @azaozz
6 years ago

#45117 was marked as a duplicate.

#4 @azaozz
6 years ago

  • Keywords has-patch commit added

#5 follow-up: @pento
6 years ago

  • Keywords dev-reviewed added
  • Owner set to azaozz
  • Status changed from new to assigned

I agree that we'll need to revisit this to reduce the code duplication, but I'm not particularly concerned about that for now.

45221.diff is good to commit.

#6 in reply to: ↑ 5 @azaozz
6 years ago

Replying to pento:

Yep, me too. Made #45286 as a follow up for 5.1+.

#7 @azaozz
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 43867:

TinyMCE:

  • Fix parsing of the init array in script-loader.
  • Do not JSON encode the options object when outputting it from PHP.
  • Remove JSON decoding of TinyMCE's style_formats option.

Fixes #45221.

This ticket was mentioned in Slack in #core by desrosj. View the logs.


6 years ago

#9 @SergeyBiryukov
6 years ago

  • Keywords fixed-5.0 added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for trunk.

#10 follow-up: @matthunt
6 years ago

  • Keywords needs-patch added; has-patch removed
  • Severity changed from normal to major
  • Version set to 5.0

Unfortunately I am still having issues with TinyMCE with WordPress 5.0. It runs into js script errors that I have fixed due to permission issues on my end. However using the Classic WP editor as suggested via wordpress.org the Toolbar buttons do not appear on visual mode. I tested on different browsers and the same result. I thought I would share this information

#11 in reply to: ↑ 10 @SergeyBiryukov
6 years ago

  • Keywords has-patch added; needs-patch removed
  • Severity changed from major to normal

Replying to matthunt:

Unfortunately I am still having issues with TinyMCE with WordPress 5.0.

Could you please create a new ticket for the issues you're having? Thanks!

#12 @SergeyBiryukov
6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 44236:

TinyMCE:

  • Fix parsing of the init array in script-loader.
  • Do not JSON encode the options object when outputting it from PHP.
  • Remove JSON decoding of TinyMCE's style_formats option.

Props azaozz.
Merges [43867] to trunk.
Fixes #45221.

#13 @SergeyBiryukov
6 years ago

In 44238:

PHPCS: Fix errors introduced in [44236].

See #45221.

Note: See TracTickets for help on using tickets.