[wp-hackers] 3.3 media upload API

Steve Taylor steve at sltaylor.co.uk
Wed Nov 9 11:52:17 UTC 2011


Hi,

I'm trying to update a plugin to be compatible with 3.3. Part of the
plugin creates a button to select an image - uploaded, or from the
Media Library. The button invokes the media overlay, and how it used
to work is that some jQuery runs, checks that we're in an overlay
invoked by the plugin's button, then switching the "Insert into Post"
etc. buttons for a "Select" button. This button in turn would just
pass the attachment's ID back to a hidden field to be stored as
postmeta.

I had problems getting it working with the Flash uploader, there
seemed to be no way to trigger some JS after the upload happens and
the media item details are output via AJAX. And there's no filters in
the get_media_item() function to switch the buttons server-side. So I
just disabled the Flash uploader if this part of the plugin was being
used.

Now with Plupload, I'm in a similar situation, except I don't have the
workaround of disabling the Flash uploader. Obviously it's great that
Plupload degrades nicely, but in this situation it means I *have* to
get things working with every uploader interface, because I can't
control that (I think?).

So, I've got this JS:

if ( typeof(wpUploaderInit) == 'object' ) {
	uploader.bind('FileUploaded', function() {
		alert( $( 'table.describe thead' ).attr( 'id' ) );
	});
}

The alert is just for testing, to check that the JS is running at the
point where the media item table has been generated. I make my script
dependent on 'plupload-handlers', and the function gets bound OK. But
I can't get it to execute AFTER the media item table has been
inserted, so I can change it.

Neither the 'UploadComplete' or 'FileUploaded' Plupload events seem to work.

Anyone else working on anything like this? I've been chipping away at
it for ages, no luck. I imagine 3.3 is due very soon, and I appreciate
most core devs will be working on bugs etc., but I really need to get
my plugin working with 3.3 soon. Any help appreciated!

Cheers,

Steve Taylor


More information about the wp-hackers mailing list