Customize Headers: Improve handling of the initial header model.

Headers are currently keyed by the basename of the image, see #31786. When two images have the same key only one image will be listed and the current image can be empty in the header control.
To prevent this we now fall back to the raw current header image if the image isn't in `_wpCustomizeHeader.uploads`.

props sirbrillig.
fixes #31742.

git-svn-id: https://develop.svn.wordpress.org/trunk@32091 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2015-04-08 22:27:57 +00:00
parent bc3e4176a0
commit 0dee3a771a
1 changed files with 33 additions and 1 deletions

View File

@ -1692,7 +1692,7 @@
this.btnNew.on( 'click', this.openMedia );
this.btnRemove.on( 'click', this.removeImage );
api.HeaderTool.currentHeader = new api.HeaderTool.ImageModel();
api.HeaderTool.currentHeader = this.getInitialHeaderImage();
new api.HeaderTool.CurrentView({
model: api.HeaderTool.currentHeader,
@ -1715,6 +1715,38 @@
]);
},
/**
* Returns a new instance of api.HeaderTool.ImageModel based on the currently
* saved header image (if any).
*
* @since 4.2.0
*
* @returns {Object} Options
*/
getInitialHeaderImage: function() {
if ( ! api.get().header_image || ! api.get().header_image_data || _.contains( [ 'remove-header', 'random-default-image', 'random-uploaded-image' ], api.get().header_image ) ) {
return new api.HeaderTool.ImageModel();
}
// Get the matching uploaded image object.
var currentHeaderObject = _.find( _wpCustomizeHeader.uploads, function( imageObj ) {
return ( imageObj.attachment_id === api.get().header_image_data.attachment_id );
} );
// Fall back to raw current header image.
if ( ! currentHeaderObject ) {
currentHeaderObject = {
url: api.get().header_image,
thumbnail_url: api.get().header_image,
attachment_id: api.get().header_image_data.attachment_id
};
}
return new api.HeaderTool.ImageModel({
header: currentHeaderObject,
choice: currentHeaderObject.url.split( '/' ).pop()
});
},
/**
* Returns a set of options, computed from the attached image data and
* theme-specific data, to be fed to the imgAreaSelect plugin in