WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#32425 closed task (blessed) (fixed)

Update WP_Editors and TinyMCE initialization

Reported by: azaozz Owned by: azaozz
Milestone: 4.3 Priority: normal
Severity: normal Version: 4.3
Component: TinyMCE Keywords: has-patch
Focuses: Cc:

Description

There are several "weak points" in the TinyMCE initialization, filtering content for the editors, switching between them, and applying wpautop.

There is no good reason to run the editor content through the PHP wpautop() before outputting it in the textarea, and have two separate filers for it. This should be handled from JS on initializing TinyMCE. Editor.js and the inline script that initializes both editors also need updating.

Attachments (4)

32425.patch (45.6 KB) - added by azaozz 3 years ago.
32425.1.patch (82.1 KB) - added by azaozz 3 years ago.
32425.2.patch (83.4 KB) - added by azaozz 3 years ago.
32425.3.patch (82.7 KB) - added by azaozz 2 years ago.

Download all attachments as: .zip

Change History (25)

@azaozz
3 years ago

#1 @azaozz
3 years ago

  • Keywords has-patch added

In 32425.patch:

  • Replace wp_richedit_pre() and wp_htmledit_pre() with format_for_editor(). Deprecate the old functions and filters. Add back-compat for the filters. The new function only runs the content through htmlspecialchars(), same as wp_htmledit_pre(). If TinyMCE is loaded first, the content is run through the JS wpautop() on initializing the editor.
  • Update editor.js to use tinymce.$.
  • Update WP_Editors, remove the unneeded filter swapping and add some more escaping.
  • When Quicktags is used, add the toolbar div from PHP. This stops the Text editor from "jumping" on page load.

Still to do: maybe move the JS wpautop() and preWpautop() to the 'wordpress' TinyMCE plugin so they are available without needing to load editor.js. That makes it a bit easier/cleaner to use only TinyMCE. Alternatively we can add them in the same file as the plugin but without being a part of it, then define them in something like tinymce.wp.*. Also wondering about the back-compat for the jQuery events on running the content through wpautop and preWpautop.

#2 @iseulde
3 years ago

Could we maybe do this in smaller pieces? :)

#3 @azaozz
3 years ago

We could, but most of the changes are related so the different pieces/tickets will have to be dependent on one another. Harder to sync :)

#4 @azaozz
3 years ago

Another idea: lets make a wpapi plugin and add the wpautop(), preWpautop() and the wpMenu functions in it. Then ensure it is always loaded first by prepending it to the plugins list.

This ticket was mentioned in Slack in #core-editor by azaozz. View the logs.


3 years ago

@azaozz
3 years ago

@azaozz
3 years ago

#6 @azaozz
3 years ago

In 32425.2.patch:

  • Move wpautop() and wpremovep() (formerly pre_wpautop) to a new TinyMCE plugin so they are always available.
  • Do not initialize TinyMCE in a hidden div when the Text editor is default. Initializing wpViews while hidden might cause problems. Open a new ticket for it for more testing.
  • Add back-compat for the new format_for_editor() that normalizes escaping and replaces wp_richedit_pre() and wp_htmledit_pre().

@azaozz
2 years ago

#7 @azaozz
2 years ago

In 32425.3.patch:

  • Keep the JS wpautop() in editor.js but add it to wp.editor.autop() and wp.editor.removep().
  • Use the above to handle adding/removing of <p> automatically when loading or switching editors.
  • Do not run the post_content through wpautop() before outputting it for editing.
  • Deprecate wp_richedit_pre() and wp_htmledit_pre() and introduce format_for_editor().
Last edited 2 years ago by azaozz (previous) (diff)

This ticket was mentioned in Slack in #core-editor by azaozz. View the logs.


2 years ago

#9 @azaozz
2 years ago

In 32899:

Update the TinyMCE initialization:

  • Replace wp_htmledit_pre() and wp_richedit_pre() with format_for_editor().
  • Replace the 'htmledit_pre' and 'richedit_pre' filters with 'format_for_editor'.
  • Do not run the post content through wpautop() in PHP when the visual editor is default. Run the textarea content through the JS wpautop on initializing TinyMCE.
  • Simplify both editors initialization.
  • Improve setting of wpActiveEditor in Quicktags.
  • Improve editor.js, use tinymce.$ when possible.

See #32425.

#10 @azaozz
2 years ago

In 32900:

Fix typo/white space in the docs.
See #32425.

#11 @azaozz
2 years ago

Leaving open for now in case some adjustments are needed.

#12 @boonebgorges
2 years ago

In 32912:

Add expectedDeprecated flags to wp_richedit_pre() and wp_htmledit_pre() unit tests.

These functions were deprecated in [32899].

See #32425.

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


2 years ago

#14 @obenland
2 years ago

  • Type changed from enhancement to task (blessed)

#15 @obenland
2 years ago

  • Owner set to azaozz
  • Status changed from new to assigned

#16 @obenland
2 years ago

@azaozz, no adjustments in 9 days, can this be closed?

This ticket was mentioned in Slack in #core-editor by ocean90. View the logs.


2 years ago

#18 @azaozz
2 years ago

In 33187:

TinyMCE:

  • Go back to encoding the editor content only when TinyMCE is used.
  • Add check and encode </textarea> if present.

See #32425.

This ticket was mentioned in Slack in #core-editor by azaozz. View the logs.


2 years ago

#20 follow-up: @obenland
2 years ago

  • Version set to trunk

@azaozz, anything left to do here?

#21 in reply to: ↑ 20 @azaozz
2 years ago

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

Replying to obenland:

This should be done. If any bugs, please open new tickets.

Note: See TracTickets for help on using tickets.