From beb401b53387f8ed4b62062f04da063d6266c839 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Fri, 25 May 2012 20:26:25 +0000 Subject: [PATCH] Theme Customizer: Improve background image control, add correct meta key to custom headers and backgrounds uploaded using the customizer. see #19910. git-svn-id: http://core.svn.wordpress.org/trunk@20913 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 8 +++ wp-includes/class-wp-customize-control.php | 60 ++++++++++++++++++---- wp-includes/class-wp-customize-manager.php | 6 +-- wp-includes/js/customize-controls.dev.js | 2 + 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index cf953f007..2fc8ebb30 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1640,6 +1640,14 @@ function wp_ajax_upload_attachment() { 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( diff --git a/wp-includes/class-wp-customize-control.php b/wp-includes/class-wp-customize-control.php index 04c89166d..9368da1b9 100644 --- a/wp-includes/class-wp-customize-control.php +++ b/wp-includes/class-wp-customize-control.php @@ -398,6 +398,52 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
+ + + + __( '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, + ) ); + + ?>
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 { @@ -424,21 +470,15 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { ?>
- - - - 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 ) : ?> - - - - default_headers as $header ) + $this->print_tab_image( $header['url'], $header['thumbnail_url'] ); } } \ No newline at end of file diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 17357f4c9..8cf6d860b 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -698,11 +698,7 @@ final class WP_Customize_Manager { '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', diff --git a/wp-includes/js/customize-controls.dev.js b/wp-includes/js/customize-controls.dev.js index d313d8317..bcd31323f 100644 --- a/wp-includes/js/customize-controls.dev.js +++ b/wp-includes/js/customize-controls.dev.js @@ -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 );