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
This commit is contained in:
koopersmith 2012-03-24 01:02:29 +00:00
parent 6f9ff90e86
commit cca689308c
4 changed files with 21 additions and 16 deletions

View File

@ -14,6 +14,7 @@ class WP_Customize_Setting {
public $section = ''; public $section = '';
public $label = ''; public $label = '';
public $control = 'text'; public $control = 'text';
public $control_params = array();
public $type = 'theme_mod'; public $type = 'theme_mod';
public $choices = array(); public $choices = array();
public $capability = 'edit_theme_options'; public $capability = 'edit_theme_options';

View File

@ -534,10 +534,13 @@ final class WP_Customize {
// Input type: checkbox // Input type: checkbox
// With custom value // With custom value
$this->add_setting( 'header_image', array( $this->add_setting( 'header_image', array(
'label' => 'Header Image', 'label' => 'Header Image',
'section' => 'header', 'section' => 'header',
'control' => 'upload', 'control' => 'upload',
'default' => get_theme_support( 'custom-header', 'default-image' ), 'default' => get_theme_support( 'custom-header', 'default-image' ),
'control_params' => array(
'context' => 'custom-header',
),
) ); ) );
/* Custom Background */ /* Custom Background */
@ -558,10 +561,13 @@ final class WP_Customize {
) ); ) );
$this->add_setting( 'background_image', array( $this->add_setting( 'background_image', array(
'label' => 'Background Image', 'label' => 'Background Image',
'section' => 'background', 'section' => 'background',
'control' => 'upload', 'control' => 'upload',
'default' => get_theme_support( 'custom-background', 'default-image' ), 'default' => get_theme_support( 'custom-background', 'default-image' ),
'control_params' => array(
'context' => 'custom-background',
),
) ); ) );
$this->add_setting( 'background_repeat', array( $this->add_setting( 'background_repeat', array(

View File

@ -103,6 +103,7 @@ do_action( 'customize_controls_print_scripts' );
$settings['controls'][ $id ] = array( $settings['controls'][ $id ] = array(
'value' => $setting->value(), 'value' => $setting->value(),
'control' => $setting->control, 'control' => $setting->control,
'params' => $setting->control_params,
); );
if ( $setting->visibility ) { if ( $setting->visibility ) {

View File

@ -10,6 +10,7 @@
initialize: function( id, value, options ) { initialize: function( id, value, options ) {
var name = '[name="' + api.settings.prefix + id + '"]'; var name = '[name="' + api.settings.prefix + id + '"]';
this.params = {};
api.Value.prototype.initialize.call( this, value, options ); api.Value.prototype.initialize.call( this, value, options );
this.id = id; this.id = id;
@ -90,6 +91,9 @@
}); });
this.bind( this.removerVisibility ); this.bind( this.removerVisibility );
if ( this.params.context )
control.uploader.param( 'post_data[context]', this.params.context );
}, },
removerVisibility: function( on ) { removerVisibility: function( on ) {
this.remover.toggle( !! on ); this.remover.toggle( !! on );
@ -240,6 +244,7 @@
control; control;
control = api.add( id, new constructor( id, data.value, { control = api.add( id, new constructor( id, data.value, {
params: data.params,
previewer: previewer previewer: previewer
} ) ); } ) );
@ -274,14 +279,6 @@
api( 'background_color', function( control ) { api( 'background_color', function( control ) {
control.method = 'postMessage'; 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 ); })( wp, jQuery );