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. Built from https://develop.svn.wordpress.org/trunk@32091 git-svn-id: http://core.svn.wordpress.org/trunk@32070 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
de3e344b2a
commit
d43d1503f7
|
@ -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
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-beta4-32090';
|
||||
$wp_version = '4.2-beta4-32091';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue