WordPress.org

Make WordPress Core

Changeset 20913


Ignore:
Timestamp:
05/25/2012 08:26:25 PM (8 years ago)
Author:
koopersmith
Message:

Theme Customizer: Improve background image control, add correct meta key to custom headers and backgrounds uploaded using the customizer. see #19910.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ajax-actions.php

    r20888 r20913  
    16411641    }
    16421642
     1643    if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
     1644        if ( 'custom-background' === $post_data['context'] )
     1645            update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
     1646
     1647        if ( 'custom-header' === $post_data['context'] )
     1648            update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
     1649    }
     1650
    16431651    $post = get_post( $attachment_id );
    16441652
  • trunk/wp-includes/class-wp-customize-control.php

    r20912 r20913  
    399399        <?php
    400400    }
     401
     402    public function print_tab_image( $url, $thumbnail_url = null ) {
     403        $url = set_url_scheme( $url );
     404        $thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
     405        ?>
     406        <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
     407            <img src="<?php echo esc_url( $thumbnail_url ); ?>" />
     408        </a>
     409        <?php
     410    }
     411}
     412
     413class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
     414    public function __construct( $manager ) {
     415        parent::__construct( $manager, 'background_image', array(
     416            'label'    => __( 'Background Image' ),
     417            'section'  => 'background_image',
     418            'context'  => 'custom-background',
     419            'get_url'  => 'get_background_image',
     420        ) );
     421
     422        if ( $this->setting->default )
     423            $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_background' ) );
     424    }
     425
     426    public function tab_uploaded() {
     427        $backgrounds = get_posts( array(
     428            'post_type'  => 'attachment',
     429            'meta_key'   => '_wp_attachment_is_custom_background',
     430            'meta_value' => $this->manager->get_stylesheet(),
     431            'orderby'    => 'none',
     432            'nopaging'   => true,
     433        ) );
     434
     435        ?><div class="uploaded-target"></div><?php
     436
     437        if ( empty( $backgrounds ) )
     438            return;
     439
     440        foreach ( (array) $backgrounds as $background )
     441            $this->print_tab_image( esc_url_raw( $background->guid ) );
     442    }
     443
     444    public function tab_default_background() {
     445        $this->print_tab_image( $this->setting->default );
     446    }
    401447}
    402448
     
    425471        ?><div class="uploaded-target"></div><?php
    426472
    427         foreach ( $headers as $header ) : ?>
    428             <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
    429                 <img src="<?php echo esc_url( set_url_scheme( $header['thumbnail_url'] ) ); ?>" />
    430             </a>
    431         <?php endforeach;
     473        foreach ( $headers as $header )
     474            $this->print_tab_image( $header['url'], $header['thumbnail_url'] );
    432475    }
    433476
     
    436479        $custom_image_header->process_default_headers();
    437480
    438         foreach ( $custom_image_header->default_headers as $header ) : ?>
    439             <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
    440                 <img src="<?php echo esc_url( set_url_scheme( $header['thumbnail_url'] ) ); ?>" />
    441             </a>
    442         <?php endforeach;
    443     }
    444 }
     481        foreach ( $custom_image_header->default_headers as $header )
     482            $this->print_tab_image( $header['url'], $header['thumbnail_url'] );
     483    }
     484}
  • trunk/wp-includes/class-wp-customize-manager.php

    r20912 r20913  
    699699        ) );
    700700
    701         $this->add_control( new WP_Customize_Image_Control( $this, 'background_image', array(
    702             'label'          => __( 'Background Image' ),
    703             'section'        => 'background_image',
    704             'context'        => 'custom-background',
    705         ) ) );
     701        $this->add_control( new WP_Customize_Background_Image_Control( $this ) );
    706702
    707703        $this->add_setting( 'background_repeat', array(
  • trunk/wp-includes/js/customize-controls.dev.js

    r20899 r20913  
    159159            if ( this.params.context )
    160160                control.uploader.param( 'post_data[context]', this.params.context );
     161
     162            control.uploader.param( 'post_data[theme]', api.settings.theme.stylesheet );
    161163        },
    162164        success: function( attachment ) {
Note: See TracChangeset for help on using the changeset viewer.