wp/wp-content/themes/twentytwelve/functions.php
changeset 8 c7c34916027a
parent 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
7:cf61fcea0001 8:c7c34916027a
     1 <?php
       
     2 /**
       
     3  * Twenty Twelve functions and definitions
       
     4  *
       
     5  * Sets up the theme and provides some helper functions, which are used
       
     6  * in the theme as custom template tags. Others are attached to action and
       
     7  * filter hooks in WordPress to change core functionality.
       
     8  *
       
     9  * When using a child theme (see https://codex.wordpress.org/Theme_Development and
       
    10  * https://codex.wordpress.org/Child_Themes), you can override certain functions
       
    11  * (those wrapped in a function_exists() call) by defining them first in your child theme's
       
    12  * functions.php file. The child theme's functions.php file is included before the parent
       
    13  * theme's file, so the child theme functions would be used.
       
    14  *
       
    15  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
       
    16  * to a filter or action hook.
       
    17  *
       
    18  * For more information on hooks, actions, and filters, @link https://codex.wordpress.org/Plugin_API
       
    19  *
       
    20  * @package WordPress
       
    21  * @subpackage Twenty_Twelve
       
    22  * @since Twenty Twelve 1.0
       
    23  */
       
    24 
       
    25 // Set up the content width value based on the theme's design and stylesheet.
       
    26 if ( ! isset( $content_width ) ) {
       
    27 	$content_width = 625;
       
    28 }
       
    29 
       
    30 /**
       
    31  * Twenty Twelve setup.
       
    32  *
       
    33  * Sets up theme defaults and registers the various WordPress features that
       
    34  * Twenty Twelve supports.
       
    35  *
       
    36  * @uses load_theme_textdomain() For translation/localization support.
       
    37  * @uses add_editor_style() To add a Visual Editor stylesheet.
       
    38  * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
       
    39  *  custom background, and post formats.
       
    40  * @uses register_nav_menu() To add support for navigation menus.
       
    41  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
       
    42  *
       
    43  * @since Twenty Twelve 1.0
       
    44  */
       
    45 function twentytwelve_setup() {
       
    46 	/*
       
    47 	 * Makes Twenty Twelve available for translation.
       
    48 	 *
       
    49 	 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentytwelve
       
    50 	 * If you're building a theme based on Twenty Twelve, use a find and replace
       
    51 	 * to change 'twentytwelve' to the name of your theme in all the template files.
       
    52 	 */
       
    53 	load_theme_textdomain( 'twentytwelve' );
       
    54 
       
    55 	// This theme styles the visual editor with editor-style.css to match the theme style.
       
    56 	add_editor_style();
       
    57 
       
    58 	// Adds RSS feed links to <head> for posts and comments.
       
    59 	add_theme_support( 'automatic-feed-links' );
       
    60 
       
    61 	// This theme supports a variety of post formats.
       
    62 	add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
       
    63 
       
    64 	// This theme uses wp_nav_menu() in one location.
       
    65 	register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
       
    66 
       
    67 	/*
       
    68 	 * This theme supports custom background color and image,
       
    69 	 * and here we also set up the default background color.
       
    70 	 */
       
    71 	add_theme_support(
       
    72 		'custom-background', array(
       
    73 			'default-color' => 'e6e6e6',
       
    74 		)
       
    75 	);
       
    76 
       
    77 	// This theme uses a custom image size for featured images, displayed on "standard" posts.
       
    78 	add_theme_support( 'post-thumbnails' );
       
    79 	set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop
       
    80 
       
    81 	// Indicate widget sidebars can use selective refresh in the Customizer.
       
    82 	add_theme_support( 'customize-selective-refresh-widgets' );
       
    83 }
       
    84 add_action( 'after_setup_theme', 'twentytwelve_setup' );
       
    85 
       
    86 /**
       
    87  * Add support for a custom header image.
       
    88  */
       
    89 require( get_template_directory() . '/inc/custom-header.php' );
       
    90 
       
    91 /**
       
    92  * Return the Google font stylesheet URL if available.
       
    93  *
       
    94  * The use of Open Sans by default is localized. For languages that use
       
    95  * characters not supported by the font, the font can be disabled.
       
    96  *
       
    97  * @since Twenty Twelve 1.2
       
    98  *
       
    99  * @return string Font stylesheet or empty string if disabled.
       
   100  */
       
   101 function twentytwelve_get_font_url() {
       
   102 	$font_url = '';
       
   103 
       
   104 	/* translators: If there are characters in your language that are not supported
       
   105 	 * by Open Sans, translate this to 'off'. Do not translate into your own language.
       
   106 	 */
       
   107 	if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) {
       
   108 		$subsets = 'latin,latin-ext';
       
   109 
       
   110 		/* translators: To add an additional Open Sans character subset specific to your language,
       
   111 		 * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
       
   112 		 */
       
   113 		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
       
   114 
       
   115 		if ( 'cyrillic' == $subset ) {
       
   116 			$subsets .= ',cyrillic,cyrillic-ext';
       
   117 		} elseif ( 'greek' == $subset ) {
       
   118 			$subsets .= ',greek,greek-ext';
       
   119 		} elseif ( 'vietnamese' == $subset ) {
       
   120 			$subsets .= ',vietnamese';
       
   121 		}
       
   122 
       
   123 		$query_args = array(
       
   124 			'family' => 'Open+Sans:400italic,700italic,400,700',
       
   125 			'subset' => $subsets,
       
   126 		);
       
   127 		$font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
       
   128 	}
       
   129 
       
   130 	return $font_url;
       
   131 }
       
   132 
       
   133 /**
       
   134  * Enqueue scripts and styles for front end.
       
   135  *
       
   136  * @since Twenty Twelve 1.0
       
   137  */
       
   138 function twentytwelve_scripts_styles() {
       
   139 	global $wp_styles;
       
   140 
       
   141 	/*
       
   142 	 * Adds JavaScript to pages with the comment form to support
       
   143 	 * sites with threaded comments (when in use).
       
   144 	 */
       
   145 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
       
   146 		wp_enqueue_script( 'comment-reply' );
       
   147 	}
       
   148 
       
   149 	// Adds JavaScript for handling the navigation menu hide-and-show behavior.
       
   150 	wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140711', true );
       
   151 
       
   152 	$font_url = twentytwelve_get_font_url();
       
   153 	if ( ! empty( $font_url ) ) {
       
   154 		wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
       
   155 	}
       
   156 
       
   157 	// Loads our main stylesheet.
       
   158 	wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
       
   159 
       
   160 	// Loads the Internet Explorer specific stylesheet.
       
   161 	wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' );
       
   162 	$wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
       
   163 }
       
   164 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
       
   165 
       
   166 /**
       
   167  * Add preconnect for Google Fonts.
       
   168  *
       
   169  * @since Twenty Twelve 2.2
       
   170  *
       
   171  * @param array   $urls          URLs to print for resource hints.
       
   172  * @param string  $relation_type The relation type the URLs are printed.
       
   173  * @return array URLs to print for resource hints.
       
   174  */
       
   175 function twentytwelve_resource_hints( $urls, $relation_type ) {
       
   176 	if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
       
   177 		if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
       
   178 			$urls[] = array(
       
   179 				'href' => 'https://fonts.gstatic.com',
       
   180 				'crossorigin',
       
   181 			);
       
   182 		} else {
       
   183 			$urls[] = 'https://fonts.gstatic.com';
       
   184 		}
       
   185 	}
       
   186 
       
   187 	return $urls;
       
   188 }
       
   189 add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
       
   190 
       
   191 /**
       
   192  * Filter TinyMCE CSS path to include Google Fonts.
       
   193  *
       
   194  * Adds additional stylesheets to the TinyMCE editor if needed.
       
   195  *
       
   196  * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
       
   197  *
       
   198  * @since Twenty Twelve 1.2
       
   199  *
       
   200  * @param string $mce_css CSS path to load in TinyMCE.
       
   201  * @return string Filtered CSS path.
       
   202  */
       
   203 function twentytwelve_mce_css( $mce_css ) {
       
   204 	$font_url = twentytwelve_get_font_url();
       
   205 
       
   206 	if ( empty( $font_url ) ) {
       
   207 		return $mce_css;
       
   208 	}
       
   209 
       
   210 	if ( ! empty( $mce_css ) ) {
       
   211 		$mce_css .= ',';
       
   212 	}
       
   213 
       
   214 	$mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
       
   215 
       
   216 	return $mce_css;
       
   217 }
       
   218 add_filter( 'mce_css', 'twentytwelve_mce_css' );
       
   219 
       
   220 /**
       
   221  * Filter the page title.
       
   222  *
       
   223  * Creates a nicely formatted and more specific title element text
       
   224  * for output in head of document, based on current view.
       
   225  *
       
   226  * @since Twenty Twelve 1.0
       
   227  *
       
   228  * @param string $title Default title text for current view.
       
   229  * @param string $sep Optional separator.
       
   230  * @return string Filtered title.
       
   231  */
       
   232 function twentytwelve_wp_title( $title, $sep ) {
       
   233 	global $paged, $page;
       
   234 
       
   235 	if ( is_feed() ) {
       
   236 		return $title;
       
   237 	}
       
   238 
       
   239 	// Add the site name.
       
   240 	$title .= get_bloginfo( 'name', 'display' );
       
   241 
       
   242 	// Add the site description for the home/front page.
       
   243 	$site_description = get_bloginfo( 'description', 'display' );
       
   244 	if ( $site_description && ( is_home() || is_front_page() ) ) {
       
   245 		$title = "$title $sep $site_description";
       
   246 	}
       
   247 
       
   248 	// Add a page number if necessary.
       
   249 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
       
   250 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
       
   251 	}
       
   252 
       
   253 	return $title;
       
   254 }
       
   255 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
       
   256 
       
   257 /**
       
   258  * Filter the page menu arguments.
       
   259  *
       
   260  * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
       
   261  *
       
   262  * @since Twenty Twelve 1.0
       
   263  */
       
   264 function twentytwelve_page_menu_args( $args ) {
       
   265 	if ( ! isset( $args['show_home'] ) ) {
       
   266 		$args['show_home'] = true;
       
   267 	}
       
   268 	return $args;
       
   269 }
       
   270 add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
       
   271 
       
   272 /**
       
   273  * Register sidebars.
       
   274  *
       
   275  * Registers our main widget area and the front page widget areas.
       
   276  *
       
   277  * @since Twenty Twelve 1.0
       
   278  */
       
   279 function twentytwelve_widgets_init() {
       
   280 	register_sidebar(
       
   281 		array(
       
   282 			'name'          => __( 'Main Sidebar', 'twentytwelve' ),
       
   283 			'id'            => 'sidebar-1',
       
   284 			'description'   => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
       
   285 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
       
   286 			'after_widget'  => '</aside>',
       
   287 			'before_title'  => '<h3 class="widget-title">',
       
   288 			'after_title'   => '</h3>',
       
   289 		)
       
   290 	);
       
   291 
       
   292 	register_sidebar(
       
   293 		array(
       
   294 			'name'          => __( 'First Front Page Widget Area', 'twentytwelve' ),
       
   295 			'id'            => 'sidebar-2',
       
   296 			'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
       
   297 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
       
   298 			'after_widget'  => '</aside>',
       
   299 			'before_title'  => '<h3 class="widget-title">',
       
   300 			'after_title'   => '</h3>',
       
   301 		)
       
   302 	);
       
   303 
       
   304 	register_sidebar(
       
   305 		array(
       
   306 			'name'          => __( 'Second Front Page Widget Area', 'twentytwelve' ),
       
   307 			'id'            => 'sidebar-3',
       
   308 			'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
       
   309 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
       
   310 			'after_widget'  => '</aside>',
       
   311 			'before_title'  => '<h3 class="widget-title">',
       
   312 			'after_title'   => '</h3>',
       
   313 		)
       
   314 	);
       
   315 }
       
   316 add_action( 'widgets_init', 'twentytwelve_widgets_init' );
       
   317 
       
   318 if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
       
   319 	/**
       
   320 	 * Displays navigation to next/previous pages when applicable.
       
   321 	 *
       
   322 	 * @since Twenty Twelve 1.0
       
   323 	 */
       
   324 	function twentytwelve_content_nav( $html_id ) {
       
   325 		global $wp_query;
       
   326 
       
   327 		if ( $wp_query->max_num_pages > 1 ) : ?>
       
   328 			<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
       
   329 				<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
       
   330 				<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
       
   331 				<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
       
   332 			</nav><!-- .navigation -->
       
   333 		<?php
       
   334 	endif;
       
   335 	}
       
   336 endif;
       
   337 
       
   338 if ( ! function_exists( 'twentytwelve_comment' ) ) :
       
   339 	/**
       
   340 	 * Template for comments and pingbacks.
       
   341 	 *
       
   342 	 * To override this walker in a child theme without modifying the comments template
       
   343 	 * simply create your own twentytwelve_comment(), and that function will be used instead.
       
   344 	 *
       
   345 	 * Used as a callback by wp_list_comments() for displaying the comments.
       
   346 	 *
       
   347 	 * @since Twenty Twelve 1.0
       
   348 	 */
       
   349 	function twentytwelve_comment( $comment, $args, $depth ) {
       
   350 		$GLOBALS['comment'] = $comment;
       
   351 		switch ( $comment->comment_type ) :
       
   352 			case 'pingback':
       
   353 			case 'trackback':
       
   354 				// Display trackbacks differently than normal comments.
       
   355 		?>
       
   356 		<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
       
   357 		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
       
   358 	<?php
       
   359 				break;
       
   360 			default:
       
   361 				// Proceed with normal comments.
       
   362 				global $post;
       
   363 		?>
       
   364 		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
       
   365 		<article id="comment-<?php comment_ID(); ?>" class="comment">
       
   366 			<header class="comment-meta comment-author vcard">
       
   367 				<?php
       
   368 					echo get_avatar( $comment, 44 );
       
   369 					printf(
       
   370 						'<cite><b class="fn">%1$s</b> %2$s</cite>',
       
   371 						get_comment_author_link(),
       
   372 						// If current post author is also comment author, make it known visually.
       
   373 						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
       
   374 					);
       
   375 					printf(
       
   376 						'<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
       
   377 						esc_url( get_comment_link( $comment->comment_ID ) ),
       
   378 						get_comment_time( 'c' ),
       
   379 						/* translators: 1: date, 2: time */
       
   380 						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
       
   381 					);
       
   382 					?>
       
   383 				</header><!-- .comment-meta -->
       
   384 
       
   385 				<?php if ( '0' == $comment->comment_approved ) : ?>
       
   386 				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
       
   387 			<?php endif; ?>
       
   388 
       
   389 				<section class="comment-content comment">
       
   390 				<?php comment_text(); ?>
       
   391 				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
       
   392 				</section><!-- .comment-content -->
       
   393 
       
   394 				<div class="reply">
       
   395 				<?php
       
   396 				comment_reply_link(
       
   397 					array_merge(
       
   398 						$args, array(
       
   399 							'reply_text' => __( 'Reply', 'twentytwelve' ),
       
   400 							'after'      => ' <span>&darr;</span>',
       
   401 							'depth'      => $depth,
       
   402 							'max_depth'  => $args['max_depth'],
       
   403 						)
       
   404 					)
       
   405 				);
       
   406 ?>
       
   407 				</div><!-- .reply -->
       
   408 			</article><!-- #comment-## -->
       
   409 		<?php
       
   410 				break;
       
   411 		endswitch; // end comment_type check
       
   412 	}
       
   413 endif;
       
   414 
       
   415 if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
       
   416 	/**
       
   417 	 * Set up post entry meta.
       
   418 	 *
       
   419 	 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
       
   420 	 *
       
   421 	 * Create your own twentytwelve_entry_meta() to override in a child theme.
       
   422 	 *
       
   423 	 * @since Twenty Twelve 1.0
       
   424 	 */
       
   425 	function twentytwelve_entry_meta() {
       
   426 		// Translators: used between list items, there is a space after the comma.
       
   427 		$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
       
   428 
       
   429 		// Translators: used between list items, there is a space after the comma.
       
   430 		$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
       
   431 
       
   432 		$date = sprintf(
       
   433 			'<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
       
   434 			esc_url( get_permalink() ),
       
   435 			esc_attr( get_the_time() ),
       
   436 			esc_attr( get_the_date( 'c' ) ),
       
   437 			esc_html( get_the_date() )
       
   438 		);
       
   439 
       
   440 		$author = sprintf(
       
   441 			'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
       
   442 			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
       
   443 			esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
       
   444 			get_the_author()
       
   445 		);
       
   446 
       
   447 		// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
       
   448 		if ( $tag_list ) {
       
   449 			$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
       
   450 		} elseif ( $categories_list ) {
       
   451 			$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
       
   452 		} else {
       
   453 			$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
       
   454 		}
       
   455 
       
   456 		printf(
       
   457 			$utility_text,
       
   458 			$categories_list,
       
   459 			$tag_list,
       
   460 			$date,
       
   461 			$author
       
   462 		);
       
   463 	}
       
   464 endif;
       
   465 
       
   466 /**
       
   467  * Extend the default WordPress body classes.
       
   468  *
       
   469  * Extends the default WordPress body class to denote:
       
   470  * 1. Using a full-width layout, when no active widgets in the sidebar
       
   471  *    or full-width template.
       
   472  * 2. Front Page template: thumbnail in use and number of sidebars for
       
   473  *    widget areas.
       
   474  * 3. White or empty background color to change the layout and spacing.
       
   475  * 4. Custom fonts enabled.
       
   476  * 5. Single or multiple authors.
       
   477  *
       
   478  * @since Twenty Twelve 1.0
       
   479  *
       
   480  * @param array $classes Existing class values.
       
   481  * @return array Filtered class values.
       
   482  */
       
   483 function twentytwelve_body_class( $classes ) {
       
   484 	$background_color = get_background_color();
       
   485 	$background_image = get_background_image();
       
   486 
       
   487 	if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) {
       
   488 		$classes[] = 'full-width';
       
   489 	}
       
   490 
       
   491 	if ( is_page_template( 'page-templates/front-page.php' ) ) {
       
   492 		$classes[] = 'template-front-page';
       
   493 		if ( has_post_thumbnail() ) {
       
   494 			$classes[] = 'has-post-thumbnail';
       
   495 		}
       
   496 		if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) {
       
   497 			$classes[] = 'two-sidebars';
       
   498 		}
       
   499 	}
       
   500 
       
   501 	if ( empty( $background_image ) ) {
       
   502 		if ( empty( $background_color ) ) {
       
   503 			$classes[] = 'custom-background-empty';
       
   504 		} elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) {
       
   505 			$classes[] = 'custom-background-white';
       
   506 		}
       
   507 	}
       
   508 
       
   509 	// Enable custom font class only if the font CSS is queued to load.
       
   510 	if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) {
       
   511 		$classes[] = 'custom-font-enabled';
       
   512 	}
       
   513 
       
   514 	if ( ! is_multi_author() ) {
       
   515 		$classes[] = 'single-author';
       
   516 	}
       
   517 
       
   518 	return $classes;
       
   519 }
       
   520 add_filter( 'body_class', 'twentytwelve_body_class' );
       
   521 
       
   522 /**
       
   523  * Adjust content width in certain contexts.
       
   524  *
       
   525  * Adjusts content_width value for full-width and single image attachment
       
   526  * templates, and when there are no active widgets in the sidebar.
       
   527  *
       
   528  * @since Twenty Twelve 1.0
       
   529  */
       
   530 function twentytwelve_content_width() {
       
   531 	if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
       
   532 		global $content_width;
       
   533 		$content_width = 960;
       
   534 	}
       
   535 }
       
   536 add_action( 'template_redirect', 'twentytwelve_content_width' );
       
   537 
       
   538 /**
       
   539  * Register postMessage support.
       
   540  *
       
   541  * Add postMessage support for site title and description for the Customizer.
       
   542  *
       
   543  * @since Twenty Twelve 1.0
       
   544  *
       
   545  * @param WP_Customize_Manager $wp_customize Customizer object.
       
   546  */
       
   547 function twentytwelve_customize_register( $wp_customize ) {
       
   548 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
       
   549 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
       
   550 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
       
   551 
       
   552 	if ( isset( $wp_customize->selective_refresh ) ) {
       
   553 		$wp_customize->selective_refresh->add_partial(
       
   554 			'blogname', array(
       
   555 				'selector'            => '.site-title > a',
       
   556 				'container_inclusive' => false,
       
   557 				'render_callback'     => 'twentytwelve_customize_partial_blogname',
       
   558 			)
       
   559 		);
       
   560 		$wp_customize->selective_refresh->add_partial(
       
   561 			'blogdescription', array(
       
   562 				'selector'            => '.site-description',
       
   563 				'container_inclusive' => false,
       
   564 				'render_callback'     => 'twentytwelve_customize_partial_blogdescription',
       
   565 			)
       
   566 		);
       
   567 	}
       
   568 }
       
   569 add_action( 'customize_register', 'twentytwelve_customize_register' );
       
   570 
       
   571 /**
       
   572  * Render the site title for the selective refresh partial.
       
   573  *
       
   574  * @since Twenty Twelve 2.0
       
   575  * @see twentytwelve_customize_register()
       
   576  *
       
   577  * @return void
       
   578  */
       
   579 function twentytwelve_customize_partial_blogname() {
       
   580 	bloginfo( 'name' );
       
   581 }
       
   582 
       
   583 /**
       
   584  * Render the site tagline for the selective refresh partial.
       
   585  *
       
   586  * @since Twenty Twelve 2.0
       
   587  * @see twentytwelve_customize_register()
       
   588  *
       
   589  * @return void
       
   590  */
       
   591 function twentytwelve_customize_partial_blogdescription() {
       
   592 	bloginfo( 'description' );
       
   593 }
       
   594 
       
   595 /**
       
   596  * Enqueue Javascript postMessage handlers for the Customizer.
       
   597  *
       
   598  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
       
   599  *
       
   600  * @since Twenty Twelve 1.0
       
   601  */
       
   602 function twentytwelve_customize_preview_js() {
       
   603 	wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
       
   604 }
       
   605 add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
       
   606 
       
   607 
       
   608 /**
       
   609  * Modifies tag cloud widget arguments to display all tags in the same font size
       
   610  * and use list format for better accessibility.
       
   611  *
       
   612  * @since Twenty Twelve 2.4
       
   613  *
       
   614  * @param array $args Arguments for tag cloud widget.
       
   615  * @return array The filtered arguments for tag cloud widget.
       
   616  */
       
   617 function twentytwelve_widget_tag_cloud_args( $args ) {
       
   618 	$args['largest']  = 22;
       
   619 	$args['smallest'] = 8;
       
   620 	$args['unit']     = 'pt';
       
   621 	$args['format']   = 'list';
       
   622 
       
   623 	return $args;
       
   624 }
       
   625 add_filter( 'widget_tag_cloud_args', 'twentytwelve_widget_tag_cloud_args' );