Changeset 46174
- Timestamp:
- 09/19/2019 01:25:14 AM (6 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/vendor/plupload/handlers.js
r46081 r46174 451 451 action: 'media-create-image-subsizes', 452 452 _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, 453 _wp_temp_ image_ref: file.id,453 _wp_temp_upload_ref: file.id, 454 454 _wp_upload_failed_cleanup: true, 455 455 } … … 479 479 action: 'media-create-image-subsizes', 480 480 _wpnonce: wpUploaderInit.multipart_params._wpnonce, 481 _wp_temp_ image_ref: file.id,481 _wp_temp_upload_ref: file.id, 482 482 _legasy_support: 'true', 483 483 } … … 600 600 uploader.bind( 'BeforeUpload', function( up, file ) { 601 601 if ( file.type && file.type.indexOf( 'image/' ) === 0 ) { 602 up.settings.multipart_params._wp_temp_ image_ref = file.id;602 up.settings.multipart_params._wp_temp_upload_ref = file.id; 603 603 } else { 604 up.settings.multipart_params._wp_temp_ image_ref = '';604 up.settings.multipart_params._wp_temp_upload_ref = ''; 605 605 } 606 606 } ); -
trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js
r46081 r46174 139 139 action: 'media-create-image-subsizes', 140 140 _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, 141 _wp_temp_ image_ref: file.id,141 _wp_temp_upload_ref: file.id, 142 142 _wp_upload_failed_cleanup: true, 143 143 } … … 162 162 action: 'media-create-image-subsizes', 163 163 _wpnonce: _wpPluploadSettings.defaults.multipart_params._wpnonce, 164 _wp_temp_ image_ref: file.id, // Used to find the new attachment_id.164 _wp_temp_upload_ref: file.id, // Used to find the new attachment_id. 165 165 } 166 166 }).done( function( response ) { … … 325 325 this.uploader.bind( 'BeforeUpload', function( up, file ) { 326 326 if ( file.type && file.type.indexOf( 'image/' ) === 0 ) { 327 up.settings.multipart_params._wp_temp_ image_ref = file.id;327 up.settings.multipart_params._wp_temp_upload_ref = file.id; 328 328 } else { 329 up.settings.multipart_params._wp_temp_ image_ref = '';329 up.settings.multipart_params._wp_temp_upload_ref = ''; 330 330 } 331 331 } ); -
trunk/src/wp-admin/includes/ajax-actions.php
r46155 r46174 2423 2423 } 2424 2424 2425 // Using Plupload `file.id` as ref. 2426 if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) { 2427 $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] ); 2425 if ( ! empty( $_POST['_wp_temp_upload_ref'] ) ) { 2426 // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory. 2427 // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error 2428 // the cliend doesn't know the attachment ID yet. 2429 // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client 2430 // in the original upload request. It is used to save a transient with the attachment_id as value. 2431 // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string. 2432 $attachment_id = _wp_get_upload_ref_attachment_id( $_POST['_wp_temp_upload_ref'] ); 2428 2433 } else { 2429 2434 wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) ); 2430 2435 } 2431 2432 // Uploading of images usually fails while creating the sub-sizes, either because of a timeout or out of memory.2433 // At this point the file has been uploaded and an attachment post created, but because of the PHP fatal error2434 // the cliend doesn't know the attachment ID yet.2435 // To be able to find the new attachment_id in these cases we temporarily store an upload reference sent by the client2436 // in the original upload request. It is used to save a transient with the attachment_id as value.2437 // That reference currently is Plupload's `file.id` but can be any sufficiently random alpha-numeric string.2438 $attachment_id = get_transient( '_wp_temp_image_ref:' . $image_ref );2439 2436 2440 2437 if ( empty( $attachment_id ) ) { … … 2482 2479 2483 2480 // At this point the image has been uploaded successfully. 2484 delete_transient( '_wp_temp_image_ref:' . $image_ref);2481 _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] ); 2485 2482 2486 2483 wp_send_json_success( $response ); -
trunk/src/wp-admin/includes/file.php
r45932 r46174 979 979 } 980 980 981 /** 982 * Temporarily stores the client upload reference in a transient. 983 * 984 * @since 5.3.0 985 * @access private 986 * 987 * @param string $upload_ref The upload reference sent by the client. 988 * @param int $attachment_id Attachment post ID. 989 * @return bool Whether the transient was set. 990 */ 991 function _wp_set_upload_ref( $upload_ref, $attachment_id ) { 992 $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); 993 994 if ( ! empty( $upload_ref ) ) { 995 return set_transient( '_wp_temp_image_ref:' . $upload_ref, $attachment_id, HOUR_IN_SECONDS ); 996 } 997 998 return false; 999 } 1000 1001 /** 1002 * Get attachment post ID from an upload reference. 1003 * 1004 * @since 5.3.0 1005 * @access private 1006 * 1007 * @param string $upload_ref The upload reference sent by the client. 1008 * @return int The attachemtn post ID. Zero if the upload reference has expired or doesn't exist. 1009 */ 1010 function _wp_get_upload_ref_attachment_id( $upload_ref ) { 1011 $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); 1012 1013 if ( ! empty( $upload_ref ) ) { 1014 return (int) get_transient( '_wp_temp_image_ref:' . $upload_ref ); 1015 } 1016 1017 return 0; 1018 } 1019 1020 /** 1021 * Remove the transient that stores a temporary upload reference. 1022 * 1023 * @since 5.3.0 1024 * @access private 1025 * 1026 * @param string $upload_ref The upload reference sent by the client. 1027 * @return bool Whether the transient was removed. 1028 */ 1029 function _wp_clear_upload_ref( $upload_ref ) { 1030 $upload_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $upload_ref ); 1031 1032 if ( ! empty( $upload_ref ) ) { 1033 return delete_transient( '_wp_temp_image_ref:' . $upload_ref ); 1034 } 1035 1036 return false; 1037 } 981 1038 982 1039 /** -
trunk/src/wp-admin/includes/media.php
r46131 r46174 309 309 $name = wp_basename( $name, ".$ext" ); 310 310 311 $url 312 $type 313 $file 314 $title 315 $content 316 $excerpt 317 $ image_ref= false;311 $url = $file['url']; 312 $type = $file['type']; 313 $file = $file['file']; 314 $title = sanitize_text_field( $name ); 315 $content = ''; 316 $excerpt = ''; 317 $_ref = false; 318 318 319 319 if ( preg_match( '#^audio#', $type ) ) { … … 377 377 // Use image exif/iptc data for title and caption defaults if possible. 378 378 } elseif ( 0 === strpos( $type, 'image/' ) ) { 379 // Image file reference passed by the uploader.380 if ( ! empty( $_POST['_wp_temp_image_ref'] ) ) {381 $image_ref = preg_replace( '/[^a-zA-Z0-9_]/', '', $_POST['_wp_temp_image_ref'] );382 }383 384 379 $image_meta = wp_read_image_metadata( $file ); 385 380 … … 416 411 if ( ! is_wp_error( $attachment_id ) ) { 417 412 // If an image, keep the upload reference until all image sub-sizes are created. 418 if ( $image_ref) {419 set_transient( '_wp_temp_image_ref:' . $image_ref, $attachment_id, HOUR_IN_SECONDS);413 if ( ! empty( $_POST['_wp_temp_upload_ref'] ) && wp_attachment_is_image( $attachment_id ) ) { 414 $_ref = _wp_set_upload_ref( $_POST['_wp_temp_upload_ref'], $attachment_id ); 420 415 } 421 416 … … 426 421 // At this point the image is uploaded successfully even if there were specific errors or some sub-sizes were not created. 427 422 // The transient is not needed any more. 428 if ( $ image_ref ) {429 delete_transient( '_wp_temp_image_ref:' . $image_ref);423 if ( $_ref ) { 424 _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] ); 430 425 } 431 426 }
Note: See TracChangeset
for help on using the changeset viewer.