admin管理员组文章数量:1291187
I am using new 3.5 media uploader in my theme frontend (base on this example). It is very simple when you want to do something with images after the 'Select'
button is pressed:
file_frame.on('select', function() {
// Get all attachments
var attachments = file_frame.state().get('selection').toJSON();
// Do stuff with attachments
});
But what if I want to do something with attachments just after they were upload? Something like:
file_frame.on('upload', function() {
// Do stuff with attachments
});
I didn't find anything useful in 'wp-includes/js/media-models.js'
or 'wp-includes/js/media-views.js'
.
I have tried to attach a lot of events found in those files:
'add', 'url', 'select', 'ready', 'escapeHandler', 'keydown', 'attach', 'open', 'close', 'escape', 'recordTab', 'updateIndex', 'activate', 'dismiss', 'remove', 'reset', 'uploading', 'deactivate', 'create', 'render', 'change:content', 'scan', 'prepare', 'content:render:upload', 'content:render', 'content', 'updateIndex', 'recordTab', 'change:uploading', 'finish', 'done', 'upload', 'uploaded', 'save', 'saved','change:compat', 'compat'
But all these events fires not when I need this.
Thanks!
I am using new 3.5 media uploader in my theme frontend (base on this example). It is very simple when you want to do something with images after the 'Select'
button is pressed:
file_frame.on('select', function() {
// Get all attachments
var attachments = file_frame.state().get('selection').toJSON();
// Do stuff with attachments
});
But what if I want to do something with attachments just after they were upload? Something like:
file_frame.on('upload', function() {
// Do stuff with attachments
});
I didn't find anything useful in 'wp-includes/js/media-models.js'
or 'wp-includes/js/media-views.js'
.
I have tried to attach a lot of events found in those files:
'add', 'url', 'select', 'ready', 'escapeHandler', 'keydown', 'attach', 'open', 'close', 'escape', 'recordTab', 'updateIndex', 'activate', 'dismiss', 'remove', 'reset', 'uploading', 'deactivate', 'create', 'render', 'change:content', 'scan', 'prepare', 'content:render:upload', 'content:render', 'content', 'updateIndex', 'recordTab', 'change:uploading', 'finish', 'done', 'upload', 'uploaded', 'save', 'saved','change:compat', 'compat'
But all these events fires not when I need this.
Thanks!
Share Improve this question edited Sep 11, 2013 at 16:00 kaiser 50.9k27 gold badges150 silver badges245 bronze badges asked Mar 26, 2013 at 12:48 fornyhuckerfornyhucker 1611 silver badge3 bronze badges 1- You could hook into the add_attachment action: codex.wordpress/Plugin_API/Action_Reference/add_attachment – MikeNGarrett Commented Jan 13, 2014 at 2:13
2 Answers
Reset to default 11There is a FileUploaded
event being fired in wp-includes/js/plupload/wp-plupload.js
.
Alternatively (and propably the better way) you may want extend wp.Uploader with your own success callback .
(function($){
$.extend( wp.Uploader.prototype, {
success : function( file_attachment ){
console.log( file_attachment );
}
});
})(jQuery);
Jörn Lund, you are a wizard! Your wp.Uploader.prototype works great! I have been looking for a very long time how can I update the media library after the file has finished loading into the wp media frame. Hats off to you! Here is my code:
$.extend(wp.Uploader.prototype,{
success: function(file_attachment){
console.log(file_attachment);
if(wp.media.frame.content.get() !== null){
setTimeout(function(){
wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
},100);
}
}
});
本文标签: Image upload callback in new 35 media
版权声明:本文标题:Image upload callback in new 3.5 media 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741513355a2382736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论