From ee70508a25ebc402bbc322ff57a05331df2af7b1 Mon Sep 17 00:00:00 2001 From: SwapnilWordpress Date: Fri, 22 May 2026 20:56:28 +0530 Subject: [PATCH] Media: Correct attachment count in featured image modal. Fixes incorrect media item count shown after uploading and replacing featured images. See #58729. --- src/js/media/models/attachments.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index 23510bd949f4c..85b38621b5376 100644 --- a/src/js/media/models/attachments.js +++ b/src/js/media/models/attachments.js @@ -239,26 +239,32 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen return this; }, /** - * Update total attachment count when items are added to a collection. + * Update total attachment count when items are removed from the mirrored collection. * * @access private * * @since 5.8.0 + * + * @param {wp.media.model.Attachment} attachment The attachment model. + * @param {wp.media.model.Attachments} collection The collection that triggered the event. */ - _removeFromTotalAttachments: function() { - if ( this.mirroring ) { + _removeFromTotalAttachments: function( attachment, collection ) { + if ( this.mirroring && collection === this.mirroring ) { this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1; } }, /** - * Update total attachment count when items are added to a collection. + * Update total attachment count when items are added to the mirrored collection. * * @access private * * @since 5.8.0 + * + * @param {wp.media.model.Attachment} attachment The attachment model. + * @param {wp.media.model.Attachments} collection The collection that triggered the event. */ - _addToTotalAttachments: function() { - if ( this.mirroring ) { + _addToTotalAttachments: function( attachment, collection ) { + if ( this.mirroring && collection === this.mirroring ) { this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1; } },