Make WordPress Core

Changeset 32091


Ignore:
Timestamp:
04/08/2015 10:27:57 PM (10 years ago)
Author:
ocean90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r32088 r32091  
    16931693            this.btnRemove.on( 'click', this.removeImage );
    16941694
    1695             api.HeaderTool.currentHeader = new api.HeaderTool.ImageModel();
     1695            api.HeaderTool.currentHeader = this.getInitialHeaderImage();
    16961696
    16971697            new api.HeaderTool.CurrentView({
     
    17141714                api.HeaderTool.DefaultsList
    17151715            ]);
     1716        },
     1717
     1718        /**
     1719         * Returns a new instance of api.HeaderTool.ImageModel based on the currently
     1720         * saved header image (if any).
     1721         *
     1722         * @since 4.2.0
     1723         *
     1724         * @returns {Object} Options
     1725         */
     1726        getInitialHeaderImage: function() {
     1727            if ( ! api.get().header_image || ! api.get().header_image_data || _.contains( [ 'remove-header', 'random-default-image', 'random-uploaded-image' ], api.get().header_image ) ) {
     1728                return new api.HeaderTool.ImageModel();
     1729            }
     1730
     1731            // Get the matching uploaded image object.
     1732            var currentHeaderObject = _.find( _wpCustomizeHeader.uploads, function( imageObj ) {
     1733                return ( imageObj.attachment_id === api.get().header_image_data.attachment_id );
     1734            } );
     1735            // Fall back to raw current header image.
     1736            if ( ! currentHeaderObject ) {
     1737                currentHeaderObject = {
     1738                    url: api.get().header_image,
     1739                    thumbnail_url: api.get().header_image,
     1740                    attachment_id: api.get().header_image_data.attachment_id
     1741                };
     1742            }
     1743
     1744            return new api.HeaderTool.ImageModel({
     1745                header: currentHeaderObject,
     1746                choice: currentHeaderObject.url.split( '/' ).pop()
     1747            });
    17161748        },
    17171749
Note: See TracChangeset for help on using the changeset viewer.