Media models: Trac and ignore deleted attachments.

Treat an admin-ajax response of 1 as successful for backwards compatibility with existing handlers.

props koopersmith. fixes #22750.



git-svn-id: https://develop.svn.wordpress.org/trunk@23057 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-12-05 02:31:41 +00:00
parent 01e7e10bf7
commit bc8f994e7b
1 changed files with 19 additions and 1 deletions

View File

@ -142,6 +142,11 @@ window.wp = window.wp || {};
// Use with PHP's wp_send_json_success() and wp_send_json_error()
$.ajax( options ).done( function( response ) {
// Treat a response of `1` as successful for backwards
// compatibility with existing handlers.
if ( response === '1' || response === 1 )
response = { success: true };
if ( _.isObject( response ) && ! _.isUndefined( response.success ) )
deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
else
@ -264,13 +269,22 @@ window.wp = window.wp || {};
// This will permanently delete an attachment.
} else if ( 'delete' === method ) {
options = options || {};
if ( ! options.wait )
this.destroyed = true;
options.context = this;
options.data = _.extend( options.data || {}, {
action: 'delete-post',
id: this.id,
_wpnonce: this.get('nonces')['delete']
});
return media.ajax( options );
return media.ajax( options ).done( function() {
this.destroyed = true;
}).fail( function() {
this.destroyed = false;
});
}
},
@ -401,7 +415,11 @@ window.wp = window.wp || {};
this.reset( this._source.filter( this.validator, this ) );
},
validateDestroyed: false,
validator: function( attachment ) {
if ( ! this.validateDestroyed && attachment.destroyed )
return false;
return _.all( this.filters, function( filter, key ) {
return !! filter.call( this, attachment );
}, this );