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

WordPress Trac noreply at wordpress.org
Mon Jul 17 18:40:59 UTC 2017


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

Comment (by westonruter):

 Replying to [comment:141 bobbingwide]:
 > Some widgets could become legacy simply because of a new line at the end
 of the text.

 Great point. I've just re-opened the [https://github.com/xwp/wordpress-
 develop/pull/235 PR] to account for that, by trimming whitespace before
 checking for line breaks: [https://github.com/xwp/wordpress-
 develop/pull/235/commits/56c9456f34e313bc6a53097e95c3eac29e9af741
 56c9456].

 > Is there any reason why legacy mode has to be permanent?
 > Removal of that new line would allow use of the visual editor.
 > A flexible approach would allow a user to switch to text only while
 still giving the option of wpautop processing.
 > It may also cater for users who upgraded to 4.8 and now have problematic
 widgets.

 The reason why the legacy mode becomes permanent is in large part due to
 how widgets are implemented as PHP animals. Whenever you save a widget, it
 re-calls the `form` method and sends it back in the Ajax response to
 replace the previous form. The side effect of this is that any form
 elements that are constructed with JS will get destroyed every time an
 update is made.  The new TinyMCE Text widget (and the media widgets as
 well) work around this by moving the DOM container for the fields outside
 of the element that gets replaced with each save. The Text widget in
 legacy mode, however, does not do this: it uses the old approach of
 replacing the form fields. All this to say, there would be a lot more
 complexity (not to mention user disorientation) to try to switch between
 legacy and visual interactively while the user is making changes,
 especially in the Customizer where there is no “Save” button.

 > And conversely, any reason why `$instance['filter'] = 'content'` is also
 permanent?

 Since the wpautop checkbox is removed entirely going forward, the `filter`
 property becomes useless and it here essentially becomes a versioning
 tool, indicating that a Text widget was created in 4.8 or later.

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


More information about the wp-trac mailing list