Make WordPress Core

Ticket #22149: 22149.3.diff

File 22149.3.diff, 2.6 KB (added by kovshenin, 13 years ago)

Added a similar scenario for async uploads.

  • wp-admin/includes/ajax-actions.php

     
    16091609
    16101610        $post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
    16111611
     1612        // If the context is custom header or background, make sure the uploaded file is an image.
     1613        if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
     1614                $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false );
     1615                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
     1616                        wp_send_json_error( array(
     1617                                'message' => __( 'The uploaded file is not a valid image. Please try again.' ),
     1618                                'filename' => $_FILES['async-upload']['name'],
     1619                        ) );
     1620                }
     1621        }
     1622
    16121623        $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
    16131624
    16141625        if ( is_wp_error( $attachment_id ) ) {
  • wp-admin/custom-header.php

     
    763763         */
    764764        function step_2_manage_upload() {
    765765                $overrides = array('test_form' => false);
    766                 $file = wp_handle_upload($_FILES['import'], $overrides);
    767766
     767                $file = $_FILES['import'];
     768                $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], false );
     769                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
     770                        wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
     771
     772                $file = wp_handle_upload($file, $overrides);
     773
    768774                if ( isset($file['error']) )
    769775                        wp_die( $file['error'],  __( 'Image Upload Error' ) );
    770776
  • wp-admin/custom-background.php

     
    358358
    359359                check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
    360360                $overrides = array('test_form' => false);
    361                 $file = wp_handle_upload($_FILES['import'], $overrides);
    362361
     362                $file = $_FILES['import'];
     363                $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], false );
     364                if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
     365                        wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
     366
     367                $file = wp_handle_upload($file, $overrides);
     368
    363369                if ( isset($file['error']) )
    364370                        wp_die( $file['error'] );
    365371