Make WordPress Core


Ignore:
Timestamp:
09/11/2012 04:55:58 PM (12 years ago)
Author:
koopersmith
Message:

Use JS Attachment models in wp.Uploader. fixes #21868.

Moves the uploading Attachments queue from the media workspace view to the uploader itself. This ensures that all attachments are added to the central attachmnet store.

Updates wp.Uploader to pass Attachment models to callbacks instead of Plupload file objects. Attachments in the process of uploading have a reference to the file object (which can be fetched by calling attachment.get('file');).

Also updates the customizer to be compatible with the API changes.

File:
1 edited

Legend:

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

    r21682 r21814  
    16121612
    16131613    if ( ! current_user_can( 'upload_files' ) )
    1614         wp_die( -1 );
     1614        wp_send_json_error();
    16151615
    16161616    if ( isset( $_REQUEST['post_id'] ) ) {
    16171617        $post_id = $_REQUEST['post_id'];
    16181618        if ( ! current_user_can( 'edit_post', $post_id ) )
    1619             wp_die( -1 );
     1619            wp_send_json_error();
    16201620    } else {
    16211621        $post_id = null;
     
    16271627
    16281628    if ( is_wp_error( $attachment_id ) ) {
    1629         echo json_encode( array(
    1630             'type' => 'error',
    1631             'data' => array(
    1632                 'message'  => $attachment_id->get_error_message(),
    1633                 'filename' => $_FILES['async-upload']['name'],
    1634             ),
     1629        wp_send_json_error( array(
     1630            'message'  => $attachment_id->get_error_message(),
     1631            'filename' => $_FILES['async-upload']['name'],
    16351632        ) );
    1636         wp_die();
    16371633    }
    16381634
     
    16451641    }
    16461642
    1647     $post = get_post( $attachment_id );
    1648 
    1649     echo json_encode( array(
    1650         'type' => 'success',
    1651         'data' => array(
    1652             'id'       => $attachment_id,
    1653             'title'    => esc_attr( $post->post_title ),
    1654             'filename' => esc_html( basename( $post->guid ) ),
    1655             'url'      => wp_get_attachment_url( $attachment_id ),
    1656             'meta'     => wp_get_attachment_metadata( $attachment_id ),
    1657         ),
    1658     ) );
    1659     wp_die();
     1643    if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
     1644        wp_send_json_error();
     1645
     1646    wp_send_json_success( $attachment );
    16601647}
    16611648
Note: See TracChangeset for help on using the changeset viewer.