WPTech Nantes 2014
function themeslug_customize_register( $wp_customize ) {
// Toutes les sections, réglages et contrôles seront ici
}
add_action( 'customize_register', 'themeslug_customize_register' );
$wp_customize->add_section( 'themeslug_section_name' , array(
'title' => __( 'Section name', 'themeslug' ),
'description'=> __( 'Section description', 'themeslug' ),
'priority' => 30,
) );
$wp_customize->add_section( $section_id, $args );
$wp_customize->add_setting( 'themeslug[option_name]' , array(
'default' => '',
'transport' => 'refresh', // refresh ou postMessage
'sanitize_callback' => 'sanitize_text_field'
) );
$wp_customize->add_setting( $setting_id, $args );
$wp_customize->add_control( 'option_name', array(
'label' => __( 'Option Name', 'themeslug' ),
'description' => __( 'Option description', 'themeslug' ),
'section' => 'themeslug_section_name',
'settings' => 'themeslug[option_name]',
'type' => 'text',
'active_callback' => 'is_front_page'
) );
$wp_customize->add_section( $option_id, $args );
$wp_customize->add_control('select_radio', array(
'label' => __('Radio options', 'themeslug'),
'section' => 'themename_section_name',
'settings' => 'themeslug[select_radio]',
'type' => 'radio',
'choices' => array(
'value1' => 'Choice 1',
'value2' => 'Choice 2',
'value3' => 'Choice 3',
),
));
$theme_options = get_theme_mod( 'themeslug' );
echo $theme_options['option_name'];
get_theme_mod( $options_id, $default );
$wp_customize->add_panel( 'panel_name', array(
'priority' => 200,
'title' => __( 'Panel name', 'themeslug' ),
'description' => __( 'Panel description', 'themeslug' )
) );
Un panneau regroupe des sections
$wp_customize->add_panel( $panel_id, $args );
$wp_customize->add_section( 'themeslug_section_name' , array(
'title' => __( 'Section name', 'themeslug' ),
'description'=> __( 'Section description', 'themeslug' ),
'priority' => 30,
'panel' => 'panel_name'
) );
'input_attrs' => array(
'min' => 0,
'max' => 10,
'step' => 2,
'class' => 'test-class test',
'style' => 'color: #0a0',
)
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'links_color',
array(
'label' => __( 'Links color', 'themeslug' ),
'section' => 'colors',
'settings' => 'themeslug[links_color]'
)
)
);
class Theme_Custom_Control extends WP_Customize_Control {
public function render_content() { ?>
<label>
<span class="customize-control-title">
<?php echo esc_html( $this->label ); ?>
</span>
</label>
<textarea rows="5" <?php $this->link(); ?>>
<?php echo esc_textarea( $this->value() ); ?>
</textarea>
<?php }
}
Pré-requis :
function themeslug_customizer_live_preview() {
wp_enqueue_script( 'themeslug-customizer',
get_template_directory_uri() . '/js/customizer.js',
array( 'jquery', 'customize-preview' ),
'1.0',
true );
}
add_action( 'customize_preview_init', 'themeslug_customizer_live_preview' );
Hook : customizer_preview_init
( function( $ ) {
wp.customize( 'themeslug[links_color]', function( value ) {
value.bind( function( newval ) {
$( 'a' ).css( 'color', newval );
} );
} );
} )( jQuery );
http://codex.wordpress.org/Theme_Customization_API
http://remyperona.fr/nouveautes-customizer-wordpress-4/
http://ottopress.com/tag/customizer/
Développeur/Intégrateur WP
Me retrouver sur :