Message info
 
To:wp-svn@lists.automattic.com From:m@wordpress.org Subject:[wp-svn] [20913] trunk: Theme Customizer: Improve background image control, add correct meta key to custom headers and backgrounds uploaded using the customizer . Date:Fri, 25 May 2012 20:26:25 +0000 (UTC)
 

Revision
20913
Author
koopersmith
Date
2012-05-25 20:26:25 +0000 (Fri, 25 May 2012)

Log Message

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

Modified Paths

Diff

Modified: trunk/wp-admin/includes/ajax-actions.php (20912 => 20913)


--- trunk/wp-admin/includes/ajax-actions.php	2012-05-25 19:52:54 UTC (rev 20912)
+++ trunk/wp-admin/includes/ajax-actions.php	2012-05-25 20:26:25 UTC (rev 20913)
@@ -1640,6 +1640,14 @@
 		wp_die();
 	}
 
+	if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
+		if ( 'custom-background' === $post_data['context'] )
+			update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
+
+		if ( 'custom-header' === $post_data['context'] )
+			update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
+	}
+
 	$post = get_post( $attachment_id );
 
 	echo json_encode( array(

Modified: trunk/wp-includes/class-wp-customize-control.php (20912 => 20913)


--- trunk/wp-includes/class-wp-customize-control.php	2012-05-25 19:52:54 UTC (rev 20912)
+++ trunk/wp-includes/class-wp-customize-control.php	2012-05-25 20:26:25 UTC (rev 20913)
@@ -398,8 +398,54 @@
 		<div class="uploaded-target"></div>
 		<?php
 	}
+
+	public function print_tab_image( $url, $thumbnail_url = null ) {
+		$url = set_url_scheme( $url );
+		$thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
+		?>
+		<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
+			<img src="<?php echo esc_url( $thumbnail_url ); ?>" />
+		</a>
+		<?php
+	}
 }
 
+class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
+	public function __construct( $manager ) {
+		parent::__construct( $manager, 'background_image', array(
+			'label'    => __( 'Background Image' ),
+			'section'  => 'background_image',
+			'context'  => 'custom-background',
+			'get_url'  => 'get_background_image',
+		) );
+
+		if ( $this->setting->default )
+			$this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_background' ) );
+	}
+
+	public function tab_uploaded() {
+		$backgrounds = get_posts( array(
+			'post_type'  => 'attachment',
+			'meta_key'   => '_wp_attachment_is_custom_background',
+			'meta_value' => $this->manager->get_stylesheet(),
+			'orderby'    => 'none',
+			'nopaging'   => true,
+		) );
+
+		?><div class="uploaded-target"></div><?php
+
+		if ( empty( $backgrounds ) )
+			return;
+
+		foreach ( (array) $backgrounds as $background )
+			$this->print_tab_image( esc_url_raw( $background->guid ) );
+	}
+
+	public function tab_default_background() {
+		$this->print_tab_image( $this->setting->default );
+	}
+}
+
 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
 	public function __construct( $manager ) {
 		parent::__construct( $manager, 'header_image', array(
@@ -424,21 +470,15 @@
 
 		?><div class="uploaded-target"></div><?php
 
-		foreach ( $headers as $header ) : ?>
-			<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
-				<img src="<?php echo esc_url( set_url_scheme( $header['thumbnail_url'] ) ); ?>" />
-			</a>
-		<?php endforeach;
+		foreach ( $headers as $header )
+			$this->print_tab_image( $header['url'], $header['thumbnail_url'] );
 	}
 
 	public function tab_default_headers() {
 		global $custom_image_header;
 		$custom_image_header->process_default_headers();
 
-		foreach ( $custom_image_header->default_headers as $header ) : ?>
-			<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
-				<img src="<?php echo esc_url( set_url_scheme( $header['thumbnail_url'] ) ); ?>" />
-			</a>
-		<?php endforeach;
+		foreach ( $custom_image_header->default_headers as $header )
+			$this->print_tab_image( $header['url'], $header['thumbnail_url'] );
 	}
 }
\ No newline at end of file

Modified: trunk/wp-includes/class-wp-customize-manager.php (20912 => 20913)


--- trunk/wp-includes/class-wp-customize-manager.php	2012-05-25 19:52:54 UTC (rev 20912)
+++ trunk/wp-includes/class-wp-customize-manager.php	2012-05-25 20:26:25 UTC (rev 20913)
@@ -698,11 +698,7 @@
 			'theme_supports' => 'custom-background',
 		) );
 
-		$this->add_control( new WP_Customize_Image_Control( $this, 'background_image', array(
-			'label'          => __( 'Background Image' ),
-			'section'        => 'background_image',
-			'context'        => 'custom-background',
-		) ) );
+		$this->add_control( new WP_Customize_Background_Image_Control( $this ) );
 
 		$this->add_setting( 'background_repeat', array(
 			'default'        => 'repeat',

Modified: trunk/wp-includes/js/customize-controls.dev.js (20912 => 20913)


--- trunk/wp-includes/js/customize-controls.dev.js	2012-05-25 19:52:54 UTC (rev 20912)
+++ trunk/wp-includes/js/customize-controls.dev.js	2012-05-25 20:26:25 UTC (rev 20913)
@@ -158,6 +158,8 @@
 
 			if ( this.params.context )
 				control.uploader.param( 'post_data[context]', this.params.context );
+
+			control.uploader.param( 'post_data[theme]', api.settings.theme.stylesheet );
 		},
 		success: function( attachment ) {
 			this.setting.set( attachment.url );