diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css index 0357c81d53..d58c632b5a 100644 --- a/src/wp-admin/css/customize-controls.css +++ b/src/wp-admin/css/customize-controls.css @@ -605,8 +605,10 @@ p.customize-section-description { } .customize-control-upload .remove-button, +.customize-control-upload .default-button, .customize-control-upload .upload-button, .customize-control-image .remove-button, +.customize-control-image .default-button, .customize-control-image .upload-button, .customize-control-header button.new, .customize-control-header button.remove { @@ -797,8 +799,10 @@ p.customize-section-description { border-radius: 2px; } -.customize-control-upload .remove-button -.customize-control-image .remove-button +.customize-control-upload .remove-button, +.customize-control-upload .default-button, +.customize-control-image .remove-button, +.customize-control-image .default-button, .customize-control-header .remove { float: left; margin-right: 3px; diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 93c707d733..380b0c7abe 100644 --- a/src/wp-includes/class-wp-customize-control.php +++ b/src/wp-includes/class-wp-customize-control.php @@ -687,6 +687,8 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; + $value = $this->value(); + if ( is_object( $this->setting ) ) { if ( $this->setting->default ) { // Fake an attachment model - needs all fields used by template. @@ -695,24 +697,28 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { 'id' => 1, 'url' => $this->setting->default, 'type' => $type, - 'sizes' => array( - 'full' => array( 'url' => $this->setting->default ), - ), 'icon' => wp_mime_type_icon( $type ), 'title' => basename( $this->setting->default ), ); + + if ( 'image' === $type ) { + $default_attachment['sizes'] = array( + 'full' => array( 'url' => $this->setting->default ), + ); + } + $this->json['defaultAttachment'] = $default_attachment; } - // Get the attachment model for the existing file. - if ( $this->value() ) { - $attachment_id = attachment_url_to_postid( $this->value() ); - if ( $attachment_id ) { - $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id); - } - } else if ( $this->setting->default ) { + if ( $value && $this->setting->default && $value === $this->setting->default ) { // Set the default as the attachment. - $this->json['attachment'] = $default_attachment; + $this->json['attachment'] = $this->json['defaultAttachment']; + } elseif ( $value ) { + // Get the attachment model for the existing file. + $attachment_id = attachment_url_to_postid( $value ); + if ( $attachment_id ) { + $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id ); + } } } } @@ -741,12 +747,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { <# } #> - <# // Ensure that the default attachment is used if it exists. - if ( _.isEmpty( data.attachment ) && data.defaultAttachment ) { - data.attachment = data.defaultAttachment; - } - - if ( data.attachment && data.attachment.id ) { #> + <# if ( data.attachment && data.attachment.id ) { #>
@@ -773,11 +774,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control {
- <# if ( data.defaultAttachment && data.defaultAttachment.id !== data.attachment.id ) { #> - - <# } else if ( ! data.defaultAttachment ) { #> - - <# } #> +
@@ -795,7 +792,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control {
<# if ( data.defaultAttachment ) { #> - + <# } #>