]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentyeleven/functions.php
WordPress 3.4
[autoinstalls/wordpress.git] / wp-content / themes / twentyeleven / functions.php
index 1997eb2bd73a179d4b8446c627e756bd48ec22ed..e9d97ed2765a63742a951bc8dba0eccddf888467 100644 (file)
@@ -62,10 +62,9 @@ if ( ! function_exists( 'twentyeleven_setup' ) ):
  *
  * @uses load_theme_textdomain() For translation/localization support.
  * @uses add_editor_style() To style the visual editor.
- * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats.
+ * @uses add_theme_support() To add support for post thumbnails, automatic feed links, custom headers
+ *     and backgrounds, and post formats.
  * @uses register_nav_menus() To add support for navigation menus.
- * @uses add_custom_background() To add support for a custom background.
- * @uses add_custom_image_header() To add support for a custom header.
  * @uses register_default_headers() To register the default custom header images provided with the theme.
  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  *
@@ -78,21 +77,16 @@ function twentyeleven_setup() {
         * If you're building a theme based on Twenty Eleven, use a find and replace
         * to change 'twentyeleven' to the name of your theme in all the template files.
         */
-       load_theme_textdomain( 'twentyeleven', TEMPLATEPATH . '/languages' );
-
-       $locale = get_locale();
-       $locale_file = TEMPLATEPATH . "/languages/$locale.php";
-       if ( is_readable( $locale_file ) )
-               require_once( $locale_file );
+       load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
 
        // This theme styles the visual editor with editor-style.css to match the theme style.
        add_editor_style();
 
        // Load up our theme options page and related code.
-       require( dirname( __FILE__ ) . '/inc/theme-options.php' );
+       require( get_template_directory() . '/inc/theme-options.php' );
 
        // Grab Twenty Eleven's Ephemera widget.
-       require( dirname( __FILE__ ) . '/inc/widgets.php' );
+       require( get_template_directory() . '/inc/widgets.php' );
 
        // Add default posts and comments RSS feed links to <head>.
        add_theme_support( 'automatic-feed-links' );
@@ -103,42 +97,63 @@ function twentyeleven_setup() {
        // Add support for a variety of post formats
        add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
 
-       // Add support for custom backgrounds
-       add_custom_background();
+       $theme_options = twentyeleven_get_theme_options();
+       if ( 'dark' == $theme_options['color_scheme'] )
+               $default_background_color = '1d1d1d';
+       else
+               $default_background_color = 'f1f1f1';
+
+       // Add support for custom backgrounds.
+       add_theme_support( 'custom-background', array(
+               // Let WordPress know what our default background color is.
+               // This is dependent on our current color scheme.
+               'default-color' => $default_background_color,
+       ) );
 
        // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
        add_theme_support( 'post-thumbnails' );
 
-       // The next four constants set how Twenty Eleven supports custom headers.
-
-       // The default header text color
-       define( 'HEADER_TEXTCOLOR', '000' );
-
-       // By leaving empty, we allow for random image rotation.
-       define( 'HEADER_IMAGE', '' );
-
-       // The height and width of your custom header.
-       // Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
-       define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
-       define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
+       // Add support for custom headers.
+       $custom_header_support = array(
+               // The default header text color.
+               'default-text-color' => '000',
+               // The height and width of our custom header.
+               'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ),
+               'height' => apply_filters( 'twentyeleven_header_image_height', 288 ),
+               // Support flexible heights.
+               'flex-height' => true,
+               // Random image rotation by default.
+               'random-default' => true,
+               // Callback for styling the header.
+               'wp-head-callback' => 'twentyeleven_header_style',
+               // Callback for styling the header preview in the admin.
+               'admin-head-callback' => 'twentyeleven_admin_header_style',
+               // Callback used to display the header preview in the admin.
+               'admin-preview-callback' => 'twentyeleven_admin_header_image',
+       );
+       
+       add_theme_support( 'custom-header', $custom_header_support );
+
+       if ( ! function_exists( 'get_custom_header' ) ) {
+               // This is all for compatibility with versions of WordPress prior to 3.4.
+               define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
+               define( 'HEADER_IMAGE', '' );
+               define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
+               define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
+               add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
+               add_custom_background();
+       }
 
        // We'll be using post thumbnails for custom header images on posts and pages.
        // We want them to be the size of the header image that we just defined
        // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
-       set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
-
-       // Add Twenty Eleven's custom image sizes
-       add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
-       add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
-
-       // Turn on random header image rotation by default.
-       add_theme_support( 'custom-header', array( 'random-default' => true ) );
+       set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
 
-       // Add a way for the custom header to be styled in the admin panel that controls
-       // custom headers. See twentyeleven_admin_header_style(), below.
-       add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' );
-
-       // ... and thus ends the changeable header business.
+       // Add Twenty Eleven's custom image sizes.
+       // Used for large feature (header) images.
+       add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
+       // Used for featured posts if a large-feature doesn't exist.
+       add_image_size( 'small-feature', 500, 300 );
 
        // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
        register_default_headers( array(
@@ -201,17 +216,18 @@ if ( ! function_exists( 'twentyeleven_header_style' ) ) :
  * @since Twenty Eleven 1.0
  */
 function twentyeleven_header_style() {
+       $text_color = get_header_textcolor();
 
-       // If no custom options for text are set, let's bail
-       // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
-       if ( HEADER_TEXTCOLOR == get_header_textcolor() )
+       // If no custom options for text are set, let's bail.
+       if ( $text_color == HEADER_TEXTCOLOR )
                return;
+               
        // If we get this far, we have custom styles. Let's do this.
        ?>
        <style type="text/css">
        <?php
                // Has the text been hidden?
-               if ( 'blank' == get_header_textcolor() ) :
+               if ( 'blank' == $text_color ) :
        ?>
                #site-title,
                #site-description {
@@ -225,7 +241,7 @@ function twentyeleven_header_style() {
        ?>
                #site-title a,
                #site-description {
-                       color: #<?php echo get_header_textcolor(); ?> !important;
+                       color: #<?php echo $text_color; ?> !important;
                }
        <?php endif; ?>
        </style>
@@ -237,7 +253,7 @@ if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
 /**
  * Styles the header image displayed on the Appearance > Header admin panel.
  *
- * Referenced via add_custom_image_header() in twentyeleven_setup().
+ * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
  *
  * @since Twenty Eleven 1.0
  */
@@ -287,23 +303,24 @@ if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
 /**
  * Custom header image markup displayed on the Appearance > Header admin panel.
  *
- * Referenced via add_custom_image_header() in twentyeleven_setup().
+ * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
  *
  * @since Twenty Eleven 1.0
  */
 function twentyeleven_admin_header_image() { ?>
        <div id="headimg">
                <?php
-               if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
-                       $style = ' style="display:none;"';
+               $color = get_header_textcolor();
+               $image = get_header_image();
+               if ( $color && $color != 'blank' )
+                       $style = ' style="color:#' . $color . '"';
                else
-                       $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
+                       $style = ' style="display:none"';
                ?>
                <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
-               <?php $header_image = get_header_image();
-               if ( ! empty( $header_image ) ) : ?>
-                       <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
+               <?php if ( $image ) : ?>
+                       <img src="<?php echo esc_url( $image ); ?>" alt="" />
                <?php endif; ?>
        </div>
 <?php }
@@ -421,6 +438,7 @@ function twentyeleven_widgets_init() {
 }
 add_action( 'widgets_init', 'twentyeleven_widgets_init' );
 
+if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
 /**
  * Display navigation to next/previous pages when applicable
  */
@@ -435,6 +453,7 @@ function twentyeleven_content_nav( $nav_id ) {
                </nav><!-- #nav-above -->
        <?php endif;
 }
+endif; // twentyeleven_content_nav
 
 /**
  * Return the URL for the first link found in the post content.
@@ -565,8 +584,8 @@ function twentyeleven_posted_on() {
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date() ),
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
-               sprintf( esc_attr__( 'View all posts by %s', 'twentyeleven' ), get_the_author() ),
-               esc_html( get_the_author() )
+               esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
+               get_the_author()
        );
 }
 endif;
@@ -580,9 +599,8 @@ endif;
  */
 function twentyeleven_body_classes( $classes ) {
 
-       if ( ! is_multi_author() ) {
+       if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
                $classes[] = 'single-author';
-       }
 
        if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
                $classes[] = 'singular';