Changeset 46382 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 10/03/2019 09:00:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r46253 r46382 2423 2423 } 2424 2424 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'] ); 2433 } else { 2434 wp_send_json_error( array( 'message' => __( 'Invalid file reference.' ) ) ); 2435 } 2436 2437 if ( empty( $attachment_id ) ) { 2425 if ( empty( $_POST['attachment_id'] ) ) { 2438 2426 wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); 2439 2427 } 2428 2429 $attachment_id = (int) $_POST['attachment_id']; 2440 2430 2441 2431 if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { 2442 2432 // Upload failed. Cleanup. 2443 if ( wp_attachment_is_image( $attachment_id ) ) {2433 if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) { 2444 2434 $attachment = get_post( $attachment_id ); 2445 2435 2446 // Posted at most 10 min ago.2436 // Created at most 10 min ago. 2447 2437 if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { 2448 /**2449 * Runs when an image upload fails during the post-processing phase,2450 * and the newly created attachment post is about to be deleted.2451 *2452 * @since 5.3.02453 *2454 * @param int $attachment_id The attachment post ID.2455 */2456 do_action( 'wp_upload_failed_cleanup', $attachment_id );2457 2458 2438 wp_delete_attachment( $attachment_id, true ); 2459 2439 wp_send_json_success(); … … 2466 2446 wp_update_image_subsizes( $attachment_id ); 2467 2447 2468 if ( ! empty( $_POST['_lega sy_support'] ) ) {2448 if ( ! empty( $_POST['_legacy_support'] ) ) { 2469 2449 // The old (inline) uploader. Only needs the attachment_id. 2470 2450 $response = array( 'id' => $attachment_id ); … … 2479 2459 2480 2460 // At this point the image has been uploaded successfully. 2481 _wp_clear_upload_ref( $_POST['_wp_temp_upload_ref'] );2482 2483 2461 wp_send_json_success( $response ); 2484 2462 }
Note: See TracChangeset
for help on using the changeset viewer.