From ff225c8bfc7d32e2aed96096eb802e3d598cdc71 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 3 Oct 2019 21:02:00 +0000 Subject: [PATCH] Upload: Fix the method used to create image sub-sizes when uploading fails with a PHP fatal error. Use a custom header to send the new attachment post ID even in HTTP 500 responses instead of an upload reference sent by the client. Also add another cap check and remove the action when deleting an attachment post during a failed upload cleanup. Props timothyblynjacobs, clorith, azaozz. Fixes #48200. Built from https://develop.svn.wordpress.org/trunk@46382 git-svn-id: http://core.svn.wordpress.org/trunk@46181 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 34 +++---------- wp-admin/includes/file.php | 58 ---------------------- wp-admin/includes/image.php | 20 ++++++++ wp-admin/includes/media.php | 12 ----- wp-includes/js/plupload/handlers.js | 37 ++++++-------- wp-includes/js/plupload/handlers.min.js | 2 +- wp-includes/js/plupload/wp-plupload.js | 33 ++++++------ wp-includes/js/plupload/wp-plupload.min.js | 2 +- wp-includes/version.php | 2 +- 9 files changed, 59 insertions(+), 141 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 17f0243897..773be72833 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -2422,39 +2422,19 @@ function wp_ajax_media_create_image_subsizes() { wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) ); } - if ( ! empty( $_POST['_wp_temp_upload_ref'] ) ) { - // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory. - // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error - // the cliend doesn't know the attachment ID yet. - // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client - // in the original upload request. It is used to save a transient with the attachment_id as value. - // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string. - $attachment_id = _wp_get_upload_ref_attachment_id( $_POST['_wp_temp_upload_ref'] ); - } else { - wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) ); - } - - if ( empty( $attachment_id ) ) { + if ( empty( $_POST['attachment_id'] ) ) { wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); } + $attachment_id = (int) $_POST['attachment_id']; + if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { // Upload failed. Cleanup. - if ( wp_attachment_is_image( $attachment_id ) ) { + if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) { $attachment = get_post( $attachment_id ); - // Posted at most 10 min ago. + // Created at most 10 min ago. if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { - /** - * Runs when an image upload fails during the post-processing phase, - * and the newly created attachment post is about to be deleted. - * - * @since 5.3.0 - * - * @param int $attachment_id The attachment post ID. - */ - do_action( 'wp_upload_failed_cleanup', $attachment_id ); - wp_delete_attachment( $attachment_id, true ); wp_send_json_success(); } @@ -2465,7 +2445,7 @@ function wp_ajax_media_create_image_subsizes() { // The js that handles the response would need to also handle HTTP 500 errors. wp_update_image_subsizes( $attachment_id ); - if ( ! empty( $_POST['_legasy_support'] ) ) { + if ( ! empty( $_POST['_legacy_support'] ) ) { // The old (inline) uploader. Only needs the attachment_id. $response = array( 'id' => $attachment_id ); } else { @@ -2478,8 +2458,6 @@ function wp_ajax_media_create_image_subsizes() { } // At this point the image has been uploaded successfully. - _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] ); - wp_send_json_success( $response ); } diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 9cd626ec0b..3812dc8000 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -981,64 +981,6 @@ function wp_handle_sideload( &$file, $overrides = false, $time = null ) { return _wp_handle_upload( $file, $overrides, $time, $action ); } -/** - * Temporarily stores the client upload reference in a transient. - * - * @since 5.3.0 - * @access private - * - * @param string $upload_ref The upload reference sent by the client. - * @param int $attachment_id Attachment post ID. - * @return bool Whether the transient was set. - */ -function _wp_set_upload_ref( $upload_ref, $attachment_id ) { - $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); - - if ( ! empty( $upload_ref ) ) { - return set_transient( '_wp_temp_image_ref:' . $upload_ref, $attachment_id, HOUR_IN_SECONDS ); - } - - return false; -} - -/** - * Get attachment post ID from an upload reference. - * - * @since 5.3.0 - * @access private - * - * @param string $upload_ref The upload reference sent by the client. - * @return int The attachemtn post ID. Zero if the upload reference has expired or doesn't exist. - */ -function _wp_get_upload_ref_attachment_id( $upload_ref ) { - $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); - - if ( ! empty( $upload_ref ) ) { - return (int) get_transient( '_wp_temp_image_ref:' . $upload_ref ); - } - - return 0; -} - -/** - * Remove the transient that stores a temporary upload reference. - * - * @since 5.3.0 - * @access private - * - * @param string $upload_ref The upload reference sent by the client. - * @return bool Whether the transient was removed. - */ -function _wp_clear_upload_ref( $upload_ref ) { - $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); - - if ( ! empty( $upload_ref ) ) { - return delete_transient( '_wp_temp_image_ref:' . $upload_ref ); - } - - return false; -} - /** * Downloads a URL to a local temporary file using the WordPress HTTP API. * diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 664b83519f..1582ceb3df 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -251,6 +251,12 @@ function wp_create_image_subsizes( $file, $attachment_id ) { return $image_meta; } + // Set a custom header with the attachment_id. + // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. + if ( ! headers_sent() ) { + header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); + } + // Resize the image $resized = $editor->resize( $threshold, $threshold ); $rotated = null; @@ -273,6 +279,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) { if ( true === $rotated && ! empty( $image_meta['image_meta']['orientation'] ) ) { $image_meta['image_meta']['orientation'] = 1; } + + wp_update_attachment_metadata( $attachment_id, $image_meta ); } else { // TODO: handle errors. } @@ -289,6 +297,10 @@ function wp_create_image_subsizes( $file, $attachment_id ) { return $image_meta; } + if ( ! headers_sent() ) { + header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); + } + // Rotate the image $rotated = $editor->maybe_exif_rotate(); @@ -303,6 +315,8 @@ function wp_create_image_subsizes( $file, $attachment_id ) { if ( ! empty( $image_meta['image_meta']['orientation'] ) ) { $image_meta['image_meta']['orientation'] = 1; } + + wp_update_attachment_metadata( $attachment_id, $image_meta ); } else { // TODO: handle errors. } @@ -386,6 +400,12 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) { return $image_meta; } + // Set a custom header with the attachment_id. + // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. + if ( ! headers_sent() ) { + header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); + } + // If stored EXIF data exists, rotate the source image before creating sub-sizes. if ( ! empty( $image_meta['image_meta'] ) ) { $rotated = $editor->maybe_exif_rotate(); diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 6987acb166..18e87baa71 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -314,7 +314,6 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid $title = sanitize_text_field( $name ); $content = ''; $excerpt = ''; - $_ref = false; if ( preg_match( '#^audio#', $type ) ) { $meta = wp_read_audio_metadata( $file ); @@ -409,20 +408,9 @@ function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrid $attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true ); if ( ! is_wp_error( $attachment_id ) ) { - // If an image, keep the upload reference until all image sub-sizes are created. - if ( ! empty( $_POST['_wp_temp_upload_ref'] ) && wp_attachment_is_image( $attachment_id ) ) { - $_ref = _wp_set_upload_ref( $_POST['_wp_temp_upload_ref'], $attachment_id ); - } - // The image sub-sizes are created during wp_generate_attachment_metadata(). // This is generally slow and may cause timeouts or out of memory errors. wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); - - // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created. - // The transient is not needed any more. - if ( $_ref ) { - _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] ); - } } return $attachment_id; diff --git a/wp-includes/js/plupload/handlers.js b/wp-includes/js/plupload/handlers.js index f225c49970..fbf1012f9c 100644 --- a/wp-includes/js/plupload/handlers.js +++ b/wp-includes/js/plupload/handlers.js @@ -431,9 +431,19 @@ jQuery( document ).ready( function( $ ) { tryAgain = function( up, error ) { var file = error.file; var times; + var id; - if ( ! file || ! file.id ) { - wpQueueError( error.message || pluploadL10n.default_error ); + if ( ! error || ! error.responseHeaders ) { + wpQueueError( pluploadL10n.http_error_image ); + return; + } + + id = error.responseHeaders.match( /x-wp-upload-attachment-id:\s*(\d+)/i ); + + if ( id && id[1] ) { + id = id[1]; + } else { + wpQueueError( pluploadL10n.http_error_image ); return; } @@ -449,8 +459,8 @@ jQuery( document ).ready( function( $ ) { dataType: 'json', data: { action: 'media-create-image-subsizes', - _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, - _wp_temp_upload_ref: file.id, + _wpnonce: wpUploaderInit.multipart_params._wpnonce, + attachment_id: id, _wp_upload_failed_cleanup: true, } }); @@ -478,8 +488,8 @@ jQuery( document ).ready( function( $ ) { data: { action: 'media-create-image-subsizes', _wpnonce: wpUploaderInit.multipart_params._wpnonce, - _wp_temp_upload_ref: file.id, - _legasy_support: 'true', + attachment_id: id, + _legacy_support: 'true', } }).done( function( response ) { var message; @@ -589,21 +599,6 @@ jQuery( document ).ready( function( $ ) { uploader.bind( 'UploadComplete', function() { uploadComplete(); }); - - /** - * When uploading images add a file reference used to retrieve the attachment_id - * if the uploading fails due to a server timeout of out of memoty (HTTP 500) error. - * - * @param {plupload.Uploader} up Uploader instance. - * @param {plupload.File} file File for uploading. - */ - uploader.bind( 'BeforeUpload', function( up, file ) { - if ( file.type && file.type.indexOf( 'image/' ) === 0 ) { - up.settings.multipart_params._wp_temp_upload_ref = file.id; - } else { - up.settings.multipart_params._wp_temp_upload_ref = ''; - } - } ); }; if ( typeof( wpUploaderInit ) == 'object' ) { diff --git a/wp-includes/js/plupload/handlers.min.js b/wp-includes/js/plupload/handlers.min.js index 0b65ec4254..5476c662d2 100644 --- a/wp-includes/js/plupload/handlers.min.js +++ b/wp-includes/js/plupload/handlers.min.js @@ -1 +1 @@ -function fileQueued(a){jQuery(".media-blank").remove();var b=jQuery("#media-items").children(),c=post_id||0;1==b.length&&b.removeClass("open").find(".slidetoggle").slideUp(200),jQuery('
').attr("id","media-item-"+a.id).addClass("child-of-"+c).append('
0%
',jQuery('
').text(" "+a.name)).appendTo(jQuery("#media-items")),jQuery("#insert-gallery").prop("disabled",!0)}function uploadStart(){try{"undefined"!=typeof topWin.tb_remove&&topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}catch(a){}return!0}function uploadProgress(a,b){var c=jQuery("#media-item-"+b.id);jQuery(".bar",c).width(200*b.loaded/b.size),jQuery(".percent",c).html(b.percent+"%")}function fileUploading(a,b){var c=104857600,d=parseInt(a.settings.max_file_size,10);d>c&&b.size>c&&setTimeout(function(){b.status<3&&0===b.loaded&&(wpFileError(b,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")),a.stop(),a.removeFile(b),a.start())},1e4)}function updateMediaForm(){var a=jQuery("#media-items").children();1==a.length?(a.addClass("open").find(".slidetoggle").show(),jQuery(".insert-gallery").hide()):a.length>1&&(a.removeClass("open"),jQuery(".insert-gallery").show()),a.not(".media-blank").length>0?jQuery(".savebutton").show():jQuery(".savebutton").hide()}function uploadSuccess(a,b){var c=jQuery("#media-item-"+a.id);return"string"==typeof b&&(b=b.replace(/^
(\d+)<\/pre>$/,"$1"),/media-upload-error|error-div/.test(b))?void c.html(b):(c.find(".percent").html(pluploadL10n.crunching),prepareMediaItem(a,b),updateMediaForm(),void(post_id&&c.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1)))}function setResize(a){a?window.resize_width&&window.resize_height?uploader.settings.resize={enabled:!0,width:window.resize_width,height:window.resize_height,quality:100}:uploader.settings.multipart_params.image_resize=!0:delete uploader.settings.multipart_params.image_resize}function prepareMediaItem(a,b){var c="undefined"==typeof shortform?1:2,d=jQuery("#media-item-"+a.id);2==c&&shortform>2&&(c=shortform);try{"undefined"!=typeof topWin.tb_remove&&topWin.jQuery("#TB_overlay").click(topWin.tb_remove)}catch(e){}isNaN(b)||!b?(d.append(b),prepareMediaItemInit(a)):d.load("async-upload.php",{attachment_id:b,fetch:c},function(){prepareMediaItemInit(a),updateMediaForm()})}function prepareMediaItemInit(a){var b=jQuery("#media-item-"+a.id);jQuery(".thumbnail",b).clone().attr("class","pinkynail toggle").prependTo(b),jQuery(".filename.original",b).replaceWith(jQuery(".filename.new",b)),jQuery("a.delete",b).click(function(){return jQuery.ajax({url:ajaxurl,type:"post",success:deleteSuccess,error:deleteError,id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}}),!1}),jQuery("a.undo",b).click(function(){return jQuery.ajax({url:ajaxurl,type:"post",id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"untrash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")},success:function(){var b,c=jQuery("#media-item-"+a.id);(b=jQuery("#type-of-"+a.id).val())&&jQuery("#"+b+"-counter").text(jQuery("#"+b+"-counter").text()-0+1),post_id&&c.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-0+1),jQuery(".filename .trashnotice",c).remove(),jQuery(".filename .title",c).css("font-weight","normal"),jQuery("a.undo",c).addClass("hidden"),jQuery(".menu_order_input",c).show(),c.css({backgroundColor:"#ceb"}).animate({backgroundColor:"#fff"},{queue:!1,duration:500,complete:function(){jQuery(this).css({backgroundColor:""})}}).removeClass("undo")}}),!1}),jQuery("#media-item-"+a.id+".startopen").removeClass("startopen").addClass("open").find("slidetoggle").fadeIn()}function wpQueueError(a){jQuery("#media-upload-error").show().html('

'+a+"

")}function wpFileError(a,b){itemAjaxError(a.id,b)}function itemAjaxError(a,b){var c=jQuery("#media-item-"+a),d=c.find(".filename").text(),e=c.data("last-err");e!=a&&c.html('
'+pluploadL10n.dismiss+""+pluploadL10n.error_uploading.replace("%s",jQuery.trim(d))+" "+b+"
").data("last-err",a)}function deleteSuccess(a){var b,c,d;return"-1"==a?itemAjaxError(this.id,"You do not have permission. Has your session expired?"):"0"==a?itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?"):(c=this.id,d=jQuery("#media-item-"+c),(b=jQuery("#type-of-"+c).val())&&jQuery("#"+b+"-counter").text(jQuery("#"+b+"-counter").text()-1),post_id&&d.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1),1==jQuery("form.type-form #media-items").children().length&&jQuery(".hidden","#media-items").length>0&&(jQuery(".toggle").toggle(),jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")),jQuery(".toggle",d).toggle(),jQuery(".slidetoggle",d).slideUp(200).siblings().removeClass("hidden"),d.css({backgroundColor:"#faa"}).animate({backgroundColor:"#f4f4f4"},{queue:!1,duration:500}).addClass("undo"),jQuery(".filename:empty",d).remove(),jQuery(".filename .title",d).css("font-weight","bold"),jQuery(".filename",d).append(' '+pluploadL10n.deleted+" ").siblings("a.toggle").hide(),jQuery(".filename",d).append(jQuery("a.undo",d).removeClass("hidden")),void jQuery(".menu_order_input",d).hide())}function deleteError(){}function uploadComplete(){jQuery("#insert-gallery").prop("disabled",!1)}function switchUploader(a){a?(deleteUserSetting("uploader"),jQuery(".media-upload-form").removeClass("html-uploader"),"object"==typeof uploader&&uploader.refresh()):(setUserSetting("uploader","1"),jQuery(".media-upload-form").addClass("html-uploader"))}function uploadError(a,b,c,d){var e,f=104857600;switch(b){case plupload.FAILED:wpFileError(a,pluploadL10n.upload_failed);break;case plupload.FILE_EXTENSION_ERROR:wpFileExtensionError(d,a,pluploadL10n.invalid_filetype);break;case plupload.FILE_SIZE_ERROR:uploadSizeError(d,a);break;case plupload.IMAGE_FORMAT_ERROR:wpFileError(a,pluploadL10n.not_an_image);break;case plupload.IMAGE_MEMORY_ERROR:wpFileError(a,pluploadL10n.image_memory_exceeded);break;case plupload.IMAGE_DIMENSIONS_ERROR:wpFileError(a,pluploadL10n.image_dimensions_exceeded);break;case plupload.GENERIC_ERROR:wpQueueError(pluploadL10n.upload_failed);break;case plupload.IO_ERROR:e=parseInt(d.settings.filters.max_file_size,10),e>f&&a.size>f?wpFileError(a,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")):wpQueueError(pluploadL10n.io_error);break;case plupload.HTTP_ERROR:wpQueueError(pluploadL10n.http_error);break;case plupload.INIT_ERROR:jQuery(".media-upload-form").addClass("html-uploader");break;case plupload.SECURITY_ERROR:wpQueueError(pluploadL10n.security_error);break;default:wpFileError(a,pluploadL10n.default_error)}}function uploadSizeError(a,b){var c,d;c=pluploadL10n.file_exceeds_size_limit.replace("%s",b.name),d=jQuery("
").attr({id:"media-item-"+b.id,"class":"media-item error"}).append(jQuery("

").text(c)),jQuery("#media-items").append(d),a.removeFile(b)}function wpFileExtensionError(a,b,c){jQuery("#media-items").append('

'+c+"

"),a.removeFile(b)}var topWin=window.dialogArguments||opener||parent||top,uploader,uploader_init;jQuery(document).ready(function(a){var b,c={};a(".media-upload-form").bind("click.uploader",function(b){var c,d,e=a(b.target);e.is('input[type="radio"]')?(c=e.closest("tr"),c.hasClass("align")?setUserSetting("align",e.val()):c.hasClass("image-size")&&setUserSetting("imgsize",e.val())):e.is("button.button")?(d=b.target.className||"",d=d.match(/url([^ '"]+)/),d&&d[1]&&(setUserSetting("urlbutton",d[1]),e.siblings(".urlfield").val(e.data("link-url")))):e.is("a.dismiss")?e.parents(".media-item").fadeOut(200,function(){a(this).remove()}):e.is(".upload-flash-bypass a")||e.is("a.uploader-html")?(a("#media-items, p.submit, span.big-file-warning").css("display","none"),switchUploader(0),b.preventDefault()):e.is(".upload-html-bypass a")?(a("#media-items, p.submit, span.big-file-warning").css("display",""),switchUploader(1),b.preventDefault()):e.is("a.describe-toggle-on")?(e.parent().addClass("open"),e.siblings(".slidetoggle").fadeIn(250,function(){var b,c,d=a(window).scrollTop(),e=a(window).height(),f=a(this).offset().top,g=a(this).height();e&&f&&g&&(b=f+g,c=d+e,b>c&&(b-c4?(a.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,_wp_temp_upload_ref:g.id,_wp_upload_failed_cleanup:!0}}),void wpQueueError(e.message&&500!==e.status?e.message:pluploadL10n.http_error_image)):(f?c[g.id]=++f:c[g.id]=1,void a.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:wpUploaderInit.multipart_params._wpnonce,_wp_temp_upload_ref:g.id,_legasy_support:"true"}}).done(function(a){var b;a.success?uploadSuccess(g,a.data.id):(a.data&&a.data.message&&(b=a.data.message),wpQueueError(b||pluploadL10n.http_error_image))}).fail(function(a){return 500===a.status?void b(d,e):void wpQueueError(pluploadL10n.http_error_image)}))):void wpQueueError(e.message||pluploadL10n.default_error)},uploader_init=function(){uploader=new plupload.Uploader(wpUploaderInit),a("#image_resize").bind("change",function(){var b=a(this).prop("checked");setResize(b),b?setUserSetting("upload_resize","1"):deleteUserSetting("upload_resize")}),uploader.bind("Init",function(b){var c=a("#plupload-upload-ui");setResize(getUserSetting("upload_resize",!1)),b.features.dragdrop&&!a(document.body).hasClass("mobile")?(c.addClass("drag-drop"),a("#drag-drop-area").on("dragover.wp-uploader",function(){c.addClass("drag-over")}).on("dragleave.wp-uploader, drop.wp-uploader",function(){c.removeClass("drag-over")})):(c.removeClass("drag-drop"),a("#drag-drop-area").off(".wp-uploader")),"html4"===b.runtime&&a(".upload-flash-bypass").hide()}),uploader.bind("postinit",function(a){a.refresh()}),uploader.init(),uploader.bind("FilesAdded",function(b,c){a("#media-upload-error").empty(),uploadStart(),plupload.each(c,function(a){fileQueued(a)}),b.refresh(),b.start()}),uploader.bind("UploadFile",function(a,b){fileUploading(a,b)}),uploader.bind("UploadProgress",function(a,b){uploadProgress(a,b)}),uploader.bind("Error",function(a,c){var d=c.file&&c.file.type&&0===c.file.type.indexOf("image/"),e=c&&c.status;return 500===e&&d?void b(a,c):(uploadError(c.file,c.code,c.message,a),void a.refresh())}),uploader.bind("FileUploaded",function(a,b,c){uploadSuccess(b,c.response)}),uploader.bind("UploadComplete",function(){uploadComplete()}),uploader.bind("BeforeUpload",function(a,b){b.type&&0===b.type.indexOf("image/")?a.settings.multipart_params._wp_temp_upload_ref=b.id:a.settings.multipart_params._wp_temp_upload_ref=""})},"object"==typeof wpUploaderInit&&uploader_init()}); \ No newline at end of file +function fileQueued(a){jQuery(".media-blank").remove();var b=jQuery("#media-items").children(),c=post_id||0;1==b.length&&b.removeClass("open").find(".slidetoggle").slideUp(200),jQuery('
').attr("id","media-item-"+a.id).addClass("child-of-"+c).append('
0%
',jQuery('
').text(" "+a.name)).appendTo(jQuery("#media-items")),jQuery("#insert-gallery").prop("disabled",!0)}function uploadStart(){try{"undefined"!=typeof topWin.tb_remove&&topWin.jQuery("#TB_overlay").unbind("click",topWin.tb_remove)}catch(a){}return!0}function uploadProgress(a,b){var c=jQuery("#media-item-"+b.id);jQuery(".bar",c).width(200*b.loaded/b.size),jQuery(".percent",c).html(b.percent+"%")}function fileUploading(a,b){var c=104857600,d=parseInt(a.settings.max_file_size,10);d>c&&b.size>c&&setTimeout(function(){b.status<3&&0===b.loaded&&(wpFileError(b,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")),a.stop(),a.removeFile(b),a.start())},1e4)}function updateMediaForm(){var a=jQuery("#media-items").children();1==a.length?(a.addClass("open").find(".slidetoggle").show(),jQuery(".insert-gallery").hide()):a.length>1&&(a.removeClass("open"),jQuery(".insert-gallery").show()),a.not(".media-blank").length>0?jQuery(".savebutton").show():jQuery(".savebutton").hide()}function uploadSuccess(a,b){var c=jQuery("#media-item-"+a.id);return"string"==typeof b&&(b=b.replace(/^
(\d+)<\/pre>$/,"$1"),/media-upload-error|error-div/.test(b))?void c.html(b):(c.find(".percent").html(pluploadL10n.crunching),prepareMediaItem(a,b),updateMediaForm(),void(post_id&&c.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(1*jQuery("#attachments-count").text()+1)))}function setResize(a){a?window.resize_width&&window.resize_height?uploader.settings.resize={enabled:!0,width:window.resize_width,height:window.resize_height,quality:100}:uploader.settings.multipart_params.image_resize=!0:delete uploader.settings.multipart_params.image_resize}function prepareMediaItem(a,b){var c="undefined"==typeof shortform?1:2,d=jQuery("#media-item-"+a.id);2==c&&shortform>2&&(c=shortform);try{"undefined"!=typeof topWin.tb_remove&&topWin.jQuery("#TB_overlay").click(topWin.tb_remove)}catch(e){}isNaN(b)||!b?(d.append(b),prepareMediaItemInit(a)):d.load("async-upload.php",{attachment_id:b,fetch:c},function(){prepareMediaItemInit(a),updateMediaForm()})}function prepareMediaItemInit(a){var b=jQuery("#media-item-"+a.id);jQuery(".thumbnail",b).clone().attr("class","pinkynail toggle").prependTo(b),jQuery(".filename.original",b).replaceWith(jQuery(".filename.new",b)),jQuery("a.delete",b).click(function(){return jQuery.ajax({url:ajaxurl,type:"post",success:deleteSuccess,error:deleteError,id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"trash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")}}),!1}),jQuery("a.undo",b).click(function(){return jQuery.ajax({url:ajaxurl,type:"post",id:a.id,data:{id:this.id.replace(/[^0-9]/g,""),action:"untrash-post",_ajax_nonce:this.href.replace(/^.*wpnonce=/,"")},success:function(){var b,c=jQuery("#media-item-"+a.id);(b=jQuery("#type-of-"+a.id).val())&&jQuery("#"+b+"-counter").text(jQuery("#"+b+"-counter").text()-0+1),post_id&&c.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-0+1),jQuery(".filename .trashnotice",c).remove(),jQuery(".filename .title",c).css("font-weight","normal"),jQuery("a.undo",c).addClass("hidden"),jQuery(".menu_order_input",c).show(),c.css({backgroundColor:"#ceb"}).animate({backgroundColor:"#fff"},{queue:!1,duration:500,complete:function(){jQuery(this).css({backgroundColor:""})}}).removeClass("undo")}}),!1}),jQuery("#media-item-"+a.id+".startopen").removeClass("startopen").addClass("open").find("slidetoggle").fadeIn()}function wpQueueError(a){jQuery("#media-upload-error").show().html('

'+a+"

")}function wpFileError(a,b){itemAjaxError(a.id,b)}function itemAjaxError(a,b){var c=jQuery("#media-item-"+a),d=c.find(".filename").text(),e=c.data("last-err");e!=a&&c.html('
'+pluploadL10n.dismiss+""+pluploadL10n.error_uploading.replace("%s",jQuery.trim(d))+" "+b+"
").data("last-err",a)}function deleteSuccess(a){var b,c,d;return"-1"==a?itemAjaxError(this.id,"You do not have permission. Has your session expired?"):"0"==a?itemAjaxError(this.id,"Could not be deleted. Has it been deleted already?"):(c=this.id,d=jQuery("#media-item-"+c),(b=jQuery("#type-of-"+c).val())&&jQuery("#"+b+"-counter").text(jQuery("#"+b+"-counter").text()-1),post_id&&d.hasClass("child-of-"+post_id)&&jQuery("#attachments-count").text(jQuery("#attachments-count").text()-1),1==jQuery("form.type-form #media-items").children().length&&jQuery(".hidden","#media-items").length>0&&(jQuery(".toggle").toggle(),jQuery(".slidetoggle").slideUp(200).siblings().removeClass("hidden")),jQuery(".toggle",d).toggle(),jQuery(".slidetoggle",d).slideUp(200).siblings().removeClass("hidden"),d.css({backgroundColor:"#faa"}).animate({backgroundColor:"#f4f4f4"},{queue:!1,duration:500}).addClass("undo"),jQuery(".filename:empty",d).remove(),jQuery(".filename .title",d).css("font-weight","bold"),jQuery(".filename",d).append(' '+pluploadL10n.deleted+" ").siblings("a.toggle").hide(),jQuery(".filename",d).append(jQuery("a.undo",d).removeClass("hidden")),void jQuery(".menu_order_input",d).hide())}function deleteError(){}function uploadComplete(){jQuery("#insert-gallery").prop("disabled",!1)}function switchUploader(a){a?(deleteUserSetting("uploader"),jQuery(".media-upload-form").removeClass("html-uploader"),"object"==typeof uploader&&uploader.refresh()):(setUserSetting("uploader","1"),jQuery(".media-upload-form").addClass("html-uploader"))}function uploadError(a,b,c,d){var e,f=104857600;switch(b){case plupload.FAILED:wpFileError(a,pluploadL10n.upload_failed);break;case plupload.FILE_EXTENSION_ERROR:wpFileExtensionError(d,a,pluploadL10n.invalid_filetype);break;case plupload.FILE_SIZE_ERROR:uploadSizeError(d,a);break;case plupload.IMAGE_FORMAT_ERROR:wpFileError(a,pluploadL10n.not_an_image);break;case plupload.IMAGE_MEMORY_ERROR:wpFileError(a,pluploadL10n.image_memory_exceeded);break;case plupload.IMAGE_DIMENSIONS_ERROR:wpFileError(a,pluploadL10n.image_dimensions_exceeded);break;case plupload.GENERIC_ERROR:wpQueueError(pluploadL10n.upload_failed);break;case plupload.IO_ERROR:e=parseInt(d.settings.filters.max_file_size,10),e>f&&a.size>f?wpFileError(a,pluploadL10n.big_upload_failed.replace("%1$s",'').replace("%2$s","")):wpQueueError(pluploadL10n.io_error);break;case plupload.HTTP_ERROR:wpQueueError(pluploadL10n.http_error);break;case plupload.INIT_ERROR:jQuery(".media-upload-form").addClass("html-uploader");break;case plupload.SECURITY_ERROR:wpQueueError(pluploadL10n.security_error);break;default:wpFileError(a,pluploadL10n.default_error)}}function uploadSizeError(a,b){var c,d;c=pluploadL10n.file_exceeds_size_limit.replace("%s",b.name),d=jQuery("
").attr({id:"media-item-"+b.id,"class":"media-item error"}).append(jQuery("

").text(c)),jQuery("#media-items").append(d),a.removeFile(b)}function wpFileExtensionError(a,b,c){jQuery("#media-items").append('

'+c+"

"),a.removeFile(b)}var topWin=window.dialogArguments||opener||parent||top,uploader,uploader_init;jQuery(document).ready(function(a){var b,c={};a(".media-upload-form").bind("click.uploader",function(b){var c,d,e=a(b.target);e.is('input[type="radio"]')?(c=e.closest("tr"),c.hasClass("align")?setUserSetting("align",e.val()):c.hasClass("image-size")&&setUserSetting("imgsize",e.val())):e.is("button.button")?(d=b.target.className||"",d=d.match(/url([^ '"]+)/),d&&d[1]&&(setUserSetting("urlbutton",d[1]),e.siblings(".urlfield").val(e.data("link-url")))):e.is("a.dismiss")?e.parents(".media-item").fadeOut(200,function(){a(this).remove()}):e.is(".upload-flash-bypass a")||e.is("a.uploader-html")?(a("#media-items, p.submit, span.big-file-warning").css("display","none"),switchUploader(0),b.preventDefault()):e.is(".upload-html-bypass a")?(a("#media-items, p.submit, span.big-file-warning").css("display",""),switchUploader(1),b.preventDefault()):e.is("a.describe-toggle-on")?(e.parent().addClass("open"),e.siblings(".slidetoggle").fadeIn(250,function(){var b,c,d=a(window).scrollTop(),e=a(window).height(),f=a(this).offset().top,g=a(this).height();e&&f&&g&&(b=f+g,c=d+e,b>c&&(b-c4?(a.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:wpUploaderInit.multipart_params._wpnonce,attachment_id:g,_wp_upload_failed_cleanup:!0}}),void wpQueueError(e.message&&500!==e.status?e.message:pluploadL10n.http_error_image)):(f?c[h.id]=++f:c[h.id]=1,void a.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:wpUploaderInit.multipart_params._wpnonce,attachment_id:g,_legacy_support:"true"}}).done(function(a){var b;a.success?uploadSuccess(h,a.data.id):(a.data&&a.data.message&&(b=a.data.message),wpQueueError(b||pluploadL10n.http_error_image))}).fail(function(a){return 500===a.status?void b(d,e):void wpQueueError(pluploadL10n.http_error_image)}))):void wpQueueError(pluploadL10n.http_error_image)):void wpQueueError(pluploadL10n.http_error_image)},uploader_init=function(){uploader=new plupload.Uploader(wpUploaderInit),a("#image_resize").bind("change",function(){var b=a(this).prop("checked");setResize(b),b?setUserSetting("upload_resize","1"):deleteUserSetting("upload_resize")}),uploader.bind("Init",function(b){var c=a("#plupload-upload-ui");setResize(getUserSetting("upload_resize",!1)),b.features.dragdrop&&!a(document.body).hasClass("mobile")?(c.addClass("drag-drop"),a("#drag-drop-area").on("dragover.wp-uploader",function(){c.addClass("drag-over")}).on("dragleave.wp-uploader, drop.wp-uploader",function(){c.removeClass("drag-over")})):(c.removeClass("drag-drop"),a("#drag-drop-area").off(".wp-uploader")),"html4"===b.runtime&&a(".upload-flash-bypass").hide()}),uploader.bind("postinit",function(a){a.refresh()}),uploader.init(),uploader.bind("FilesAdded",function(b,c){a("#media-upload-error").empty(),uploadStart(),plupload.each(c,function(a){fileQueued(a)}),b.refresh(),b.start()}),uploader.bind("UploadFile",function(a,b){fileUploading(a,b)}),uploader.bind("UploadProgress",function(a,b){uploadProgress(a,b)}),uploader.bind("Error",function(a,c){var d=c.file&&c.file.type&&0===c.file.type.indexOf("image/"),e=c&&c.status;return 500===e&&d?void b(a,c):(uploadError(c.file,c.code,c.message,a),void a.refresh())}),uploader.bind("FileUploaded",function(a,b,c){uploadSuccess(b,c.response)}),uploader.bind("UploadComplete",function(){uploadComplete()})},"object"==typeof wpUploaderInit&&uploader_init()}); \ No newline at end of file diff --git a/wp-includes/js/plupload/wp-plupload.js b/wp-includes/js/plupload/wp-plupload.js index 67e44226e6..b42c98cf9b 100644 --- a/wp-includes/js/plupload/wp-plupload.js +++ b/wp-includes/js/plupload/wp-plupload.js @@ -119,9 +119,19 @@ window.wp = window.wp || {}; */ tryAgain = function( message, data, file ) { var times; + var id; - if ( ! file || ! file.id ) { - error( pluploadL10n.upload_failed, data, file, 'no-retry' ); + if ( ! data || ! data.responseHeaders ) { + error( pluploadL10n.http_error_image, data, file, 'no-retry' ); + return; + } + + id = data.responseHeaders.match( /x-wp-upload-attachment-id:\s*(\d+)/i ); + + if ( id && id[1] ) { + id = id[1]; + } else { + error( pluploadL10n.http_error_image, data, file, 'no-retry' ); return; } @@ -138,7 +148,7 @@ window.wp = window.wp || {}; data: { action: 'media-create-image-subsizes', _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, - _wp_temp_upload_ref: file.id, + attachment_id: id, _wp_upload_failed_cleanup: true, } }); @@ -161,7 +171,7 @@ window.wp = window.wp || {}; data: { action: 'media-create-image-subsizes', _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, - _wp_temp_upload_ref: file.id, // Used to find the new attachment_id. + attachment_id: id, } }).done( function( response ) { if ( response.success ) { @@ -315,21 +325,6 @@ window.wp = window.wp || {}; $('#' + this.uploader.id + '_html5_container').hide(); } - /** - * When uploading images add a reference used to retrieve the attachment_id. - * Used if the uploading fails due to a server timeout of out of memoty error (HTTP 500). - * - * @param {plupload.Uploader} up Uploader instance. - * @param {plupload.File} file File for uploading. - */ - this.uploader.bind( 'BeforeUpload', function( up, file ) { - if ( file.type && file.type.indexOf( 'image/' ) === 0 ) { - up.settings.multipart_params._wp_temp_upload_ref = file.id; - } else { - up.settings.multipart_params._wp_temp_upload_ref = ''; - } - } ); - /** * After files were filtered and added to the queue, create a model for each. * diff --git a/wp-includes/js/plupload/wp-plupload.min.js b/wp-includes/js/plupload/wp-plupload.min.js index 35bc3bac58..3737f00fbc 100644 --- a/wp-includes/js/plupload/wp-plupload.min.js +++ b/wp-includes/js/plupload/wp-plupload.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a,b){var c;"undefined"!=typeof _wpPluploadSettings&&(c=function(a){var d,e,f,g,h=this,i={container:"container",browser:"browse_button",dropzone:"drop_element"},j={};if(this.supports={upload:c.browser.supported},this.supported=this.supports.upload,this.supported){this.plupload=b.extend(!0,{multipart_params:{}},c.defaults),this.container=document.body,b.extend(!0,this,a);for(e in this)b.isFunction(this[e])&&(this[e]=b.proxy(this[e],this));for(e in i)this[e]&&(this[e]=b(this[e]).first(),this[e].length?(this[e].prop("id")||this[e].prop("id","__wp-uploader-id-"+c.uuid++),this.plupload[i[e]]=this[e].prop("id")):delete this[e]);(this.browser&&this.browser.length||this.dropzone&&this.dropzone.length)&&(this.uploader=new plupload.Uploader(this.plupload),delete this.plupload,this.param(this.params||{}),delete this.params,d=function(a,c,e){var i;return e&&e.id?(i=j[e.id],i&&i>4?(b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,_wp_temp_upload_ref:e.id,_wp_upload_failed_cleanup:!0}}),void f(a,c,e,"no-retry")):(i?j[e.id]=++i:j[e.id]=1,void b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,_wp_temp_upload_ref:e.id}}).done(function(b){b.success?g(h.uploader,e,b):(b.data&&b.data.message&&(a=b.data.message),f(a,c,e,"no-retry"))}).fail(function(b){return 500===b.status?void d(a,c,e):void f(a,c,e,"no-retry")}))):void f(pluploadL10n.upload_failed,c,e,"no-retry")},f=function(a,b,e,f){var g=e.type&&0===e.type.indexOf("image/"),i=b&&b.status;return"no-retry"!==f&&500===i&&g?void d(a,b,e):(e.attachment&&e.attachment.destroy(),c.errors.unshift({message:a||pluploadL10n.default_error,data:b,file:e}),void h.error(a,b,e))},g=function(a,b,d){var e;_.each(["file","loaded","size","percent"],function(a){b.attachment.unset(a)}),b.attachment.set(_.extend(d.data,{uploading:!1})),wp.media.model.Attachment.get(d.data.id,b.attachment),e=c.queue.all(function(a){return!a.get("uploading")}),e&&c.queue.reset(),h.success(b.attachment)},this.uploader.bind("init",function(a){var d,e,f,g=h.dropzone;if(f=h.supports.dragdrop=a.features.dragdrop&&!c.browser.mobile,g){if(g.toggleClass("supports-drag-drop",!!f),!f)return g.unbind(".wp-uploader");g.bind("dragover.wp-uploader",function(){d&&clearTimeout(d),e||(g.trigger("dropzone:enter").addClass("drag-over"),e=!0)}),g.bind("dragleave.wp-uploader, drop.wp-uploader",function(){d=setTimeout(function(){e=!1,g.trigger("dropzone:leave").removeClass("drag-over")},0)}),h.ready=!0,b(h).trigger("uploader:ready")}}),this.uploader.bind("postinit",function(a){a.refresh(),h.init()}),this.uploader.init(),this.browser?this.browser.on("mouseenter",this.refresh):(this.uploader.disableBrowse(!0),b("#"+this.uploader.id+"_html5_container").hide()),this.uploader.bind("BeforeUpload",function(a,b){b.type&&0===b.type.indexOf("image/")?a.settings.multipart_params._wp_temp_upload_ref=b.id:a.settings.multipart_params._wp_temp_upload_ref=""}),this.uploader.bind("FilesAdded",function(a,b){_.each(b,function(a){var b,d;plupload.FAILED!==a.status&&(b=_.extend({file:a,uploading:!0,date:new Date,filename:a.name,menuOrder:0,uploadedTo:wp.media.model.settings.post.id},_.pick(a,"loaded","size","percent")),d=/(?:jpe?g|png|gif)$/i.exec(a.name),d&&(b.type="image",b.subtype="jpg"===d[0]?"jpeg":d[0]),a.attachment=wp.media.model.Attachment.create(b),c.queue.add(a.attachment),h.added(a.attachment))}),a.refresh(),a.start()}),this.uploader.bind("UploadProgress",function(a,b){b.attachment.set(_.pick(b,"loaded","percent")),h.progress(b.attachment)}),this.uploader.bind("FileUploaded",function(a,b,c){try{c=JSON.parse(c.response)}catch(d){return f(pluploadL10n.default_error,d,b)}return!_.isObject(c)||_.isUndefined(c.success)?f(pluploadL10n.default_error,null,b):c.success?void g(a,b,c):f(c.data&&c.data.message,c.data,b)}),this.uploader.bind("Error",function(a,b){var d,e=pluploadL10n.default_error;for(d in c.errorMap)if(b.code===plupload[d]){e=c.errorMap[d],_.isFunction(e)&&(e=e(b.file,b));break}f(e,b,b.file),a.refresh()}))}},b.extend(c,_wpPluploadSettings),c.uuid=0,c.errorMap={FAILED:pluploadL10n.upload_failed,FILE_EXTENSION_ERROR:pluploadL10n.invalid_filetype,IMAGE_FORMAT_ERROR:pluploadL10n.not_an_image,IMAGE_MEMORY_ERROR:pluploadL10n.image_memory_exceeded,IMAGE_DIMENSIONS_ERROR:pluploadL10n.image_dimensions_exceeded,GENERIC_ERROR:pluploadL10n.upload_failed,IO_ERROR:pluploadL10n.io_error,SECURITY_ERROR:pluploadL10n.security_error,FILE_SIZE_ERROR:function(a){return pluploadL10n.file_exceeds_size_limit.replace("%s",a.name)},HTTP_ERROR:function(a){return a.type&&0===a.type.indexOf("image/")?pluploadL10n.http_error_image:pluploadL10n.http_error}},b.extend(c.prototype,{param:function(a,c){return 1===arguments.length&&"string"==typeof a?this.uploader.settings.multipart_params[a]:void(arguments.length>1?this.uploader.settings.multipart_params[a]=c:b.extend(this.uploader.settings.multipart_params,a))},init:function(){},error:function(){},success:function(){},added:function(){},progress:function(){},complete:function(){},refresh:function(){var a,c,d,e;if(this.browser){for(a=this.browser[0];a;){if(a===document.body){c=!0;break}a=a.parentNode}c||(e="wp-uploader-browser-"+this.uploader.id,d=b("#"+e),d.length||(d=b('
').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),d.append(this.browser))}this.uploader.refresh()}}),c.queue=new wp.media.model.Attachments([],{query:!1}),c.errors=new Backbone.Collection,a.Uploader=c)}(wp,jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a,b){var c;"undefined"!=typeof _wpPluploadSettings&&(c=function(a){var d,e,f,g,h=this,i={container:"container",browser:"browse_button",dropzone:"drop_element"},j={};if(this.supports={upload:c.browser.supported},this.supported=this.supports.upload,this.supported){this.plupload=b.extend(!0,{multipart_params:{}},c.defaults),this.container=document.body,b.extend(!0,this,a);for(e in this)b.isFunction(this[e])&&(this[e]=b.proxy(this[e],this));for(e in i)this[e]&&(this[e]=b(this[e]).first(),this[e].length?(this[e].prop("id")||this[e].prop("id","__wp-uploader-id-"+c.uuid++),this.plupload[i[e]]=this[e].prop("id")):delete this[e]);(this.browser&&this.browser.length||this.dropzone&&this.dropzone.length)&&(this.uploader=new plupload.Uploader(this.plupload),delete this.plupload,this.param(this.params||{}),delete this.params,d=function(a,c,e){var i,k;return c&&c.responseHeaders?(k=c.responseHeaders.match(/x-wp-upload-attachment-id:\s*(\d+)/i),k&&k[1]?(k=k[1],i=j[e.id],i&&i>4?(b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,attachment_id:k,_wp_upload_failed_cleanup:!0}}),void f(a,c,e,"no-retry")):(i?j[e.id]=++i:j[e.id]=1,void b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,attachment_id:k}}).done(function(b){b.success?g(h.uploader,e,b):(b.data&&b.data.message&&(a=b.data.message),f(a,c,e,"no-retry"))}).fail(function(b){return 500===b.status?void d(a,c,e):void f(a,c,e,"no-retry")}))):void f(pluploadL10n.http_error_image,c,e,"no-retry")):void f(pluploadL10n.http_error_image,c,e,"no-retry")},f=function(a,b,e,f){var g=e.type&&0===e.type.indexOf("image/"),i=b&&b.status;return"no-retry"!==f&&500===i&&g?void d(a,b,e):(e.attachment&&e.attachment.destroy(),c.errors.unshift({message:a||pluploadL10n.default_error,data:b,file:e}),void h.error(a,b,e))},g=function(a,b,d){var e;_.each(["file","loaded","size","percent"],function(a){b.attachment.unset(a)}),b.attachment.set(_.extend(d.data,{uploading:!1})),wp.media.model.Attachment.get(d.data.id,b.attachment),e=c.queue.all(function(a){return!a.get("uploading")}),e&&c.queue.reset(),h.success(b.attachment)},this.uploader.bind("init",function(a){var d,e,f,g=h.dropzone;if(f=h.supports.dragdrop=a.features.dragdrop&&!c.browser.mobile,g){if(g.toggleClass("supports-drag-drop",!!f),!f)return g.unbind(".wp-uploader");g.bind("dragover.wp-uploader",function(){d&&clearTimeout(d),e||(g.trigger("dropzone:enter").addClass("drag-over"),e=!0)}),g.bind("dragleave.wp-uploader, drop.wp-uploader",function(){d=setTimeout(function(){e=!1,g.trigger("dropzone:leave").removeClass("drag-over")},0)}),h.ready=!0,b(h).trigger("uploader:ready")}}),this.uploader.bind("postinit",function(a){a.refresh(),h.init()}),this.uploader.init(),this.browser?this.browser.on("mouseenter",this.refresh):(this.uploader.disableBrowse(!0),b("#"+this.uploader.id+"_html5_container").hide()),this.uploader.bind("FilesAdded",function(a,b){_.each(b,function(a){var b,d;plupload.FAILED!==a.status&&(b=_.extend({file:a,uploading:!0,date:new Date,filename:a.name,menuOrder:0,uploadedTo:wp.media.model.settings.post.id},_.pick(a,"loaded","size","percent")),d=/(?:jpe?g|png|gif)$/i.exec(a.name),d&&(b.type="image",b.subtype="jpg"===d[0]?"jpeg":d[0]),a.attachment=wp.media.model.Attachment.create(b),c.queue.add(a.attachment),h.added(a.attachment))}),a.refresh(),a.start()}),this.uploader.bind("UploadProgress",function(a,b){b.attachment.set(_.pick(b,"loaded","percent")),h.progress(b.attachment)}),this.uploader.bind("FileUploaded",function(a,b,c){try{c=JSON.parse(c.response)}catch(d){return f(pluploadL10n.default_error,d,b)}return!_.isObject(c)||_.isUndefined(c.success)?f(pluploadL10n.default_error,null,b):c.success?void g(a,b,c):f(c.data&&c.data.message,c.data,b)}),this.uploader.bind("Error",function(a,b){var d,e=pluploadL10n.default_error;for(d in c.errorMap)if(b.code===plupload[d]){e=c.errorMap[d],_.isFunction(e)&&(e=e(b.file,b));break}f(e,b,b.file),a.refresh()}))}},b.extend(c,_wpPluploadSettings),c.uuid=0,c.errorMap={FAILED:pluploadL10n.upload_failed,FILE_EXTENSION_ERROR:pluploadL10n.invalid_filetype,IMAGE_FORMAT_ERROR:pluploadL10n.not_an_image,IMAGE_MEMORY_ERROR:pluploadL10n.image_memory_exceeded,IMAGE_DIMENSIONS_ERROR:pluploadL10n.image_dimensions_exceeded,GENERIC_ERROR:pluploadL10n.upload_failed,IO_ERROR:pluploadL10n.io_error,SECURITY_ERROR:pluploadL10n.security_error,FILE_SIZE_ERROR:function(a){return pluploadL10n.file_exceeds_size_limit.replace("%s",a.name)},HTTP_ERROR:function(a){return a.type&&0===a.type.indexOf("image/")?pluploadL10n.http_error_image:pluploadL10n.http_error}},b.extend(c.prototype,{param:function(a,c){return 1===arguments.length&&"string"==typeof a?this.uploader.settings.multipart_params[a]:void(arguments.length>1?this.uploader.settings.multipart_params[a]=c:b.extend(this.uploader.settings.multipart_params,a))},init:function(){},error:function(){},success:function(){},added:function(){},progress:function(){},complete:function(){},refresh:function(){var a,c,d,e;if(this.browser){for(a=this.browser[0];a;){if(a===document.body){c=!0;break}a=a.parentNode}c||(e="wp-uploader-browser-"+this.uploader.id,d=b("#"+e),d.length||(d=b('
').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),d.append(this.browser))}this.uploader.refresh()}}),c.queue=new wp.media.model.Attachments([],{query:!1}),c.errors=new Backbone.Collection,a.Uploader=c)}(wp,jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index d93a716d9c..7b75ba6ec9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-beta2-46381'; +$wp_version = '5.3-beta2-46382'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.