[wp-trac] [WordPress Trac] #53801: Block-based Widgets Screen does action wp_footer after each Widget

WordPress Trac noreply at wordpress.org
Tue Aug 24 23:54:29 UTC 2021

#53801: Block-based Widgets Screen does action wp_footer after each Widget
 Reporter:  MadtownLems   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  5.8.1
Component:  Widgets       |     Version:  5.8
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:

Comment (by eatingrules):

 So I came across this today since I noticed our script was being loaded
 multiple times in the widgets.

 Proof of concept... This will load `/test.js` once for each legacy widget
 in the editor.

 add_action( 'wp_enqueue_scripts', 'enqueue_test_script' );

 function enqueue_test_script() {
         wp_enqueue_script( 'enqueue-test', '/test.js' );

 Hiding the output of `wp_footer` with `display:none` would not have solved
 this, since our JavaScript is a third-party script that displays a help
 widget in the lower-right corner of the screen. So it was loading in the
 bottom corner of each legacy widget.

 I also saw this on a clients' site today. She has an email opt-in popup --
 it popped up and obscured every widget on the page. Made it impossible to
 edit anything, of course.

 As a temporary workaround in our plugin, we're going to add a check for
 `is_admin()`, as @peterwilsoncc suggested above... but that definitely
 seems a bit clunky.

 I think continuing to output JavaScript is likely to cause strange
 behaviors or other errors (especially if that JavaScript does anything to
 modify the content). And, it's being loaded multiple times which also
 isn't ideal.

 Perhaps a better solution is for a "Legacy Widget" to actually look and
 behave like an old-style widget, with no actual preview?

Ticket URL: <https://core.trac.wordpress.org/ticket/53801#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list