Customizer: Re-add the possibility to remove and restore a default background image.

see #21483.
fixes #30683 for trunk.

git-svn-id: https://develop.svn.wordpress.org/trunk@30849 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2014-12-14 19:36:27 +00:00
parent 4a662deaa5
commit 326d7f8c5f
2 changed files with 26 additions and 25 deletions

View File

@ -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;

View File

@ -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 {
<# } #>
</label>
<# // 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 ) { #>
<div class="current">
<div class="container">
<div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }}">
@ -773,11 +774,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control {
</div>
</div>
<div class="actions">
<# if ( data.defaultAttachment && data.defaultAttachment.id !== data.attachment.id ) { #>
<button type="button" class="button default-button remove-button"><?php echo $this->button_labels['default']; ?></button>
<# } else if ( ! data.defaultAttachment ) { #>
<button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
<# } #>
<button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
<button type="button" class="button upload-button" id="{{ data.settings.default }}-button"><?php echo $this->button_labels['change']; ?></button>
<div style="clear:both"></div>
</div>
@ -795,7 +792,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control {
</div>
<div class="actions">
<# if ( data.defaultAttachment ) { #>
<button type="button" class="button default-button remove-button"><?php echo $this->button_labels['default']; ?></button>
<button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
<# } #>
<button type="button" class="button upload-button" id="{{ data.settings.default }}-button"><?php echo $this->button_labels['select']; ?></button>
<div style="clear:both"></div>