' . __( 'Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, Twenty Eleven, provides the following Theme Options:', 'twentyeleven' ) . '
' .
'' .
'' . __( 'Color Scheme : You can choose a color palette of "Light" (light background with dark text) or "Dark" (dark background with light text) for your site.', 'twentyeleven' ) . ' ' .
'' . __( 'Link Color : You can choose the color used for text links on your site. You can enter the HTML color or hex code, or you can choose visually by clicking the "Select a Color" button to pick from a color wheel.', 'twentyeleven' ) . ' ' .
'' . __( 'Default Layout : You can choose if you want your site’s default layout to have a sidebar on the left, the right, or not at all.', 'twentyeleven' ) . ' ' .
' ' .
'' . __( 'Remember to click "Save Changes" to save any changes you have made to the theme options.', 'twentyeleven' ) . '
';
$sidebar = '' . __( 'For more information:', 'twentyeleven' ) . '
' .
'' . __( 'Documentation on Theme Customization ', 'twentyeleven' ) . '
' .
'' . __( 'Support forums ', 'twentyeleven' ) . '
';
$screen = get_current_screen();
if ( method_exists( $screen, 'add_help_tab' ) ) {
// WordPress 3.3.0.
$screen->add_help_tab(
array(
'title' => __( 'Overview', 'twentyeleven' ),
'id' => 'theme-options-help',
'content' => $help,
)
);
$screen->set_help_sidebar( $sidebar );
} else {
// WordPress 3.2.0.
add_contextual_help( $screen, $help . $sidebar );
}
}
/**
* Returns an array of color schemes registered for Twenty Eleven.
*
* @since Twenty Eleven 1.0
*
* @return array> An associative array of color scheme options.
*/
function twentyeleven_color_schemes() {
$color_scheme_options = array(
'light' => array(
'value' => 'light',
'label' => __( 'Light', 'twentyeleven' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/light.png',
'default_link_color' => '#1b8be0',
),
'dark' => array(
'value' => 'dark',
'label' => __( 'Dark', 'twentyeleven' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png',
'default_link_color' => '#e4741f',
),
);
/**
* Filters the Twenty Eleven color scheme options.
*
* @since Twenty Eleven 1.0
*
* @param array> $color_scheme_options An associative array of color scheme options.
*/
return apply_filters( 'twentyeleven_color_schemes', $color_scheme_options );
}
/**
* Returns an array of layout options registered for Twenty Eleven.
*
* @since Twenty Eleven 1.0
*
* @return array> An associative array of layout options.
*/
function twentyeleven_layouts() {
$layout_options = array(
'content-sidebar' => array(
'value' => 'content-sidebar',
'label' => __( 'Content on left', 'twentyeleven' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/content-sidebar.png',
),
'sidebar-content' => array(
'value' => 'sidebar-content',
'label' => __( 'Content on right', 'twentyeleven' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/sidebar-content.png',
),
'content' => array(
'value' => 'content',
'label' => __( 'One-column, no sidebar', 'twentyeleven' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/content.png',
),
);
/**
* Filters the Twenty Eleven layout options.
*
* @since Twenty Eleven 1.0
*
* @param array> $layout_options An associative array of layout options.
*/
return apply_filters( 'twentyeleven_layouts', $layout_options );
}
/**
* Returns the default options for Twenty Eleven.
*
* @since Twenty Eleven 1.0
*
* @return array An array of default theme options.
*/
function twentyeleven_get_default_theme_options() {
$default_theme_options = array(
'color_scheme' => 'light',
'link_color' => twentyeleven_get_default_link_color( 'light' ),
'theme_layout' => 'content-sidebar',
);
if ( is_rtl() ) {
$default_theme_options['theme_layout'] = 'sidebar-content';
}
/**
* Filters the Twenty Eleven default options.
*
* @since Twenty Eleven 1.0
*
* @param array $default_theme_options An array of default theme options.
*/
return apply_filters( 'twentyeleven_default_theme_options', $default_theme_options );
}
/**
* Returns the default link color for Twenty Eleven, based on color scheme.
*
* @since Twenty Eleven 1.0
*
* @param string $color_scheme Optional. Color scheme.
* Default null (or the active color scheme).
* @return string|false The default link color, or false if not set.
*/
function twentyeleven_get_default_link_color( $color_scheme = null ) {
if ( null === $color_scheme ) {
$options = twentyeleven_get_theme_options();
$color_scheme = $options['color_scheme'];
}
$color_schemes = twentyeleven_color_schemes();
if ( ! isset( $color_schemes[ $color_scheme ] ) ) {
return false;
}
return $color_schemes[ $color_scheme ]['default_link_color'];
}
/**
* Returns the options array for Twenty Eleven.
*
* @since Twenty Eleven 1.0
*
* @return array The theme options array.
*/
function twentyeleven_get_theme_options() {
return get_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() );
}
/**
* Renders the Color Scheme setting field.
*
* @since Twenty Eleven 1.3
*/
function twentyeleven_settings_field_color_scheme() {
$options = twentyeleven_get_theme_options();
foreach ( twentyeleven_color_schemes() as $scheme ) {
?>
' . twentyeleven_get_default_link_color( $options['color_scheme'] ) . ' ' );
?>
display( 'Name' ) : get_option( 'current_theme' );
?>
An array of sanitized and validated form output.
*/
function twentyeleven_theme_options_validate( $input ) {
$defaults = twentyeleven_get_default_theme_options();
$output = $defaults;
// 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.
$defaults['link_color'] = twentyeleven_get_default_link_color( $output['color_scheme'] );
$output['link_color'] = $defaults['link_color'];
// 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'];
}
/**
* Filters the Twenty Eleven sanitized form input array.
*
* @since Twenty Eleven 1.0
*
* @param array $output An array of sanitized form output.
* @param array $input An array of un-sanitized form input.
* @param array $defaults An array of default theme options.
*/
return apply_filters( 'twentyeleven_theme_options_validate', $output, $input, $defaults );
}
/**
* Enqueues the styles for the current color scheme.
*
* @since Twenty Eleven 1.0
*/
function twentyeleven_enqueue_color_scheme() {
$options = twentyeleven_get_theme_options();
$color_scheme = $options['color_scheme'];
if ( 'dark' === $color_scheme ) {
wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), '20251017' );
}
/**
* Fires after the styles for the Twenty Eleven color scheme are enqueued.
*
* @since Twenty Eleven 1.0
*
* @param string $color_scheme The color scheme.
*/
do_action( 'twentyeleven_enqueue_color_scheme', $color_scheme );
}
add_action( 'wp_enqueue_scripts', 'twentyeleven_enqueue_color_scheme' );
/**
* Adds a style block to the theme for the current link color.
*
* This function is attached to the wp_head action hook.
*
* @since Twenty Eleven 1.0
*/
function twentyeleven_print_link_color_style() {
$options = twentyeleven_get_theme_options();
$link_color = $options['link_color'];
$default_options = twentyeleven_get_default_theme_options();
// Don't do anything if the current link color is the default.
if ( $default_options['link_color'] === $link_color ) {
return;
}
?>
get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
if ( isset( $wp_customize->selective_refresh ) ) {
$wp_customize->selective_refresh->add_partial(
'blogname',
array(
'selector' => '#site-title a',
'container_inclusive' => false,
'render_callback' => 'twentyeleven_customize_partial_blogname',
)
);
$wp_customize->selective_refresh->add_partial(
'blogdescription',
array(
'selector' => '#site-description',
'container_inclusive' => false,
'render_callback' => 'twentyeleven_customize_partial_blogdescription',
)
);
}
$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 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,
)
);
}
add_action( 'customize_register', 'twentyeleven_customize_register' );
/**
* Renders the site title for the selective refresh partial.
*
* @since Twenty Eleven 2.4
*
* @see twentyeleven_customize_register()
*
* @return void
*/
function twentyeleven_customize_partial_blogname() {
bloginfo( 'name' );
}
/**
* Renders the site tagline for the selective refresh partial.
*
* @since Twenty Eleven 2.4
*
* @see twentyeleven_customize_register()
*
* @return void
*/
function twentyeleven_customize_partial_blogdescription() {
bloginfo( 'description' );
}
/**
* Binds JS handlers to make Customizer preview reload changes asynchronously.
*
* Used with blogname and blogdescription.
*
* @since Twenty Eleven 1.3
*/
function twentyeleven_customize_preview_js() {
wp_enqueue_script( 'twentyeleven-customizer', get_template_directory_uri() . '/inc/theme-customizer.js', array( 'customize-preview' ), '20250217', array( 'in_footer' => true ) );
}
add_action( 'customize_preview_init', 'twentyeleven_customize_preview_js' );