/** * Implements Twenty Eleven theme options into Theme Customizer * * @since Twenty Eleven 1.3 * * @param object $wp_customize Theme Customizer object. */ function twentyeleven_customize_register($wp_customize) { $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; $options = twentyeleven_get_theme_options(); $defaults = twentyeleven_get_default_theme_options(); $wp_customize->add_setting('twentyeleven_theme_options[color_scheme]', array('default' => $defaults['color_scheme'], 'type' => 'option', 'capability' => 'edit_theme_options')); $schemes = twentyeleven_color_schemes(); $choices = array(); foreach ($schemes as $scheme) { $choices[$scheme['value']] = $scheme['label']; } $wp_customize->add_control('twentyeleven_color_scheme', array('label' => __('Color Scheme', 'twentyeleven'), 'section' => 'colors', 'settings' => 'twentyeleven_theme_options[color_scheme]', 'type' => 'radio', 'choices' => $choices, 'priority' => 5)); // Link Color (added to Color Scheme section in Theme Customizer) $wp_customize->add_setting('twentyeleven_theme_options[link_color]', array('default' => twentyeleven_get_default_link_color($options['color_scheme']), 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options')); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array('label' => __('Link Color', 'twentyeleven'), 'section' => 'colors', 'settings' => 'twentyeleven_theme_options[link_color]'))); // Default Layout $wp_customize->add_section('twentyeleven_layout', array('title' => __('Layout', 'twentyeleven'), 'priority' => 50)); $wp_customize->add_setting('twentyeleven_theme_options[theme_layout]', array('type' => 'option', 'default' => $defaults['theme_layout'], 'sanitize_callback' => 'sanitize_key')); $layouts = twentyeleven_layouts(); $choices = array(); foreach ($layouts as $layout) { $choices[$layout['value']] = $layout['label']; } $wp_customize->add_control('twentyeleven_theme_options[theme_layout]', array('section' => 'twentyeleven_layout', 'type' => 'radio', 'choices' => $choices)); }
/** * Sanitize and validate form input. Accepts an array, return a sanitized array. * * @see twentyeleven_theme_options_init() * @todo set up Reset Options action * * @since Twenty Eleven 1.0 */ function twentyeleven_theme_options_validate($input) { $output = $defaults = twentyeleven_get_default_theme_options(); // Color scheme must be in our array of color scheme options if (isset($input['color_scheme']) && array_key_exists($input['color_scheme'], twentyeleven_color_schemes())) { $output['color_scheme'] = $input['color_scheme']; } // Our defaults for the link color may have changed, based on the color scheme. $output['link_color'] = $defaults['link_color'] = twentyeleven_get_default_link_color($output['color_scheme']); // Link color must be 3 or 6 hexadecimal characters if (isset($input['link_color']) && preg_match('/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'])) { $output['link_color'] = '#' . strtolower(ltrim($input['link_color'], '#')); } // Theme layout must be in our array of theme layout options if (isset($input['theme_layout']) && array_key_exists($input['theme_layout'], twentyeleven_layouts())) { $output['theme_layout'] = $input['theme_layout']; } return apply_filters('twentyeleven_theme_options_validate', $output, $input, $defaults); }