Make WordPress Core

Changeset 30849


Ignore:
Timestamp:
12/14/2014 07:36:27 PM (9 years ago)
Author:
ocean90
Message:

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

see #21483.
fixes #30683 for trunk.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r30737 r30849  
    606606
    607607.customize-control-upload .remove-button,
     608.customize-control-upload .default-button,
    608609.customize-control-upload .upload-button,
    609610.customize-control-image .remove-button,
     611.customize-control-image .default-button,
    610612.customize-control-image .upload-button,
    611613.customize-control-header button.new,
     
    798800}
    799801
    800 .customize-control-upload .remove-button
    801 .customize-control-image .remove-button
     802.customize-control-upload .remove-button,
     803.customize-control-upload .default-button,
     804.customize-control-image .remove-button,
     805.customize-control-image .default-button,
    802806.customize-control-header .remove {
    803807    float: left;
  • trunk/src/wp-includes/class-wp-customize-control.php

    r30847 r30849  
    688688        $this->json['button_labels'] = $this->button_labels;
    689689
     690        $value = $this->value();
     691
    690692        if ( is_object( $this->setting ) ) {
    691693            if ( $this->setting->default ) {
     
    696698                    'url' => $this->setting->default,
    697699                    'type' => $type,
    698                     'sizes' => array(
    699                         'full' => array( 'url' => $this->setting->default ),
    700                     ),
    701700                    'icon' => wp_mime_type_icon( $type ),
    702701                    'title' => basename( $this->setting->default ),
    703702                );
     703
     704                if ( 'image' === $type ) {
     705                    $default_attachment['sizes'] = array(
     706                        'full' => array( 'url' => $this->setting->default ),
     707                    );
     708                }
     709
    704710                $this->json['defaultAttachment'] = $default_attachment;
    705711            }
    706712
    707             // Get the attachment model for the existing file.
    708             if ( $this->value() ) {
    709                 $attachment_id = attachment_url_to_postid( $this->value() );
     713            if ( $value && $this->setting->default && $value === $this->setting->default ) {
     714                // Set the default as the attachment.
     715                $this->json['attachment'] = $this->json['defaultAttachment'];
     716            } elseif ( $value ) {
     717                // Get the attachment model for the existing file.
     718                $attachment_id = attachment_url_to_postid( $value );
    710719                if ( $attachment_id ) {
    711                     $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id);
     720                    $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
    712721                }
    713             } else if ( $this->setting->default ) {
    714                 // Set the default as the attachment.
    715                 $this->json['attachment'] = $default_attachment;
    716722            }
    717723        }
     
    742748        </label>
    743749
    744         <# // Ensure that the default attachment is used if it exists.
    745         if ( _.isEmpty( data.attachment ) && data.defaultAttachment ) {
    746             data.attachment = data.defaultAttachment;
    747         }
    748 
    749         if ( data.attachment && data.attachment.id ) { #>
     750        <# if ( data.attachment && data.attachment.id ) { #>
    750751            <div class="current">
    751752                <div class="container">
     
    774775            </div>
    775776            <div class="actions">
    776                 <# if ( data.defaultAttachment && data.defaultAttachment.id !== data.attachment.id ) { #>
    777                     <button type="button" class="button default-button remove-button"><?php echo $this->button_labels['default']; ?></button>
    778                 <# } else if ( ! data.defaultAttachment ) { #>
    779                     <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
    780                 <# } #>
     777                <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
    781778                <button type="button" class="button upload-button" id="{{ data.settings.default }}-button"><?php echo $this->button_labels['change']; ?></button>
    782779                <div style="clear:both"></div>
     
    796793            <div class="actions">
    797794                <# if ( data.defaultAttachment ) { #>
    798                     <button type="button" class="button default-button remove-button"><?php echo $this->button_labels['default']; ?></button>
     795                    <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
    799796                <# } #>
    800797                <button type="button" class="button upload-button" id="{{ data.settings.default }}-button"><?php echo $this->button_labels['select']; ?></button>
Note: See TracChangeset for help on using the changeset viewer.