WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

#43125 closed defect (bug) (fixed)

Deregistering WP_Widget_Media_Image breaks Text widget's "Add Media" button

Reported by: standardspace Owned by: westonruter
Milestone: 4.9.3 Priority: normal
Severity: normal Version: 4.9
Component: Widgets Keywords: has-patch commit fixed-major
Focuses: Cc:

Description

Using:

<?php
unregister_widget( 'WP_Widget_Media_Image' );

results in Text widget's "Add Media" button no longer working.

Attachments (1)

43125.0.diff (386 bytes) - added by westonruter 5 months ago.

Download all attachments as: .zip

Change History (13)

#1 @swissspidy
5 months ago

  • Keywords reporter-feedback added

Hey there

Welcome to WordPress Trac!

I cannot reproduce this using

add_action( 'widgets_init', function() {
        unregister_widget( 'WP_Widget_Media_Image' );
} );

The "Add Media" button in the text widget is still there and I can successfully upload and insert images to the text widget.

Have you tried disabling all plugins and using a default theme to see if the error persists?

#2 @standardspace
5 months ago

Hi, Thanks for quick response. I'll set up a clean install now and let you know.

#3 @standardspace
5 months ago

  • Resolution set to invalid
  • Status changed from new to closed

You're correct.

Sorry, I could have tried it with a standard theme. I guess the bug is with my code.

Please feel free to close.

#4 @swissspidy
5 months ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted

#5 @standardspace
5 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I've investigated further and found that the "Add Media" button fails unless one of the Media widgets is active.

Adding this to the Twenty Seventeen theme:

<?php
add_action( 'widgets_init', function() {
   unregister_widget( 'WP_Widget_Media_Image' );
   unregister_widget( 'WP_Widget_Media_Audio' );
   unregister_widget( 'WP_Widget_Media_Video' );
   unregister_widget( 'WP_Widget_Media_Gallery' );
} );

causes the "Add Media" button to fail.

Looks like the required javascript may not be loaded when there are no "media" widgets present. This leaves the Text widget without the add media functionality.

#6 @swissspidy
5 months ago

  • Keywords needs-patch added
  • Milestone set to 4.9.3
  • Version changed from 4.9.2 to 4.9

Indeed. I just tested this using WP Widget Disable and am getting the same result now. That's certainly unexpected.

Adding to the 4.9.3 milestone for visibility, but needs a patch to get into that release.

#7 @westonruter
5 months ago

  • Keywords has-patch added; needs-patch removed

@standardspace would you please try 43125.0.diff?

#8 @standardspace
5 months ago

Hi @westonruter, I've tested that on a clean wp install all seems to work as I would expect.

I've added the following to my functions.php :

<?php
add_action( 'widgets_init', function() {
    unregister_widget( 'WP_Widget_Media_Image' );
    unregister_widget( 'WP_Widget_Media_Audio' );
    unregister_widget( 'WP_Widget_Media_Video' );
    unregister_widget( 'WP_Widget_Media_Gallery' );
} );

and the Text widget's "Add Media" was able to function without the other media widgets present.

Looks like a fix. Thanks

Last edited 5 months ago by standardspace (previous) (diff)

#9 @westonruter
5 months ago

  • Keywords commit added
  • Owner set to westonruter
  • Status changed from reopened to accepted

@westonruter
5 months ago

#10 @westonruter
5 months ago

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

In 42545:

Widgets: Ensure media is explicitly enqueued from Text widget in case Media widgets are unregistered.

Amends [41344].
See #40854.
Fixes #43125.

#11 @westonruter
5 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

#12 @westonruter
5 months ago

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

In 42546:

Widgets: Ensure media is explicitly enqueued from Text widget in case Media widgets are unregistered.

Amends [41344].
See #40854.
Fixes #43125 for 4.9 branch.

Note: See TracTickets for help on using tickets.