From cca689308c0c1c94ab0221dead65a6cc8b8a9f8a Mon Sep 17 00:00:00 2001 From: koopersmith Date: Sat, 24 Mar 2012 01:02:29 +0000 Subject: [PATCH] Theme Customizer: Add WP_Customizer_Setting->control_params, and wp.customize.Control.params to allow settings to pass arbitrary parameters to controls. Add the 'context' parameter to wp.customize.UploadControl. see #19910. git-svn-id: http://svn.automattic.com/wordpress/trunk@20276 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-setting.php | 1 + wp-includes/class-wp-customize.php | 22 ++++++++++++++-------- wp-includes/customize-controls.php | 1 + wp-includes/js/customize-controls.dev.js | 13 +++++-------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/wp-includes/class-wp-customize-setting.php b/wp-includes/class-wp-customize-setting.php index 1fa0f7c6b..e734f4967 100644 --- a/wp-includes/class-wp-customize-setting.php +++ b/wp-includes/class-wp-customize-setting.php @@ -14,6 +14,7 @@ class WP_Customize_Setting { public $section = ''; public $label = ''; public $control = 'text'; + public $control_params = array(); public $type = 'theme_mod'; public $choices = array(); public $capability = 'edit_theme_options'; diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index e97c547b4..45d27d11b 100644 --- a/wp-includes/class-wp-customize.php +++ b/wp-includes/class-wp-customize.php @@ -534,10 +534,13 @@ final class WP_Customize { // Input type: checkbox // With custom value $this->add_setting( 'header_image', array( - 'label' => 'Header Image', - 'section' => 'header', - 'control' => 'upload', - 'default' => get_theme_support( 'custom-header', 'default-image' ), + 'label' => 'Header Image', + 'section' => 'header', + 'control' => 'upload', + 'default' => get_theme_support( 'custom-header', 'default-image' ), + 'control_params' => array( + 'context' => 'custom-header', + ), ) ); /* Custom Background */ @@ -558,10 +561,13 @@ final class WP_Customize { ) ); $this->add_setting( 'background_image', array( - 'label' => 'Background Image', - 'section' => 'background', - 'control' => 'upload', - 'default' => get_theme_support( 'custom-background', 'default-image' ), + 'label' => 'Background Image', + 'section' => 'background', + 'control' => 'upload', + 'default' => get_theme_support( 'custom-background', 'default-image' ), + 'control_params' => array( + 'context' => 'custom-background', + ), ) ); $this->add_setting( 'background_repeat', array( diff --git a/wp-includes/customize-controls.php b/wp-includes/customize-controls.php index fcc220534..3780968bf 100644 --- a/wp-includes/customize-controls.php +++ b/wp-includes/customize-controls.php @@ -103,6 +103,7 @@ do_action( 'customize_controls_print_scripts' ); $settings['controls'][ $id ] = array( 'value' => $setting->value(), 'control' => $setting->control, + 'params' => $setting->control_params, ); if ( $setting->visibility ) { diff --git a/wp-includes/js/customize-controls.dev.js b/wp-includes/js/customize-controls.dev.js index 79c64cfa0..59ec58fac 100644 --- a/wp-includes/js/customize-controls.dev.js +++ b/wp-includes/js/customize-controls.dev.js @@ -10,6 +10,7 @@ initialize: function( id, value, options ) { var name = '[name="' + api.settings.prefix + id + '"]'; + this.params = {}; api.Value.prototype.initialize.call( this, value, options ); this.id = id; @@ -90,6 +91,9 @@ }); this.bind( this.removerVisibility ); + + if ( this.params.context ) + control.uploader.param( 'post_data[context]', this.params.context ); }, removerVisibility: function( on ) { this.remover.toggle( !! on ); @@ -240,6 +244,7 @@ control; control = api.add( id, new constructor( id, data.value, { + params: data.params, previewer: previewer } ) ); @@ -274,14 +279,6 @@ api( 'background_color', function( control ) { control.method = 'postMessage'; }); - - api( 'background_image', function( control ) { - control.uploader.param( 'post_data[context]', 'custom-background' ); - }); - - api( 'header_image', function( control ) { - control.uploader.param( 'post_data[context]', 'custom-header' ); - }); }); })( wp, jQuery ); \ No newline at end of file