diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/themes/twentyeleven/inc/theme-options.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/themes/twentyeleven/inc/theme-options.php Mon Nov 19 18:26:13 2012 +0100 @@ -0,0 +1,531 @@ +' . __( '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' ) . '

' . + '
    ' . + '
  1. ' . __( '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' ) . '
  2. ' . + '
  3. ' . __( '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' ) . '
  4. ' . + '
  5. ' . __( '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' ) . '
  6. ' . + '
' . + '

' . __( '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 Options', 'twentyeleven' ) . '

' . + '

' . __( 'Support Forums', 'twentyeleven' ) . '

'; + + $screen = get_current_screen(); + + if ( method_exists( $screen, 'add_help_tab' ) ) { + // WordPress 3.3 + $screen->add_help_tab( array( + 'title' => __( 'Overview', 'twentyeleven' ), + 'id' => 'theme-options-help', + 'content' => $help, + ) + ); + + $screen->set_help_sidebar( $sidebar ); + } else { + // WordPress 3.2 + add_contextual_help( $screen, $help . $sidebar ); + } +} + +/** + * Returns an array of color schemes registered for Twenty Eleven. + * + * @since Twenty Eleven 1.0 + */ +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', + ), + ); + + return apply_filters( 'twentyeleven_color_schemes', $color_scheme_options ); +} + +/** + * Returns an array of layout options registered for Twenty Eleven. + * + * @since Twenty Eleven 1.0 + */ +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', + ), + ); + + return apply_filters( 'twentyeleven_layouts', $layout_options ); +} + +/** + * Returns the default options for Twenty Eleven. + * + * @since Twenty Eleven 1.0 + */ +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'; + + 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 Color scheme. Defaults to the active color scheme. + * @return $string Color. +*/ +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 + */ +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'] ) . '' ); ?> + +
+ +
+ +
+ + +

+ + +
+ +
+
+ + +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, + ) ); +} +add_action( 'customize_register', 'twentyeleven_customize_register' ); + +/** + * Bind JS handlers to make Theme 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' ), '20120523', true ); +} +add_action( 'customize_preview_init', 'twentyeleven_customize_preview_js' ); \ No newline at end of file