Opened 7 years ago
Closed 7 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 |
---|---|---|---|
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)
Change History (13)
#3
@
7 years 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.
#5
@
7 years 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
@
7 years 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
@
7 years ago
- Keywords has-patch added; needs-patch removed
@standardspace would you please try 43125.0.diff?
#8
@
7 years 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
#9
@
7 years ago
- Keywords commit added
- Owner set to westonruter
- Status changed from reopened to accepted
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?