I need to run some code as soon as new images get uploaded in WordPress 3.5 uploader. Here is the code of wp-includes/js/media-views.js (line 529-540)
uploading: function( attachment ) {
var content = this.frame.content;
// If the uploader was selected, navigate to the browser.
if ( 'upload' === content.mode() )
this.frame.content.mode('browse');
// If we're in a workflow that supports multiple attachments,
// automatically select any uploading attachments.
if ( this.get('multiple') )
this.get('selection').add( attachment );
},
I added alert(‘New image uploaded!’) at the bottom of this uploading function, and the browser alert ‘New image uploaded!’ when new image was uploaded. However I don’t want to hack the core of WordPress, so I’m wondering if there is a way that I can write some code in my theme that can do the same thing? Sorry for my English. Thank you for you attention guys!
This line of wp-plupload.js shows that the uploader queue will reset on complete. So you can do this:
I’ve tested it and it works on WP 3.5 sites.
So, here is the full version including support for both the regular uploader on “Upload New Media” Page and the new plupload uploader on “Insert Media” Dialog.
Create a javascript file named:
wp-admin-extender.jsand save it under your/custom/js/folder or whatever within your template directory.And finally; add this into your theme’s functions.php to get this functionality in WP Admin:
This might not be the legitimate solution but it’s a workaround at least.