public
Created

add sections to the wordpress customize panel

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?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' );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.