这行 wp-plupload.js显示上传者队列将在完成时重置。所以你可以这样做:
wp.Uploader.queue.on('reset', function() {
alert('Upload Complete!');
});
我已经对其进行了测试,它适用于 WP 3.5网站。
因此,这里是完整版,包括对“上传新媒体”页面上的常规上传器和“插入媒体”对话框上的新plupload上传器的支持。
创建一个名为:的 javascript 文件wp-admin-extender.js
并将其保存在您的/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!');
});
}
最后;将此添加到主题的 functions.php 以在 WP Admin 中获取此功能:
//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');
这可能不是合法的解决方案,但至少是一种解决方法。