]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentyeleven/inc/theme-options.php
WordPress 3.4
[autoinstalls/wordpress.git] / wp-content / themes / twentyeleven / inc / theme-options.php
index f1d6c4b3d8c3f3a9206fdfdda397c2574bcff86a..698f2a0b5e51e15f91fa6b7c4eca216672fcac56 100644 (file)
@@ -31,16 +31,10 @@ add_action( 'admin_print_styles-appearance_page_theme_options', 'twentyeleven_ad
  * which is used when the option is saved, to ensure that our option values are complete, properly
  * formatted, and safe.
  *
  * which is used when the option is saved, to ensure that our option values are complete, properly
  * formatted, and safe.
  *
- * We also use this function to add our theme option if it doesn't already exist.
- *
  * @since Twenty Eleven 1.0
  */
 function twentyeleven_theme_options_init() {
 
  * @since Twenty Eleven 1.0
  */
 function twentyeleven_theme_options_init() {
 
-       // If we have no options in the database, let's add them now.
-       if ( false === twentyeleven_get_theme_options() )
-               add_option( 'twentyeleven_theme_options', twentyeleven_get_default_theme_options() );
-
        register_setting(
                'twentyeleven_options',       // Options group, see settings_fields() call in twentyeleven_theme_options_render_page()
                'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options()
        register_setting(
                'twentyeleven_options',       // Options group, see settings_fields() call in twentyeleven_theme_options_render_page()
                'twentyeleven_theme_options', // Database option, see twentyeleven_get_theme_options()
@@ -314,7 +308,8 @@ function twentyeleven_theme_options_render_page() {
        ?>
        <div class="wrap">
                <?php screen_icon(); ?>
        ?>
        <div class="wrap">
                <?php screen_icon(); ?>
-               <h2><?php printf( __( '%s Theme Options', 'twentyeleven' ), get_current_theme() ); ?></h2>
+               <?php $theme_name = function_exists( 'wp_get_theme' ) ? wp_get_theme() : get_current_theme(); ?>
+               <h2><?php printf( __( '%s Theme Options', 'twentyeleven' ), $theme_name ); ?></h2>
                <?php settings_errors(); ?>
 
                <form method="post" action="options.php">
                <?php settings_errors(); ?>
 
                <form method="post" action="options.php">
@@ -446,4 +441,91 @@ function twentyeleven_layout_classes( $existing_classes ) {
 
        return array_merge( $existing_classes, $classes );
 }
 
        return array_merge( $existing_classes, $classes );
 }
-add_filter( 'body_class', 'twentyeleven_layout_classes' );
\ No newline at end of file
+add_filter( 'body_class', 'twentyeleven_layout_classes' );
+
+/**
+ * Implements Twenty Eleven theme options into Theme Customizer
+ *
+ * @param $wp_customize Theme Customizer object
+ * @return void
+ *
+ * @since Twenty Eleven 1.3
+ */
+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,
+       ) );
+}
+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