Opened 8 days ago
Last modified 4 hours ago
#40907 reopened feature request
Introduce widget dedicated for HTML code
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.8.1 | Priority: | normal |
| Severity: | normal | Version: | 4.8 |
| Component: | Widgets | Keywords: | has-patch has-unit-tests commit fixed-major |
| Focuses: | Cc: |
Description (last modified by westonruter)
As summarized in Dev Chat Summary: May 31st (4.8 week 5), the Text widget as of 4.8 uses the same TinyMCE editor as the edit post screen. Like the WP editor, it has a Visual tab and a Text tab, where a user can supply raw HTML in the latter. What is removed from the Text widget is the “auto add paragraphs” checkbox which allowed a user to control whether or not wpautop was applied to the text. This was removed to align the widget's behavior with the post editor, where wpautop is always applied. As noted in the TinyMCE Text Widget post, the behavioral changes to the Text widget means that users who have previously pasted 3rd party HTML into the Text widget may encounter extra line breaks if the HTML copied includes extra line breaks for readability (as normally line breaks in HTML are not significant). This extra line break issue is more problematic when pasted 3rd-party HTML includes JavaScript, wpautop can currently (erroneously) add p tags inside of script elements (see #2833).
So, in order to facilitate users being able to paste in arbitrary HTML, a new “HTML Code Widget” can be introduced.
At a minimum, the widget could look the same as the old Text widget except (again) without the checkbox to wpautop, where in this case it does not get applied.
The textarea should have the same fixed-width font styling applied as the Text (HTML) tab of the post editor.
It would also be ideal for the HTML code widget to make use of CodeMirror to provide syntax highlighting and checking, however this depends on #12423, which is currently blocked due to CodeMirror not being fully accessible. Use of CodeMirror has also been proposed for as well as Additional CSS in the Customizer and the Text tab in the post editor.
When the user does not have the unfiltered_html capability, the HTML code widget should also indicate the HTML tags that are allowed and anything not allowed will be stripped. It seems logical that the HTML code widget should allow the same tags that are allowed in post content.
Suggested PHP class name: WP_Widget_HTML_Code
Suggested widget ID base: html_code
Attachments (4)
Change History (31)
#1
@westonruter
8 days ago
- Description modified (diff)
#2
@westonruter
8 days ago
- Description modified (diff)
#3
follow-ups:
↓ 4
↓ 5
@sami.keijonen
8 days ago
#4
in reply to:
↑ 3
@Kopepasah
8 days ago
Why not leave the old text widget and have TinyMCE widget as a new widget? That would not break anything.
I agree with @sami.keijonen here, but it may be too little too late to make a revert.
That aside, I think the suggest class name and id are fine.
#5
in reply to:
↑ 3
@westonruter
8 days ago
Replying to sami.keijonen:
Why not leave the old text widget and have TinyMCE widget as a new widget? That would not break anything.
True, and this was brought up during the dev chat. But Matt wants to move forward with the upgraded Text widget as-is, with there not being a great enough concern for some users potentially having to adjust their usage to align with the new behavior (which aligns with longstanding post editor behavior).
#6
@jbpaul17
8 days ago
Are we purposely NOT supporting JavaScript in this new widget? The proposed title of "HTML Code Widget" to me means it would NOT support JavaScript. However, from the dev chat it seemed that JS snippets was an expected use case.
#7
@westonruter
7 days ago
@jbpaul17 by “HTML Code” it is meant to accept any acceptable HTML, and that includes script tags (if the user can unfiltered_html). This would contrast with a “JavaScript Code” (or “CSS Code”) widget which would expect just code in that language.
This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.
5 days ago
#9
@westonruter
5 days ago
- Description modified (diff)
This ticket was mentioned in Slack in #core-customize by jeffpaul. View the logs.
44 hours ago
#12
@carasmo
40 hours ago
Many people use the old text widget for html and it was great, now it's autowp in my sign up forms and other stuff. This is actually horrible.
#13
@carasmo
37 hours ago
I forked it. Hopefully someone will come along with a plugin. I can't do it for until time allows.
https://gist.github.com/carasmo/d29722a1ef7e1ebe29125661ed3690a2
This ticket was mentioned in Slack in #forums by jeffr0. View the logs.
35 hours ago
#15
@westonruter
35 hours ago
I think the (TinyMCE) Text widget might also warrant having a comment that suggests users to use the HTML Code widget if they switch to the Text tab.
#16
@westonruter
32 hours ago
At least when the HTML Code widget lands, there should be a admin pointer that appears when the user clicks the Text (HTML) tab of the Text widget and notifies users of the new widget specifically intended for arbitrary HTML.
#17
@vfontj
17 hours ago
Until there's a new widget, here is a plugin that restores the classic WordPress text widget. It has been submitted to the repository, but until it is approved, it can be downloaded here: https://victorfont.com/go/classic-text-widget/
The source is on Github here: https://victorfont.com/go/classic-text-widget-source/
#18
@westonruter
12 hours ago
- Keywords good-first-bug removed
- Owner set to westonruter
- Status changed from new to accepted
Given the perceived urgency of having a plain HTML Code widget in trunk for testing and the next minor release, I'll take this.
@westonruter
11 hours ago
#19
@westonruter
11 hours ago
- Keywords has-patch needs-testing needs-unit-tests added; needs-patch removed
- Version set to 4.8
This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.
11 hours ago
@westonruter
11 hours ago
#21
@westonruter
10 hours ago
I didn't include the .textwidget wrapper around the content that is printed, so a <div class="textwidget"> would need to be added if a user wanted to have all of the styles that would apply to a text widget.
We should also check to make sure there isn't an existing widget with html_code as its ID base in the repo, and that the WP_Widget_HTML_Code class isn't used for that matter.
@westonruter
9 hours ago
Add unit tests and address PR feedback from timmydcrawford: https://github.com/xwp/wordpress-develop/pull/233/files/d75cfaa29632fc6191b6b11b456d9494a14c76df..a270b828b61df8b251600346e86a0c987dcf3d66
#22
@westonruter
9 hours ago
- Keywords has-unit-tests added; needs-testing needs-unit-tests removed
Note that 40907.1.diff introduces new files. Will this work in a 4.8.1 minor release or not?
#23
@westonruter
9 hours ago
- Keywords commit added
@melchoyce should we update the Text widget's description from “Arbitrary text or HTML” to be something like “Arbitrary content”? This is because we want to direct users away from using the Text widget now for arbitrary HTML.
#24
follow-up:
↓ 27
@westonruter
9 hours ago
@ipstenu would you please ack PHP files for ['"]html_code['"] and WP_Widget_HTML_Code in the plugin directory?
#25
@westonruter
8 hours ago
- Resolution set to fixed
- Status changed from accepted to closed
In 40893:
#26
@westonruter
8 hours ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for consideration in 4.8.1, committing to the 4.8 branch though note the presence of new files.
#27
in reply to:
↑ 24
@Ipstenu
4 hours ago
Replying to westonruter:
@ipstenu would you please ack PHP files for ['"]html_code['"] and WP_Widget_HTML_Code in the plugin directory?
FYI, due to WCEU I won't be able to until I get to ... Paris :/
Why not leave the old text widget and have TinyMCE widget as a new widget? That would not break anything.