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.
git-svn-id: http://core.svn.wordpress.org/trunk@21814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1611,12 +1611,12 @@ function wp_ajax_upload_attachment() {
|
||||
check_ajax_referer( 'media-form' );
|
||||
|
||||
if ( ! current_user_can( 'upload_files' ) )
|
||||
wp_die( -1 );
|
||||
wp_send_json_error();
|
||||
|
||||
if ( isset( $_REQUEST['post_id'] ) ) {
|
||||
$post_id = $_REQUEST['post_id'];
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) )
|
||||
wp_die( -1 );
|
||||
wp_send_json_error();
|
||||
} else {
|
||||
$post_id = null;
|
||||
}
|
||||
@@ -1626,14 +1626,10 @@ function wp_ajax_upload_attachment() {
|
||||
$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
|
||||
|
||||
if ( is_wp_error( $attachment_id ) ) {
|
||||
echo json_encode( array(
|
||||
'type' => 'error',
|
||||
'data' => array(
|
||||
'message' => $attachment_id->get_error_message(),
|
||||
'filename' => $_FILES['async-upload']['name'],
|
||||
),
|
||||
wp_send_json_error( array(
|
||||
'message' => $attachment_id->get_error_message(),
|
||||
'filename' => $_FILES['async-upload']['name'],
|
||||
) );
|
||||
wp_die();
|
||||
}
|
||||
|
||||
if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
|
||||
@@ -1644,19 +1640,10 @@ function wp_ajax_upload_attachment() {
|
||||
update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
|
||||
}
|
||||
|
||||
$post = get_post( $attachment_id );
|
||||
if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
|
||||
wp_send_json_error();
|
||||
|
||||
echo json_encode( array(
|
||||
'type' => 'success',
|
||||
'data' => array(
|
||||
'id' => $attachment_id,
|
||||
'title' => esc_attr( $post->post_title ),
|
||||
'filename' => esc_html( basename( $post->guid ) ),
|
||||
'url' => wp_get_attachment_url( $attachment_id ),
|
||||
'meta' => wp_get_attachment_metadata( $attachment_id ),
|
||||
),
|
||||
) );
|
||||
wp_die();
|
||||
wp_send_json_success( $attachment );
|
||||
}
|
||||
|
||||
function wp_ajax_image_editor() {
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
this.removerVisibility( this.setting.get() );
|
||||
},
|
||||
success: function( attachment ) {
|
||||
this.setting.set( attachment.url );
|
||||
this.setting.set( attachment.get('url') );
|
||||
},
|
||||
removerVisibility: function( to ) {
|
||||
this.remover.toggle( to != this.params.removed );
|
||||
@@ -272,9 +272,10 @@
|
||||
if ( this.tabs.uploaded && this.tabs.uploaded.target.length ) {
|
||||
this.tabs.uploaded.both.removeClass('hidden');
|
||||
|
||||
// @todo: Do NOT store this on the attachment model. That is bad.
|
||||
attachment.element = $( '<a href="#" class="thumbnail"></a>' )
|
||||
.data( 'customizeImageValue', attachment.url )
|
||||
.append( '<img src="' + attachment.url+ '" />' )
|
||||
.data( 'customizeImageValue', attachment.get('url') )
|
||||
.append( '<img src="' + attachment.get('url')+ '" />' )
|
||||
.appendTo( this.tabs.uploaded.target );
|
||||
}
|
||||
},
|
||||
@@ -945,16 +946,16 @@
|
||||
api.ImageControl.prototype.success.call( control, attachment );
|
||||
|
||||
data = {
|
||||
attachment_id: attachment.id,
|
||||
url: attachment.url,
|
||||
thumbnail_url: attachment.url,
|
||||
height: attachment.meta.height,
|
||||
width: attachment.meta.width
|
||||
attachment_id: attachment.get('id'),
|
||||
url: attachment.get('url'),
|
||||
thumbnail_url: attachment.get('url'),
|
||||
height: attachment.get('height'),
|
||||
width: attachment.get('width')
|
||||
};
|
||||
|
||||
attachment.element.data( 'customizeHeaderImageData', data );
|
||||
control.settings.data.set( data );
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
api.trigger( 'ready' );
|
||||
|
||||
Reference in New Issue
Block a user