wp/wp-content/themes/twentytwelve/functions.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    21  * @subpackage Twenty_Twelve
    21  * @subpackage Twenty_Twelve
    22  * @since Twenty Twelve 1.0
    22  * @since Twenty Twelve 1.0
    23  */
    23  */
    24 
    24 
    25 // Set up the content width value based on the theme's design and stylesheet.
    25 // Set up the content width value based on the theme's design and stylesheet.
    26 if ( ! isset( $content_width ) )
    26 if ( ! isset( $content_width ) ) {
    27 	$content_width = 625;
    27 	$content_width = 625;
       
    28 }
    28 
    29 
    29 /**
    30 /**
    30  * Twenty Twelve setup.
    31  * Twenty Twelve setup.
    31  *
    32  *
    32  * Sets up theme defaults and registers the various WordPress features that
    33  * Sets up theme defaults and registers the various WordPress features that
    33  * Twenty Twelve supports.
    34  * Twenty Twelve supports.
    34  *
    35  *
    35  * @uses load_theme_textdomain() For translation/localization support.
    36  * @uses load_theme_textdomain() For translation/localization support.
    36  * @uses add_editor_style() To add a Visual Editor stylesheet.
    37  * @uses add_editor_style() To add a Visual Editor stylesheet.
    37  * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
    38  * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
    38  * 	custom background, and post formats.
    39  *  custom background, and post formats.
    39  * @uses register_nav_menu() To add support for navigation menus.
    40  * @uses register_nav_menu() To add support for navigation menus.
    40  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
    41  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
    41  *
    42  *
    42  * @since Twenty Twelve 1.0
    43  * @since Twenty Twelve 1.0
    43  */
    44  */
    44 function twentytwelve_setup() {
    45 function twentytwelve_setup() {
    45 	/*
    46 	/*
    46 	 * Makes Twenty Twelve available for translation.
    47 	 * Makes Twenty Twelve available for translation.
    47 	 *
    48 	 *
    48 	 * Translations can be added to the /languages/ directory.
    49 	 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentytwelve
    49 	 * If you're building a theme based on Twenty Twelve, use a find and replace
    50 	 * If you're building a theme based on Twenty Twelve, use a find and replace
    50 	 * to change 'twentytwelve' to the name of your theme in all the template files.
    51 	 * to change 'twentytwelve' to the name of your theme in all the template files.
    51 	 */
    52 	 */
    52 	load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
    53 	load_theme_textdomain( 'twentytwelve' );
    53 
    54 
    54 	// This theme styles the visual editor with editor-style.css to match the theme style.
    55 	// This theme styles the visual editor with editor-style.css to match the theme style.
    55 	add_editor_style();
    56 	add_editor_style();
    56 
    57 
    57 	// Adds RSS feed links to <head> for posts and comments.
    58 	// Adds RSS feed links to <head> for posts and comments.
    65 
    66 
    66 	/*
    67 	/*
    67 	 * This theme supports custom background color and image,
    68 	 * This theme supports custom background color and image,
    68 	 * and here we also set up the default background color.
    69 	 * and here we also set up the default background color.
    69 	 */
    70 	 */
    70 	add_theme_support( 'custom-background', array(
    71 	add_theme_support(
    71 		'default-color' => 'e6e6e6',
    72 		'custom-background', array(
    72 	) );
    73 			'default-color' => 'e6e6e6',
       
    74 		)
       
    75 	);
    73 
    76 
    74 	// This theme uses a custom image size for featured images, displayed on "standard" posts.
    77 	// This theme uses a custom image size for featured images, displayed on "standard" posts.
    75 	add_theme_support( 'post-thumbnails' );
    78 	add_theme_support( 'post-thumbnails' );
    76 	set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop
    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' );
    77 }
    83 }
    78 add_action( 'after_setup_theme', 'twentytwelve_setup' );
    84 add_action( 'after_setup_theme', 'twentytwelve_setup' );
    79 
    85 
    80 /**
    86 /**
    81  * Add support for a custom header image.
    87  * Add support for a custom header image.
   104 		/* translators: To add an additional Open Sans character subset specific to your language,
   110 		/* translators: To add an additional Open Sans character subset specific to your language,
   105 		 * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
   111 		 * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
   106 		 */
   112 		 */
   107 		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
   113 		$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' );
   108 
   114 
   109 		if ( 'cyrillic' == $subset )
   115 		if ( 'cyrillic' == $subset ) {
   110 			$subsets .= ',cyrillic,cyrillic-ext';
   116 			$subsets .= ',cyrillic,cyrillic-ext';
   111 		elseif ( 'greek' == $subset )
   117 		} elseif ( 'greek' == $subset ) {
   112 			$subsets .= ',greek,greek-ext';
   118 			$subsets .= ',greek,greek-ext';
   113 		elseif ( 'vietnamese' == $subset )
   119 		} elseif ( 'vietnamese' == $subset ) {
   114 			$subsets .= ',vietnamese';
   120 			$subsets .= ',vietnamese';
   115 
   121 		}
   116 		$protocol = is_ssl() ? 'https' : 'http';
   122 
   117 		$query_args = array(
   123 		$query_args = array(
   118 			'family' => 'Open+Sans:400italic,700italic,400,700',
   124 			'family' => 'Open+Sans:400italic,700italic,400,700',
   119 			'subset' => $subsets,
   125 			'subset' => $subsets,
   120 		);
   126 		);
   121 		$font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
   127 		$font_url   = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
   122 	}
   128 	}
   123 
   129 
   124 	return $font_url;
   130 	return $font_url;
   125 }
   131 }
   126 
   132 
   127 /**
   133 /**
   128  * Enqueue scripts and styles for front-end.
   134  * Enqueue scripts and styles for front end.
   129  *
   135  *
   130  * @since Twenty Twelve 1.0
   136  * @since Twenty Twelve 1.0
   131  */
   137  */
   132 function twentytwelve_scripts_styles() {
   138 function twentytwelve_scripts_styles() {
   133 	global $wp_styles;
   139 	global $wp_styles;
   134 
   140 
   135 	/*
   141 	/*
   136 	 * Adds JavaScript to pages with the comment form to support
   142 	 * Adds JavaScript to pages with the comment form to support
   137 	 * sites with threaded comments (when in use).
   143 	 * sites with threaded comments (when in use).
   138 	 */
   144 	 */
   139 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
   145 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
   140 		wp_enqueue_script( 'comment-reply' );
   146 		wp_enqueue_script( 'comment-reply' );
       
   147 	}
   141 
   148 
   142 	// Adds JavaScript for handling the navigation menu hide-and-show behavior.
   149 	// Adds JavaScript for handling the navigation menu hide-and-show behavior.
   143 	wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140711', true );
   150 	wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140711', true );
   144 
   151 
   145 	$font_url = twentytwelve_get_font_url();
   152 	$font_url = twentytwelve_get_font_url();
   146 	if ( ! empty( $font_url ) )
   153 	if ( ! empty( $font_url ) ) {
   147 		wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
   154 		wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
       
   155 	}
   148 
   156 
   149 	// Loads our main stylesheet.
   157 	// Loads our main stylesheet.
   150 	wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
   158 	wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );
   151 
   159 
   152 	// Loads the Internet Explorer specific stylesheet.
   160 	// Loads the Internet Explorer specific stylesheet.
   154 	$wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
   162 	$wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' );
   155 }
   163 }
   156 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
   164 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
   157 
   165 
   158 /**
   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 /**
   159  * Filter TinyMCE CSS path to include Google Fonts.
   192  * Filter TinyMCE CSS path to include Google Fonts.
   160  *
   193  *
   161  * Adds additional stylesheets to the TinyMCE editor if needed.
   194  * Adds additional stylesheets to the TinyMCE editor if needed.
   162  *
   195  *
   163  * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
   196  * @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL.
   168  * @return string Filtered CSS path.
   201  * @return string Filtered CSS path.
   169  */
   202  */
   170 function twentytwelve_mce_css( $mce_css ) {
   203 function twentytwelve_mce_css( $mce_css ) {
   171 	$font_url = twentytwelve_get_font_url();
   204 	$font_url = twentytwelve_get_font_url();
   172 
   205 
   173 	if ( empty( $font_url ) )
   206 	if ( empty( $font_url ) ) {
   174 		return $mce_css;
   207 		return $mce_css;
   175 
   208 	}
   176 	if ( ! empty( $mce_css ) )
   209 
       
   210 	if ( ! empty( $mce_css ) ) {
   177 		$mce_css .= ',';
   211 		$mce_css .= ',';
       
   212 	}
   178 
   213 
   179 	$mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
   214 	$mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) );
   180 
   215 
   181 	return $mce_css;
   216 	return $mce_css;
   182 }
   217 }
   195  * @return string Filtered title.
   230  * @return string Filtered title.
   196  */
   231  */
   197 function twentytwelve_wp_title( $title, $sep ) {
   232 function twentytwelve_wp_title( $title, $sep ) {
   198 	global $paged, $page;
   233 	global $paged, $page;
   199 
   234 
   200 	if ( is_feed() )
   235 	if ( is_feed() ) {
   201 		return $title;
   236 		return $title;
       
   237 	}
   202 
   238 
   203 	// Add the site name.
   239 	// Add the site name.
   204 	$title .= get_bloginfo( 'name', 'display' );
   240 	$title .= get_bloginfo( 'name', 'display' );
   205 
   241 
   206 	// Add the site description for the home/front page.
   242 	// Add the site description for the home/front page.
   207 	$site_description = get_bloginfo( 'description', 'display' );
   243 	$site_description = get_bloginfo( 'description', 'display' );
   208 	if ( $site_description && ( is_home() || is_front_page() ) )
   244 	if ( $site_description && ( is_home() || is_front_page() ) ) {
   209 		$title = "$title $sep $site_description";
   245 		$title = "$title $sep $site_description";
       
   246 	}
   210 
   247 
   211 	// Add a page number if necessary.
   248 	// Add a page number if necessary.
   212 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() )
   249 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
   213 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
   250 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
       
   251 	}
   214 
   252 
   215 	return $title;
   253 	return $title;
   216 }
   254 }
   217 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
   255 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
   218 
   256 
   222  * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
   260  * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
   223  *
   261  *
   224  * @since Twenty Twelve 1.0
   262  * @since Twenty Twelve 1.0
   225  */
   263  */
   226 function twentytwelve_page_menu_args( $args ) {
   264 function twentytwelve_page_menu_args( $args ) {
   227 	if ( ! isset( $args['show_home'] ) )
   265 	if ( ! isset( $args['show_home'] ) ) {
   228 		$args['show_home'] = true;
   266 		$args['show_home'] = true;
       
   267 	}
   229 	return $args;
   268 	return $args;
   230 }
   269 }
   231 add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
   270 add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' );
   232 
   271 
   233 /**
   272 /**
   236  * Registers our main widget area and the front page widget areas.
   275  * Registers our main widget area and the front page widget areas.
   237  *
   276  *
   238  * @since Twenty Twelve 1.0
   277  * @since Twenty Twelve 1.0
   239  */
   278  */
   240 function twentytwelve_widgets_init() {
   279 function twentytwelve_widgets_init() {
   241 	register_sidebar( array(
   280 	register_sidebar(
   242 		'name' => __( 'Main Sidebar', 'twentytwelve' ),
   281 		array(
   243 		'id' => 'sidebar-1',
   282 			'name'          => __( 'Main Sidebar', 'twentytwelve' ),
   244 		'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
   283 			'id'            => 'sidebar-1',
   245 		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   284 			'description'   => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ),
   246 		'after_widget' => '</aside>',
   285 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   247 		'before_title' => '<h3 class="widget-title">',
   286 			'after_widget'  => '</aside>',
   248 		'after_title' => '</h3>',
   287 			'before_title'  => '<h3 class="widget-title">',
   249 	) );
   288 			'after_title'   => '</h3>',
   250 
   289 		)
   251 	register_sidebar( array(
   290 	);
   252 		'name' => __( 'First Front Page Widget Area', 'twentytwelve' ),
   291 
   253 		'id' => 'sidebar-2',
   292 	register_sidebar(
   254 		'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
   293 		array(
   255 		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   294 			'name'          => __( 'First Front Page Widget Area', 'twentytwelve' ),
   256 		'after_widget' => '</aside>',
   295 			'id'            => 'sidebar-2',
   257 		'before_title' => '<h3 class="widget-title">',
   296 			'description'   => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
   258 		'after_title' => '</h3>',
   297 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   259 	) );
   298 			'after_widget'  => '</aside>',
   260 
   299 			'before_title'  => '<h3 class="widget-title">',
   261 	register_sidebar( array(
   300 			'after_title'   => '</h3>',
   262 		'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ),
   301 		)
   263 		'id' => 'sidebar-3',
   302 	);
   264 		'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ),
   303 
   265 		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   304 	register_sidebar(
   266 		'after_widget' => '</aside>',
   305 		array(
   267 		'before_title' => '<h3 class="widget-title">',
   306 			'name'          => __( 'Second Front Page Widget Area', 'twentytwelve' ),
   268 		'after_title' => '</h3>',
   307 			'id'            => 'sidebar-3',
   269 	) );
   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 	);
   270 }
   315 }
   271 add_action( 'widgets_init', 'twentytwelve_widgets_init' );
   316 add_action( 'widgets_init', 'twentytwelve_widgets_init' );
   272 
   317 
   273 if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
   318 if ( ! function_exists( 'twentytwelve_content_nav' ) ) :
   274 /**
   319 	/**
   275  * Displays navigation to next/previous pages when applicable.
   320 	 * Displays navigation to next/previous pages when applicable.
   276  *
   321 	 *
   277  * @since Twenty Twelve 1.0
   322 	 * @since Twenty Twelve 1.0
   278  */
   323 	 */
   279 function twentytwelve_content_nav( $html_id ) {
   324 	function twentytwelve_content_nav( $html_id ) {
   280 	global $wp_query;
   325 		global $wp_query;
   281 
   326 
   282 	if ( $wp_query->max_num_pages > 1 ) : ?>
   327 		if ( $wp_query->max_num_pages > 1 ) : ?>
   283 		<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
   328 			<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
   284 			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
   329 				<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
   285 			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
   330 				<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
   286 			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
   331 				<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
   287 		</nav><!-- .navigation -->
   332 			</nav><!-- .navigation -->
   288 	<?php endif;
   333 		<?php
   289 }
   334 	endif;
       
   335 	}
   290 endif;
   336 endif;
   291 
   337 
   292 if ( ! function_exists( 'twentytwelve_comment' ) ) :
   338 if ( ! function_exists( 'twentytwelve_comment' ) ) :
   293 /**
   339 	/**
   294  * Template for comments and pingbacks.
   340 	 * Template for comments and pingbacks.
   295  *
   341 	 *
   296  * To override this walker in a child theme without modifying the comments template
   342 	 * To override this walker in a child theme without modifying the comments template
   297  * simply create your own twentytwelve_comment(), and that function will be used instead.
   343 	 * simply create your own twentytwelve_comment(), and that function will be used instead.
   298  *
   344 	 *
   299  * Used as a callback by wp_list_comments() for displaying the comments.
   345 	 * Used as a callback by wp_list_comments() for displaying the comments.
   300  *
   346 	 *
   301  * @since Twenty Twelve 1.0
   347 	 * @since Twenty Twelve 1.0
   302  */
   348 	 */
   303 function twentytwelve_comment( $comment, $args, $depth ) {
   349 	function twentytwelve_comment( $comment, $args, $depth ) {
   304 	$GLOBALS['comment'] = $comment;
   350 		$GLOBALS['comment'] = $comment;
   305 	switch ( $comment->comment_type ) :
   351 		switch ( $comment->comment_type ) :
   306 		case 'pingback' :
   352 			case 'pingback':
   307 		case 'trackback' :
   353 			case 'trackback':
   308 		// Display trackbacks differently than normal comments.
   354 				// Display trackbacks differently than normal comments.
   309 	?>
   355 		?>
   310 	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
   356 		<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
   311 		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
   357 		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
   312 	<?php
   358 	<?php
   313 			break;
   359 				break;
   314 		default :
   360 			default:
   315 		// Proceed with normal comments.
   361 				// Proceed with normal comments.
   316 		global $post;
   362 				global $post;
   317 	?>
   363 		?>
   318 	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
   364 		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
   319 		<article id="comment-<?php comment_ID(); ?>" class="comment">
   365 		<article id="comment-<?php comment_ID(); ?>" class="comment">
   320 			<header class="comment-meta comment-author vcard">
   366 			<header class="comment-meta comment-author vcard">
   321 				<?php
   367 				<?php
   322 					echo get_avatar( $comment, 44 );
   368 					echo get_avatar( $comment, 44 );
   323 					printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
   369 					printf(
       
   370 						'<cite><b class="fn">%1$s</b> %2$s</cite>',
   324 						get_comment_author_link(),
   371 						get_comment_author_link(),
   325 						// If current post author is also comment author, make it known visually.
   372 						// If current post author is also comment author, make it known visually.
   326 						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
   373 						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
   327 					);
   374 					);
   328 					printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
   375 					printf(
       
   376 						'<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
   329 						esc_url( get_comment_link( $comment->comment_ID ) ),
   377 						esc_url( get_comment_link( $comment->comment_ID ) ),
   330 						get_comment_time( 'c' ),
   378 						get_comment_time( 'c' ),
   331 						/* translators: 1: date, 2: time */
   379 						/* translators: 1: date, 2: time */
   332 						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
   380 						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
   333 					);
   381 					);
   334 				?>
   382 					?>
   335 			</header><!-- .comment-meta -->
   383 				</header><!-- .comment-meta -->
   336 
   384 
   337 			<?php if ( '0' == $comment->comment_approved ) : ?>
   385 				<?php if ( '0' == $comment->comment_approved ) : ?>
   338 				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
   386 				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
   339 			<?php endif; ?>
   387 			<?php endif; ?>
   340 
   388 
   341 			<section class="comment-content comment">
   389 				<section class="comment-content comment">
   342 				<?php comment_text(); ?>
   390 				<?php comment_text(); ?>
   343 				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
   391 				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
   344 			</section><!-- .comment-content -->
   392 				</section><!-- .comment-content -->
   345 
   393 
   346 			<div class="reply">
   394 				<div class="reply">
   347 				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
   395 				<?php
   348 			</div><!-- .reply -->
   396 				comment_reply_link(
   349 		</article><!-- #comment-## -->
   397 					array_merge(
   350 	<?php
   398 						$args, array(
   351 		break;
   399 							'reply_text' => __( 'Reply', 'twentytwelve' ),
   352 	endswitch; // end comment_type check
   400 							'after'      => ' <span>&darr;</span>',
   353 }
   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 	}
   354 endif;
   413 endif;
   355 
   414 
   356 if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
   415 if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
   357 /**
   416 	/**
   358  * Set up post entry meta.
   417 	 * Set up post entry meta.
   359  *
   418 	 *
   360  * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
   419 	 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
   361  *
   420 	 *
   362  * Create your own twentytwelve_entry_meta() to override in a child theme.
   421 	 * Create your own twentytwelve_entry_meta() to override in a child theme.
   363  *
   422 	 *
   364  * @since Twenty Twelve 1.0
   423 	 * @since Twenty Twelve 1.0
   365  */
   424 	 */
   366 function twentytwelve_entry_meta() {
   425 	function twentytwelve_entry_meta() {
   367 	// Translators: used between list items, there is a space after the comma.
   426 		// Translators: used between list items, there is a space after the comma.
   368 	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
   427 		$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
   369 
   428 
   370 	// Translators: used between list items, there is a space after the comma.
   429 		// Translators: used between list items, there is a space after the comma.
   371 	$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
   430 		$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
   372 
   431 
   373 	$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
   432 		$date = sprintf(
   374 		esc_url( get_permalink() ),
   433 			'<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
   375 		esc_attr( get_the_time() ),
   434 			esc_url( get_permalink() ),
   376 		esc_attr( get_the_date( 'c' ) ),
   435 			esc_attr( get_the_time() ),
   377 		esc_html( get_the_date() )
   436 			esc_attr( get_the_date( 'c' ) ),
   378 	);
   437 			esc_html( get_the_date() )
   379 
   438 		);
   380 	$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
   439 
   381 		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
   440 		$author = sprintf(
   382 		esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
   441 			'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
   383 		get_the_author()
   442 			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
   384 	);
   443 			esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
   385 
   444 			get_the_author()
   386 	// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
   445 		);
   387 	if ( $tag_list ) {
   446 
   388 		$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' );
   447 		// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
   389 	} elseif ( $categories_list ) {
   448 		if ( $tag_list ) {
   390 		$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
   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' );
   391 	} else {
   450 		} elseif ( $categories_list ) {
   392 		$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
   451 			$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
   393 	}
   452 		} else {
   394 
   453 			$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' );
   395 	printf(
   454 		}
   396 		$utility_text,
   455 
   397 		$categories_list,
   456 		printf(
   398 		$tag_list,
   457 			$utility_text,
   399 		$date,
   458 			$categories_list,
   400 		$author
   459 			$tag_list,
   401 	);
   460 			$date,
   402 }
   461 			$author
       
   462 		);
       
   463 	}
   403 endif;
   464 endif;
   404 
   465 
   405 /**
   466 /**
   406  * Extend the default WordPress body classes.
   467  * Extend the default WordPress body classes.
   407  *
   468  *
   421  */
   482  */
   422 function twentytwelve_body_class( $classes ) {
   483 function twentytwelve_body_class( $classes ) {
   423 	$background_color = get_background_color();
   484 	$background_color = get_background_color();
   424 	$background_image = get_background_image();
   485 	$background_image = get_background_image();
   425 
   486 
   426 	if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
   487 	if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) {
   427 		$classes[] = 'full-width';
   488 		$classes[] = 'full-width';
       
   489 	}
   428 
   490 
   429 	if ( is_page_template( 'page-templates/front-page.php' ) ) {
   491 	if ( is_page_template( 'page-templates/front-page.php' ) ) {
   430 		$classes[] = 'template-front-page';
   492 		$classes[] = 'template-front-page';
   431 		if ( has_post_thumbnail() )
   493 		if ( has_post_thumbnail() ) {
   432 			$classes[] = 'has-post-thumbnail';
   494 			$classes[] = 'has-post-thumbnail';
   433 		if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) )
   495 		}
       
   496 		if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) {
   434 			$classes[] = 'two-sidebars';
   497 			$classes[] = 'two-sidebars';
       
   498 		}
   435 	}
   499 	}
   436 
   500 
   437 	if ( empty( $background_image ) ) {
   501 	if ( empty( $background_image ) ) {
   438 		if ( empty( $background_color ) )
   502 		if ( empty( $background_color ) ) {
   439 			$classes[] = 'custom-background-empty';
   503 			$classes[] = 'custom-background-empty';
   440 		elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) )
   504 		} elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) {
   441 			$classes[] = 'custom-background-white';
   505 			$classes[] = 'custom-background-white';
       
   506 		}
   442 	}
   507 	}
   443 
   508 
   444 	// Enable custom font class only if the font CSS is queued to load.
   509 	// Enable custom font class only if the font CSS is queued to load.
   445 	if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) )
   510 	if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) {
   446 		$classes[] = 'custom-font-enabled';
   511 		$classes[] = 'custom-font-enabled';
   447 
   512 	}
   448 	if ( ! is_multi_author() )
   513 
       
   514 	if ( ! is_multi_author() ) {
   449 		$classes[] = 'single-author';
   515 		$classes[] = 'single-author';
       
   516 	}
   450 
   517 
   451 	return $classes;
   518 	return $classes;
   452 }
   519 }
   453 add_filter( 'body_class', 'twentytwelve_body_class' );
   520 add_filter( 'body_class', 'twentytwelve_body_class' );
   454 
   521 
   479  */
   546  */
   480 function twentytwelve_customize_register( $wp_customize ) {
   547 function twentytwelve_customize_register( $wp_customize ) {
   481 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   548 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   482 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   549 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   483 	$wp_customize->get_setting( 'header_textcolor' )->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 	}
   484 }
   568 }
   485 add_action( 'customize_register', 'twentytwelve_customize_register' );
   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 }
   486 
   594 
   487 /**
   595 /**
   488  * Enqueue Javascript postMessage handlers for the Customizer.
   596  * Enqueue Javascript postMessage handlers for the Customizer.
   489  *
   597  *
   490  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
   598  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
   493  */
   601  */
   494 function twentytwelve_customize_preview_js() {
   602 function twentytwelve_customize_preview_js() {
   495 	wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
   603 	wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
   496 }
   604 }
   497 add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
   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' );