Media: Fix selections in Media Library Featured Image modal on open.

In [50829] infinite scrolling was removed from the Media Library and modal which introduced unintended behavior for featured images where only the selected image shows when opening the library. This change reverts only the logic that caused this and applies a proper fix when opening the library.

Props benitolopez, hellofromTonya, joedolson, peterwilsoncc, circlecube, danielbachhuber, PieWP, sabernhardt, szaqal21, dariak, sergeybiryukov.
Fixes #53765.

Built from https://develop.svn.wordpress.org/trunk@52384


git-svn-id: http://core.svn.wordpress.org/trunk@51976 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
antpb 2021-12-17 20:17:05 +00:00
parent 0795991b6f
commit a6a27970a9
3 changed files with 14 additions and 16 deletions

View File

@ -4064,9 +4064,7 @@ FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prot
*/
updateSelection: function() {
var selection = this.get('selection'),
library = this.get('library'),
id = wp.media.view.settings.post.featuredImageId,
infiniteScrolling = wp.media.view.settings.infiniteScrolling,
attachment;
if ( '' !== id && -1 !== id ) {
@ -4075,10 +4073,6 @@ FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prot
}
selection.reset( attachment ? [ attachment ] : [] );
if ( ! infiniteScrolling && library.hasMore() ) {
library.more();
}
}
});
@ -7465,24 +7459,28 @@ ReplaceImage = Library.extend(/** @lends wp.media.controller.ReplaceImage.protot
* @since 3.9.0
*/
activate: function() {
this.updateSelection();
this.frame.on( 'content:render:browse', this.updateSelection, this );
Library.prototype.activate.apply( this, arguments );
},
/**
* @since 5.9.0
*/
deactivate: function() {
this.frame.off( 'content:render:browse', this.updateSelection, this );
Library.prototype.deactivate.apply( this, arguments );
},
/**
* @since 3.9.0
*/
updateSelection: function() {
var selection = this.get('selection'),
library = this.get('library'),
attachment = this.image.attachment,
infiniteScrolling = wp.media.view.settings.infiniteScrolling;
attachment = this.image.attachment;
selection.reset( attachment ? [ attachment ] : [] );
if ( ! infiniteScrolling && library.getTotalAttachments() === 0 && library.hasMore() ) {
library.more();
}
}
});

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-beta3-52383';
$wp_version = '5.9-beta3-52384';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.