wp/wp-includes/js/wp-util.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
--- 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] );