]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-content/themes/twentyeleven/functions.php
Wordpress 3.5.2
[autoinstalls/wordpress.git] / wp-content / themes / twentyeleven / functions.php
index 9858126b6aa06daa7dcaaca04e82e97c278d489e..1fc8e659e7840dc4a8a1769558a2dff7bbf33d15 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.
  *
@@ -80,11 +79,6 @@ function twentyeleven_setup() {
         */
        load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
 
-       $locale = get_locale();
-       $locale_file = get_template_directory() . "/languages/$locale.php";
-       if ( is_readable( $locale_file ) )
-               require_once( $locale_file );
-
        // This theme styles the visual editor with editor-style.css to match the theme style.
        add_editor_style();
 
@@ -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 = 'e2e2e2';
+
+       // 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' );
+       // 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',
+       );
 
-       // By leaving empty, we allow for random image rotation.
-       define( 'HEADER_IMAGE', '' );
+       add_theme_support( 'custom-header', $custom_header_support );
 
-       // 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 ) );
+       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 );
+       set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['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 ) );
-
-       // 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 }
@@ -320,12 +337,14 @@ function twentyeleven_excerpt_length( $length ) {
 }
 add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
 
+if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) :
 /**
  * Returns a "Continue Reading" link for excerpts
  */
 function twentyeleven_continue_reading_link() {
        return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
 }
+endif; // twentyeleven_continue_reading_link
 
 /**
  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link().
@@ -356,7 +375,8 @@ add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
  * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  */
 function twentyeleven_page_menu_args( $args ) {
-       $args['show_home'] = true;
+       if ( ! isset( $args['show_home'] ) )
+               $args['show_home'] = true;
        return $args;
 }
 add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
@@ -425,11 +445,11 @@ if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
 /**
  * Display navigation to next/previous pages when applicable
  */
-function twentyeleven_content_nav( $nav_id ) {
+function twentyeleven_content_nav( $html_id ) {
        global $wp_query;
 
        if ( $wp_query->max_num_pages > 1 ) : ?>
-               <nav id="<?php echo $nav_id; ?>">
+               <nav id="<?php echo esc_attr( $html_id ); ?>">
                        <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
@@ -521,7 +541,7 @@ function twentyeleven_comment( $comment, $args, $depth ) {
                                                /* translators: 1: comment author, 2: date and time */
                                                printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
                                                        sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
-                                                       sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
+                                                       sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
                                                                esc_url( get_comment_link( $comment->comment_ID ) ),
                                                                get_comment_time( 'c' ),
                                                                /* translators: 1: date, 2: time */
@@ -561,7 +581,7 @@ if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
  * @since Twenty Eleven 1.0
  */
 function twentyeleven_posted_on() {
-       printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
+       printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ),
                esc_url( get_permalink() ),
                esc_attr( get_the_time() ),
                esc_attr( get_the_date( 'c' ) ),