if ( response.success ) {
uploadSuccess( file, response.data.id );
if ( response.data && response.data.message ) {
message = response.data.message;
wpQueueError( message || pluploadL10n.http_error_image );
}).fail( function( jqXHR ) {
// If another HTTP 5xx error, try try again...
if ( jqXHR.status >= 500 && jqXHR.status < 600 ) {
wpQueueError( pluploadL10n.http_error_image );
// Init and set the uploader.
uploader_init = function() {
uploader = new plupload.Uploader( wpUploaderInit );
$( '#image_resize' ).bind( 'change', function() {
var arg = $( this ).prop( 'checked' );
setUserSetting( 'upload_resize', '1' );
deleteUserSetting( 'upload_resize' );
uploader.bind( 'Init', function( up ) {
var uploaddiv = $( '#plupload-upload-ui' );
setResize( getUserSetting( 'upload_resize', false ) );
if ( up.features.dragdrop && ! $( document.body ).hasClass( 'mobile' ) ) {
uploaddiv.addClass( 'drag-drop' );
$( '#drag-drop-area' ).on( 'dragover.wp-uploader', function() { // dragenter doesn't fire right :(
uploaddiv.addClass( 'drag-over' );
}).on( 'dragleave.wp-uploader, drop.wp-uploader', function() {
uploaddiv.removeClass( 'drag-over' );
uploaddiv.removeClass( 'drag-drop' );
$( '#drag-drop-area' ).off( '.wp-uploader' );
if ( up.runtime === 'html4' ) {
$( '.upload-flash-bypass' ).hide();
uploader.bind( 'postinit', function( up ) {
uploader.bind( 'FilesAdded', function( up, files ) {
$( '#media-upload-error' ).empty();
plupload.each( files, function( file ) {
if ( file.type === 'image/heic' && up.settings.heic_upload_error ) {
// Show error but do not block uploading.
wpQueueError( pluploadL10n.unsupported_image )
uploader.bind( 'UploadFile', function( up, file ) {
fileUploading( up, file );
uploader.bind( 'UploadProgress', function( up, file ) {
uploadProgress( up, file );
uploader.bind( 'Error', function( up, error ) {
var isImage = error.file && error.file.type && error.file.type.indexOf( 'image/' ) === 0;
var status = error && error.status;
// If the file is an image and the error is HTTP 5xx try to create sub-sizes again.
if ( isImage && status >= 500 && status < 600 ) {
uploadError( error.file, error.code, error.message, up );
uploader.bind( 'FileUploaded', function( up, file, response ) {
uploadSuccess( file, response.response );
uploader.bind( 'UploadComplete', function() {
if ( typeof( wpUploaderInit ) == 'object' ) {