Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#14829 closed enhancement (invalid)

More hooks/actions required for Media Uploader

Reported by: Alhadis Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: Upload Keywords: needs-patch reporter-feedback
Focuses: Cc:


Okay, so the Media Uploader's API needs work.

This is not just a suggestion; it's a revelation that occurred to me after nine solid hours of picking around uncompromising source code and relying on JavaScript and guesswork to add custom functionality.

Many times I've found myself developing WordPress features that all attempted to manipulate or customise the Media Uploader thickbox in some way... many of which became completely unworkable due to the lack of hooks or filters provided by the source code. Furthermore, the way the uploader sends images back to the TinyMCE editor has made it incredibly difficult to "intercept" those commands and have them handled differently.

Say I have a metabox added to the Edit Post screen that displays thumbnails to a computer illiterate client... ones that can be dragged around and rearranged to control the order of a slideshow that's shown above a page when loaded. Now, we've already shown the client how to insert images into a post using WordPress' Thickbox, and they've grown comfortable with traversing the tabs. So it only makes sense that we'd use the same interface for picking or uploading an image.

What if we want to send those images somewhere else, like into a metabox? There's no apparent hook or callback provided by either PHP or JavaScript that allows plugin developers to implement this level of functionality. It's as though the Media Uploader was never intended to be touched or customised in any fashion. And so, my current solution relies solely on using jQuery for adding buttons and callbacks over the top of the existing interface. I'm up to the part that involves "stealing" the attachment's ID and trying to send it back to the Edit Post page in the background. Lot of work? Yes. Secure? No. At any given point in future, there's no guarantee that the core structure of the Media Items list will change, thereby breaking the plugin that relied on class-names and DOM traversal to apply buttons.

In short, these are ridiculous lengths that I've had to go to to try and implement an enhancement to the Media Uploader. I don't want to go through the trouble of scripting an entirely new uploader specifically for plugins and theme features... I think we'd all agree it's in WordPress's nature to allow a degree of control over how the Uploader Thickbox works as well.

Attachments (1)

media-bulk-image-uploader.php.zip (3.5 KB) - added by martythornley 9 years ago.
A plugin that hooks into the upload process

Download all attachments as: .zip

Change History (10)

#1 @Alhadis
11 years ago

Okay, so... has anybody even noticed this yet?

#2 @alex-ye
11 years ago

Woo , Great suggestions Iam agree with you ...

#3 @Alhadis
11 years ago

If you saw the spaghetti code it took just to insert an extra button to redirect the picked image into a custom metabox, you'd probably agree with me even more. >_>;

#4 @nacin
11 years ago

  • Keywords needs-patch close added; Thickbox Media Gallery Uploader Callback Filters Hooks Edit Gallery removed
  • Milestone changed from Awaiting Review to Future Release

Sure. Please provide a patch.

#5 @ocean90
10 years ago

  • Keywords reporter-feedback added; close removed
  • Milestone changed from Future Release to Awaiting Review

Which hooks are really needed?

See also #18206.

#6 @ocean90
10 years ago

  • Component changed from UI to Upload

#7 @martythornley
9 years ago

  • Cc marty@… added

#8 @martythornley
9 years ago

There are hooks to control what you can do with images uploaded through the thickbox window. It just is really tough to find and not at all intuitive. The real problem is that the functions in media.php are very confusing and redundant and it takes following a thread of function to function to function to track down what is doing what.

It is easy enough to add your own tabs to the thickbox but if you want to add say an extra checkbox or setting to each image within the current list of uploaded images, that would need some hooks. As mentioned in the ticket description, I had to resort to javascript to insert some checkboxes.

For example, I will attach a zipped plugin that I wrote to allow bulk insert of images. It uses the following

	add_filter ( 'media_upload_image' ,					'bulk_image_alter_image_uploads');
	add_filter ( 'media_upload_gallery' ,				'bulk_image_alter_image_uploads' );
	add_filter ( 'media_upload_library' ,				'bulk_image_alter_image_uploads' );

Then the bulk_image_alter_image_uploads() function returns either a custom function ( bulk_image_insert_to_editor() ) that mimics the built in one or adds another filter so other plugins can hook in. So in another plugin for image galleries, I used this new hook to interrupt the upload process and send images to my own folder instead of the standard uploads folder, then sent them back to a metabox instead of the editor.

The bulk_image_insert_to_editor() handles the uploads, then returns another mimic function bulk_image_fast_insert_to_editor() instead of the core insert to editor function.

So I guess it would be nice if all those steps had a hook in it, so that any one could be replaced, whereas I had to replace all three?

It is related to http://core.trac.wordpress.org/ticket/21329, where I tried to consolidate at least the initial hooks a little but I think that whole set of functions in media.php could use some refining.

9 years ago

A plugin that hooks into the upload process

#9 @scribu
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I think this has gotten better with the media manager rewrite in WP 3.5. If not, please open a new ticket that references the new code.

Note: See TracTickets for help on using tickets.