Media: Update total attachment count when media added or removed.

Add handlers to increment the total attachments count for the media collection when an item is added or removed.

props adamsilverstein.
Fixes #53171.
Built from https://develop.svn.wordpress.org/trunk@51191


git-svn-id: http://core.svn.wordpress.org/trunk@50800 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson
2021-06-21 20:46:02 +00:00
parent dc51282844
commit d5c9c310e7
3 changed files with 28 additions and 2 deletions

View File

@@ -591,6 +591,8 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
this.observers.push( attachments );
attachments.on( 'add change remove', this._validateHandler, this );
attachments.on( 'add', this._addToTotalAttachments, this );
attachments.on( 'remove', this._removeFromTotalAttachments, this );
attachments.on( 'reset', this._validateAllHandler, this );
this.validateAll( attachments );
return this;
@@ -615,6 +617,30 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
return this;
},
/**
* Update total attachment count when items are added to a collection.
*
* @access private
*
* @since 5.8.0
*/
_removeFromTotalAttachments: function() {
if ( this.mirroring ) {
this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1;
}
},
/**
* Update total attachment count when items are added to a collection.
*
* @access private
*
* @since 5.8.0
*/
_addToTotalAttachments: function() {
if ( this.mirroring ) {
this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1;
}
},
/**
* @access private
*

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-beta2-51190';
$wp_version = '5.8-beta2-51191';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.