我需要运行一些代码,一旦新的图像被上传到WordPress 3.5上传程序。下面是wp-includes/js/media-views.js的代码(第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 );
},
我添加了警告(‘新图片上传中!’)在此上传功能的底部,浏览器会提示“新图像已上传!”上传新图像的时间。然而,我不想破解WordPress的核心,所以我想知道是否有一种方法可以在我的主题中编写一些代码来做同样的事情?对不起,我的英语不好。谢谢大家的关注!
发布于 2013-01-25 05:09:49
wp-plupload.js显示上传程序队列将在完成时重置。所以你可以这样做:
wp.Uploader.queue.on('reset', function() {
alert('Upload Complete!');
});
因此,这里是完整的版本,包括对"Upload New Media“对话框上的常规上传程序和"Insert ”对话框上的新plupload上传程序的支持。
创建一个名为:wp-admin-extender.js
的javascript文件,并将其保存在/custom/js/
文件夹或模板目录中的任何位置。
// Hack for "Upload New Media" Page (old uploader)
// Overriding the uploadSuccess function:
if (typeof uploadSuccess !== 'undefined') {
// First backup the function into a new variable.
var uploadSuccess_original = uploadSuccess;
// The original uploadSuccess function with has two arguments: fileObj, serverData
// So we globally declare and override the function with two arguments (argument names shouldn't matter)
uploadSuccess = function(fileObj, serverData)
{
// Fire the original procedure with the same arguments
uploadSuccess_original(fileObj, serverData);
// Execute whatever you want here:
alert('Upload Complete!');
}
}
// Hack for "Insert Media" Dialog (new plupload uploader)
// Hooking on the uploader queue (on reset):
if (typeof wp.Uploader !== 'undefined' && typeof wp.Uploader.queue !== 'undefined') {
wp.Uploader.queue.on('reset', function() {
alert('Upload Complete!');
});
}
//You can also use other techniques to add/register the script for WP Admin.
function extend_admin_js() {
wp_enqueue_script('wp-admin-extender.js', get_template_directory_uri().'/custom/js/wp-admin-extender.js', array('media-upload', 'swfupload', 'plupload'), false, true);
}
add_action('admin_enqueue_scripts', 'extend_admin_js');
发布于 2015-12-17 15:31:14
Onur Yıldırım的回答是建议挂接到所有上传的完成。但根据您的问题,您需要连接到每个成功的上传。这可以通过扩展wp.Uploader.prototype来实现。有关jQuery的正确说明,请访问stackexchange:https://wordpress.stackexchange.com/a/131295
我已经测试过了,它真的允许你连接到“成功”响应(以及其他响应,包括初始化、错误、添加、进度、完成),它分别代表了每个文件的plupload "FileUploaded“自触发事件,得到了async-upload.php json字符串。
发布于 2013-01-12 06:35:54
在Javascript中,这可能会有所帮助:
wp.media.view.Attachments.prototype.on('ready',function(){console.log('your code here');});
在php代码中也可能有一个动作可以工作,我注意到在async-upload.php的末尾有一个echo apply_filters("async_upload_{$type}", $id);
。
https://stackoverflow.com/questions/14279786
复制相似问题