WordPress.org

Make WordPress Core

Changeset 23057


Ignore:
Timestamp:
12/05/12 02:31:41 (2 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-models.js

    r23045 r23057  
    143143                // Use with PHP's wp_send_json_success() and wp_send_json_error() 
    144144                $.ajax( options ).done( function( response ) { 
     145                    // Treat a response of `1` as successful for backwards 
     146                    // compatibility with existing handlers. 
     147                    if ( response === '1' || response === 1 ) 
     148                        response = { success: true }; 
     149 
    145150                    if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) 
    146151                        deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] ); 
     
    265270            } else if ( 'delete' === method ) { 
    266271                options = options || {}; 
     272 
     273                if ( ! options.wait ) 
     274                    this.destroyed = true; 
     275 
    267276                options.context = this; 
    268277                options.data = _.extend( options.data || {}, { 
     
    271280                    _wpnonce: this.get('nonces')['delete'] 
    272281                }); 
    273                 return media.ajax( options ); 
     282 
     283                return media.ajax( options ).done( function() { 
     284                    this.destroyed = true; 
     285                }).fail( function() { 
     286                    this.destroyed = false; 
     287                }); 
    274288            } 
    275289        }, 
     
    402416        }, 
    403417 
     418        validateDestroyed: false, 
     419 
    404420        validator: function( attachment ) { 
     421            if ( ! this.validateDestroyed && attachment.destroyed ) 
     422                return false; 
    405423            return _.all( this.filters, function( filter, key ) { 
    406424                return !! filter.call( this, attachment ); 
Note: See TracChangeset for help on using the changeset viewer.