Skip to content

Instantly share code, notes, and snippets.

@robmint
Created July 16, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robmint/3120600 to your computer and use it in GitHub Desktop.
Save robmint/3120600 to your computer and use it in GitHub Desktop.
add sections to the wordpress customize panel
<?php
require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
class WP_Customize_Palette_Control extends WP_Customize_Image_Control {
public $type = 'palette';
public $removed = '';
public $context;
public function enqueue() {
//wp_enqueue_script( 'wp-plupload' );
}
public function to_json() {
parent::to_json();
$this->json['removed'] = $this->removed;
if ( $this->context )
$this->json['context'] = $this->context;
}
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<div>
<a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
<a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
</div>
</label>
<?php
}
}
//new WP_Customize_Palette_Control();
//add_action('customize_controls_init', 'WP_Customize_Palette_Control');
// add an option to the customize panel
function sci_customize_controls_init($wp_customize) {
$wp_customize->add_section( 'themename_color_scheme', array(
'title' => __( 'Color Scheme', 'themename' ),
'priority' => 35,
) );
$wp_customize->add_setting( 'themename_theme_options[color_scheme]', array(
'default' => 'some-default-value',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'themename_color_scheme', array(
'label' => __( 'Color Scheme', 'themename' ),
'section' => 'themename_color_scheme',
'settings' => 'themename_theme_options[color_scheme]',
'type' => 'palette',
'choices' => array(
'value1' => 'Choice 1',
'value2' => 'Choice 2',
'value3' => 'Choice 3',
),
) );
}
add_action( 'customize_register', 'sci_customize_controls_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment