Ticket #22446: 22446.upload.diff
File 22446.upload.diff, 1.9 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
1585 1585 check_ajax_referer( 'media-form' ); 1586 1586 1587 1587 if ( ! current_user_can( 'upload_files' ) ) 1588 wp_ send_json_error();1588 wp_die(); 1589 1589 1590 1590 if ( isset( $_REQUEST['post_id'] ) ) { 1591 1591 $post_id = $_REQUEST['post_id']; 1592 1592 if ( ! current_user_can( 'edit_post', $post_id ) ) 1593 wp_ send_json_error();1593 wp_die(); 1594 1594 } else { 1595 1595 $post_id = null; 1596 1596 } … … 1601 1601 if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { 1602 1602 $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false ); 1603 1603 if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { 1604 wp_send_json_error( array( 1604 echo json_encode( array( 1605 'success' => false, 1605 1606 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), 1606 1607 'filename' => $_FILES['async-upload']['name'], 1607 1608 ) ); 1609 1610 wp_die(); 1608 1611 } 1609 1612 } 1610 1613 1611 1614 $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); 1612 1615 1613 1616 if ( is_wp_error( $attachment_id ) ) { 1614 wp_send_json_error( array( 1617 echo json_encode( array( 1618 'success' => false, 1615 1619 'message' => $attachment_id->get_error_message(), 1616 1620 'filename' => $_FILES['async-upload']['name'], 1617 1621 ) ); 1622 1623 wp_die(); 1618 1624 } 1619 1625 1620 1626 if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) { … … 1626 1632 } 1627 1633 1628 1634 if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) 1629 wp_ send_json_error();1635 wp_die(); 1630 1636 1631 wp_send_json_success( $attachment ); 1637 echo json_encode( array( 1638 'success' => true, 1639 'data' => $attachment, 1640 ) ); 1641 1642 wp_die(); 1632 1643 } 1633 1644 1634 1645 function wp_ajax_image_editor() {