[wp-trac] [WordPress Trac] #40951: New Text Widget - Switching Between Visual/Text Editor Strips Out Code

WordPress Trac noreply at wordpress.org
Fri Jun 23 21:51:19 UTC 2017


#40951: New Text Widget - Switching Between Visual/Text Editor Strips Out Code
-------------------------------------------------+-------------------------
 Reporter:  dwrippe                              |       Owner:
     Type:  defect (bug)                         |  westonruter
 Priority:  normal                               |      Status:  accepted
Component:  Widgets                              |   Milestone:  4.8.1
 Severity:  major                                |     Version:  4.8
 Keywords:  needs-patch needs-testing has-unit-  |  Resolution:
  tests                                          |     Focuses:
-------------------------------------------------+-------------------------
Changes (by westonruter):

 * keywords:  needs-patch => needs-patch needs-testing has-unit-tests


Comment:

 OK, this is ready for testing. Please see [attachment:40951.0.diff] which
 is also available in a [https://github.com/xwp/wordpress-develop/pull/235
 PR] on GitHub for checkout and review.

 The patch introduces a legacy mode for the Text widget. The legacy mode
 hinges on the new `\WP_Widget_Text::is_legacy_instance()` method. It has
 an explicit whitelist of conditions that will result in a Text widget
 being initialized in legacy mode. Once a Text widget is determined to need
 legacy mode, after the widget is henceforth modified the legacy mode will
 persist in perpetuity for the instance. The whitelist of conditions for a
 Text widget being in legacy mode are:

 * It was created prior to the TinyMCE-enhanced widget in 4.8. All widgets
 created in 4.8 and beyond will never be in legacy mode but will always
 have TinyMCE.
 * The auto-paragraph checkbox was unchecked and there are line breaks in
 the text.
 * There are empty elements that are not always empty, like `img` or `hr`.
 * The text contains any HTML element or attribute other than: `strong`,
 `em`, `b`, `i`, `u`, `s`, `ul`, `ol`, `li`, `hr`, `abbr`, `acronym`,
 `code`, `dfn`, `a[href]`, `img[src][alt]`.

 Question: Should `style` be whitelisted for all of these elements as well?

 I added unit tests that include all of the examples shared in this ticket.
 See [attachment:text-widget-legacy-mode-2.png] for screenshot of what the
 legacy mode looks like.

 @melchoyce For the non-legacy widget, should there be a notice displayed
 when selecting the Text (HTML) tab of the TinyMCE editor that they should
 also consider the HTML Code (Custom HTML) widget instead?

 Please test.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40951#comment:79>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list