diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/js/wp-util.js --- a/wp/wp-includes/js/wp-util.js Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/js/wp-util.js Wed Sep 21 18:19:35 2022 +0200 @@ -115,6 +115,22 @@ } if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) { + + // When handling a media attachments request, get the total attachments from response headers. + var context = this; + deferred.done( function() { + if ( + action && + action.data && + 'query-attachments' === action.data.action && + deferred.jqXHR.hasOwnProperty( 'getResponseHeader' ) && + deferred.jqXHR.getResponseHeader( 'X-WP-Total' ) + ) { + context.totalAttachments = parseInt( deferred.jqXHR.getResponseHeader( 'X-WP-Total' ), 10 ); + } else { + context.totalAttachments = 0; + } + } ); deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] ); } else { deferred.rejectWith( this, [response] );