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: http://core.svn.wordpress.org/trunk@23057 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-12-05 02:31:41 +00:00
parent e1405b6f1d
commit a914ab2e43
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 );