Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#43125 closed defect (bug) (fixed)

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

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

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 9 years ago.

Download all attachments as: .zip

Change History (13)

#1 @swissspidy
9 years 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
9 years ago

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

#3 @standardspace
9 years ago

  • Resolutioninvalid
  • Status newclosed

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
9 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review

#5 @standardspace
9 years ago

  • Resolution invalid
  • Status closedreopened

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
9 years ago

  • Keywords needs-patch added
  • Milestone4.9.3
  • Version 4.9.24.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
9 years ago

  • Keywords has-patch added; needs-patch removed

@standardspace would you please try 43125.0.diff?

#8 @standardspace
9 years ago

Hi Weston,
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

Version 0, edited 9 years ago by standardspace (next)

#9 @westonruter
9 years ago

  • Keywords commit added
  • Owner set to westonruter
  • Status reopenedaccepted

@westonruter
9 years ago

#10 @westonruter
9 years ago

  • Resolutionfixed
  • Status acceptedclosed

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
9 years ago

  • Keywords fixed-major added
  • Resolution fixed
  • Status closedreopened

#12 @westonruter
9 years ago

  • Resolutionfixed
  • Status reopenedclosed

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.