Make WordPress Core

Changeset 22845


Ignore:
Timestamp:
11/26/2012 08:12:50 PM (12 years ago)
Author:
nacin
Message:

Don't use wp_send_json_* handlers in the upload-attachment XHR handler.

The difference is the content type: application/json (which jQuery deserializes automatically for us) and the default text/html.

jQuery correctly handles application/json requests for IE, so we can continue to use the wp_send_json_* handlers elsewhere. Plupload rolls its own requests and does not handle application/json correctly. So, keep the standard text/html content type on upload-attachment.

props koopersmith.
see #22446.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ajax-actions.php

    r22843 r22845  
    15861586
    15871587    if ( ! current_user_can( 'upload_files' ) )
    1588         wp_send_json_error();
     1588        wp_die();
    15891589
    15901590    if ( isset( $_REQUEST['post_id'] ) ) {
    15911591        $post_id = $_REQUEST['post_id'];
    15921592        if ( ! current_user_can( 'edit_post', $post_id ) )
    1593             wp_send_json_error();
     1593            wp_die();
    15941594    } else {
    15951595        $post_id = null;
     
    16021602        $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false );
    16031603        if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
    1604             wp_send_json_error( array(
     1604            echo json_encode( array(
     1605                'success'  => false,
    16051606                'message' => __( 'The uploaded file is not a valid image. Please try again.' ),
    16061607                'filename' => $_FILES['async-upload']['name'],
    16071608            ) );
     1609
     1610            wp_die();
    16081611        }
    16091612    }
     
    16121615
    16131616    if ( is_wp_error( $attachment_id ) ) {
    1614         wp_send_json_error( array(
     1617        echo json_encode( array(
     1618            'success'  => false,
    16151619            'message'  => $attachment_id->get_error_message(),
    16161620            'filename' => $_FILES['async-upload']['name'],
    16171621        ) );
     1622
     1623        wp_die();
    16181624    }
    16191625
     
    16271633
    16281634    if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
    1629         wp_send_json_error();
    1630 
    1631     wp_send_json_success( $attachment );
     1635        wp_die();
     1636
     1637    echo json_encode( array(
     1638        'success' => true,
     1639        'data'    => $attachment,
     1640    ) );
     1641
     1642    wp_die();
    16321643}
    16331644
Note: See TracChangeset for help on using the changeset viewer.