Make WordPress Core


Ignore:
Timestamp:
05/25/2012 08:26:25 PM (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.