Skip to content

Instantly share code, notes, and snippets.

@jeremyclark13
Created November 16, 2012 20:29
Show Gist options
  • Select an option

  • Save jeremyclark13/4090632 to your computer and use it in GitHub Desktop.

Select an option

Save jeremyclark13/4090632 to your computer and use it in GitHub Desktop.
Options Framework theme customizer
/**
* Front End Customizer
*
* WordPress 3.4 Required
*
* Search and replace theme_slug with your own theme slug.
*
*/
add_action( 'customize_register', 'theme_slug_customizer_register' );
function theme_slug_customizer_register( $wp_customize ) {
$customizer_array = array(
'basic' => array(
'name' => __( 'Basic', 'theme_slug'),
'priority' => 100,
'settings' => array(
'setting_1',
'setting_2',
)
),
'advanced' => array(
'name' => __( 'Advanced', 'theme_slug'),
'priority' => 101,
'settings' => array(
'setting_3',
'setting_4',
)
)
);
/**
* This is optional, but if you want to reuse some of the defaults
* or values you already have built in the options panel, you
* can load them into $options for easy reference
*/
$options = optionsframework_options();
foreach ( $customizer_array as $name => $val ) {
$i = 0;
$wp_customize->add_section( "theme_slug_$name", array(
'title' => $val['name'],
'priority' => $val['priority']
) );
foreach ( $val['settings'] as $setting ) {
$wp_customize->add_setting( "theme_slug[$setting]", array(
'default' => $options[$setting]['std'],
'type' => 'option'
) );
if ( $options[$setting]['type'] == 'radio' || $options[$setting]['type'] == 'select' ) {
$wp_customize->add_control( "theme_slug_$setting", array(
'label' => $options[$setting]['name'],
'section' => "theme_slug_$name",
'settings' => "theme_slug[$setting]",
'type' => $options[$setting]['type'],
'choices' => $options[$setting]['options'],
'priority' => $i
) );
} elseif ( $options[$setting]['type'] == 'text' || $options[$setting]['type'] == 'checkbox' ) {
$wp_customize->add_control( "theme_slug_$setting", array(
'label' => $options[$setting]['name'],
'section' => "theme_slug_$name",
'settings' => "theme_slug[$setting]",
'type' => $options[$setting]['type'],
'priority' => $i
) );
} elseif ( $options[$setting]['type'] == 'color' ) {
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, "theme_slug_$setting", array(
'label' => $options[$setting]['name'],
'section' => "theme_slug_$name",
'settings' => "theme_slug[$setting]",
'priority' => $i
) ) );
} elseif ( $options[$setting]['type'] == 'upload' ) {
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, "theme_slug_$setting", array(
'label' => $options[$setting]['name'],
'section' => "theme_slug_$name",
'settings' => "theme_slug[$setting]",
'priority' => $i
) ) );
}
$i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment