PageRenderTime 188ms CodeModel.GetById 81ms app.highlight 46ms RepoModel.GetById 54ms app.codeStats 1ms

/wp-content/themes/twentyeleven/functions.php

https://bitbucket.org/aqge/deptandashboard
PHP | 594 lines | 326 code | 65 blank | 203 comment | 41 complexity | ffd08dfe89978fd3fa5d4b072cf53eb3 MD5 | raw file
  1<?php
  2/**
  3 * Twenty Eleven functions and definitions
  4 *
  5 * Sets up the theme and provides some helper functions. Some helper functions
  6 * are used in the theme as custom template tags. Others are attached to action and
  7 * filter hooks in WordPress to change core functionality.
  8 *
  9 * The first function, twentyeleven_setup(), sets up the theme by registering support
 10 * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
 11 *
 12 * When using a child theme (see http://codex.wordpress.org/Theme_Development and
 13 * http://codex.wordpress.org/Child_Themes), you can override certain functions
 14 * (those wrapped in a function_exists() call) by defining them first in your child theme's
 15 * functions.php file. The child theme's functions.php file is included before the parent
 16 * theme's file, so the child theme functions would be used.
 17 *
 18 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 19 * to a filter or action hook. The hook can be removed by using remove_action() or
 20 * remove_filter() and you can attach your own function to the hook.
 21 *
 22 * We can remove the parent theme's hook only after it is attached, which means we need to
 23 * wait until setting up the child theme:
 24 *
 25 * <code>
 26 * add_action( 'after_setup_theme', 'my_child_theme_setup' );
 27 * function my_child_theme_setup() {
 28 *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
 29 *     remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
 30 *     ...
 31 * }
 32 * </code>
 33 *
 34 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 35 *
 36 * @package WordPress
 37 * @subpackage Twenty_Eleven
 38 * @since Twenty Eleven 1.0
 39 */
 40
 41/**
 42 * Set the content width based on the theme's design and stylesheet.
 43 */
 44if ( ! isset( $content_width ) )
 45	$content_width = 584;
 46
 47/**
 48 * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
 49 */
 50add_action( 'after_setup_theme', 'twentyeleven_setup' );
 51
 52if ( ! function_exists( 'twentyeleven_setup' ) ):
 53/**
 54 * Sets up theme defaults and registers support for various WordPress features.
 55 *
 56 * Note that this function is hooked into the after_setup_theme hook, which runs
 57 * before the init hook. The init hook is too late for some features, such as indicating
 58 * support post thumbnails.
 59 *
 60 * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's
 61 * functions.php file.
 62 *
 63 * @uses load_theme_textdomain() For translation/localization support.
 64 * @uses add_editor_style() To style the visual editor.
 65 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats.
 66 * @uses register_nav_menus() To add support for navigation menus.
 67 * @uses add_custom_background() To add support for a custom background.
 68 * @uses add_custom_image_header() To add support for a custom header.
 69 * @uses register_default_headers() To register the default custom header images provided with the theme.
 70 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 71 *
 72 * @since Twenty Eleven 1.0
 73 */
 74function twentyeleven_setup() {
 75
 76	/* Make Twenty Eleven available for translation.
 77	 * Translations can be added to the /languages/ directory.
 78	 * If you're building a theme based on Twenty Eleven, use a find and replace
 79	 * to change 'twentyeleven' to the name of your theme in all the template files.
 80	 */
 81	load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
 82
 83	$locale = get_locale();
 84	$locale_file = get_template_directory() . "/languages/$locale.php";
 85	if ( is_readable( $locale_file ) )
 86		require_once( $locale_file );
 87
 88	// This theme styles the visual editor with editor-style.css to match the theme style.
 89	add_editor_style();
 90
 91	// Load up our theme options page and related code.
 92	require( get_template_directory() . '/inc/theme-options.php' );
 93
 94	// Grab Twenty Eleven's Ephemera widget.
 95	require( get_template_directory() . '/inc/widgets.php' );
 96
 97	// Add default posts and comments RSS feed links to <head>.
 98	add_theme_support( 'automatic-feed-links' );
 99
100	// This theme uses wp_nav_menu() in one location.
101	register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );
102
103	// Add support for a variety of post formats
104	add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
105
106	// Add support for custom backgrounds
107	add_custom_background();
108
109	// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
110	add_theme_support( 'post-thumbnails' );
111
112	// The next four constants set how Twenty Eleven supports custom headers.
113
114	// The default header text color
115	define( 'HEADER_TEXTCOLOR', '000' );
116
117	// By leaving empty, we allow for random image rotation.
118	define( 'HEADER_IMAGE', '' );
119
120	// The height and width of your custom header.
121	// Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
122	define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
123	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
124
125	// We'll be using post thumbnails for custom header images on posts and pages.
126	// We want them to be the size of the header image that we just defined
127	// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
128	set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
129
130	// Add Twenty Eleven's custom image sizes
131	add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
132	add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
133
134	// Turn on random header image rotation by default.
135	add_theme_support( 'custom-header', array( 'random-default' => true ) );
136
137	// Add a way for the custom header to be styled in the admin panel that controls
138	// custom headers. See twentyeleven_admin_header_style(), below.
139	add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' );
140
141	// ... and thus ends the changeable header business.
142
143	// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
144	register_default_headers( array(
145		'wheel' => array(
146			'url' => '%s/images/headers/wheel.jpg',
147			'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
148			/* translators: header image description */
149			'description' => __( 'Wheel', 'twentyeleven' )
150		),
151		'shore' => array(
152			'url' => '%s/images/headers/shore.jpg',
153			'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
154			/* translators: header image description */
155			'description' => __( 'Shore', 'twentyeleven' )
156		),
157		'trolley' => array(
158			'url' => '%s/images/headers/trolley.jpg',
159			'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',
160			/* translators: header image description */
161			'description' => __( 'Trolley', 'twentyeleven' )
162		),
163		'pine-cone' => array(
164			'url' => '%s/images/headers/pine-cone.jpg',
165			'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',
166			/* translators: header image description */
167			'description' => __( 'Pine Cone', 'twentyeleven' )
168		),
169		'chessboard' => array(
170			'url' => '%s/images/headers/chessboard.jpg',
171			'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',
172			/* translators: header image description */
173			'description' => __( 'Chessboard', 'twentyeleven' )
174		),
175		'lanterns' => array(
176			'url' => '%s/images/headers/lanterns.jpg',
177			'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',
178			/* translators: header image description */
179			'description' => __( 'Lanterns', 'twentyeleven' )
180		),
181		'willow' => array(
182			'url' => '%s/images/headers/willow.jpg',
183			'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',
184			/* translators: header image description */
185			'description' => __( 'Willow', 'twentyeleven' )
186		),
187		'hanoi' => array(
188			'url' => '%s/images/headers/hanoi.jpg',
189			'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',
190			/* translators: header image description */
191			'description' => __( 'Hanoi Plant', 'twentyeleven' )
192		)
193	) );
194}
195endif; // twentyeleven_setup
196
197if ( ! function_exists( 'twentyeleven_header_style' ) ) :
198/**
199 * Styles the header image and text displayed on the blog
200 *
201 * @since Twenty Eleven 1.0
202 */
203function twentyeleven_header_style() {
204
205	// If no custom options for text are set, let's bail
206	// get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
207	if ( HEADER_TEXTCOLOR == get_header_textcolor() )
208		return;
209	// If we get this far, we have custom styles. Let's do this.
210	?>
211	<style type="text/css">
212	<?php
213		// Has the text been hidden?
214		if ( 'blank' == get_header_textcolor() ) :
215	?>
216		#site-title,
217		#site-description {
218			position: absolute !important;
219			clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
220			clip: rect(1px, 1px, 1px, 1px);
221		}
222	<?php
223		// If the user has set a custom color for the text use that
224		else :
225	?>
226		#site-title a,
227		#site-description {
228			color: #<?php echo get_header_textcolor(); ?> !important;
229		}
230	<?php endif; ?>
231	</style>
232	<?php
233}
234endif; // twentyeleven_header_style
235
236if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
237/**
238 * Styles the header image displayed on the Appearance > Header admin panel.
239 *
240 * Referenced via add_custom_image_header() in twentyeleven_setup().
241 *
242 * @since Twenty Eleven 1.0
243 */
244function twentyeleven_admin_header_style() {
245?>
246	<style type="text/css">
247	.appearance_page_custom-header #headimg {
248		border: none;
249	}
250	#headimg h1,
251	#desc {
252		font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
253	}
254	#headimg h1 {
255		margin: 0;
256	}
257	#headimg h1 a {
258		font-size: 32px;
259		line-height: 36px;
260		text-decoration: none;
261	}
262	#desc {
263		font-size: 14px;
264		line-height: 23px;
265		padding: 0 0 3em;
266	}
267	<?php
268		// If the user has set a custom color for the text use that
269		if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
270	?>
271		#site-title a,
272		#site-description {
273			color: #<?php echo get_header_textcolor(); ?>;
274		}
275	<?php endif; ?>
276	#headimg img {
277		max-width: 1000px;
278		height: auto;
279		width: 100%;
280	}
281	</style>
282<?php
283}
284endif; // twentyeleven_admin_header_style
285
286if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
287/**
288 * Custom header image markup displayed on the Appearance > Header admin panel.
289 *
290 * Referenced via add_custom_image_header() in twentyeleven_setup().
291 *
292 * @since Twenty Eleven 1.0
293 */
294function twentyeleven_admin_header_image() { ?>
295	<div id="headimg">
296		<?php
297		if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
298			$style = ' style="display:none;"';
299		else
300			$style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
301		?>
302		<h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
303		<div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
304		<?php $header_image = get_header_image();
305		if ( ! empty( $header_image ) ) : ?>
306			<img src="<?php echo esc_url( $header_image ); ?>" alt="" />
307		<?php endif; ?>
308	</div>
309<?php }
310endif; // twentyeleven_admin_header_image
311
312/**
313 * Sets the post excerpt length to 40 words.
314 *
315 * To override this length in a child theme, remove the filter and add your own
316 * function tied to the excerpt_length filter hook.
317 */
318function twentyeleven_excerpt_length( $length ) {
319	return 40;
320}
321add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
322
323/**
324 * Returns a "Continue Reading" link for excerpts
325 */
326function twentyeleven_continue_reading_link() {
327	return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
328}
329
330/**
331 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link().
332 *
333 * To override this in a child theme, remove the filter and add your own
334 * function tied to the excerpt_more filter hook.
335 */
336function twentyeleven_auto_excerpt_more( $more ) {
337	return ' &hellip;' . twentyeleven_continue_reading_link();
338}
339add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
340
341/**
342 * Adds a pretty "Continue Reading" link to custom post excerpts.
343 *
344 * To override this link in a child theme, remove the filter and add your own
345 * function tied to the get_the_excerpt filter hook.
346 */
347function twentyeleven_custom_excerpt_more( $output ) {
348	if ( has_excerpt() && ! is_attachment() ) {
349		$output .= twentyeleven_continue_reading_link();
350	}
351	return $output;
352}
353add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
354
355/**
356 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
357 */
358function twentyeleven_page_menu_args( $args ) {
359	$args['show_home'] = true;
360	return $args;
361}
362add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
363
364/**
365 * Register our sidebars and widgetized areas. Also register the default Epherma widget.
366 *
367 * @since Twenty Eleven 1.0
368 */
369function twentyeleven_widgets_init() {
370
371	register_widget( 'Twenty_Eleven_Ephemera_Widget' );
372
373	register_sidebar( array(
374		'name' => __( 'Main Sidebar', 'twentyeleven' ),
375		'id' => 'sidebar-1',
376		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
377		'after_widget' => "</aside>",
378		'before_title' => '<h3 class="widget-title">',
379		'after_title' => '</h3>',
380	) );
381
382	register_sidebar( array(
383		'name' => __( 'Showcase Sidebar', 'twentyeleven' ),
384		'id' => 'sidebar-2',
385		'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
386		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
387		'after_widget' => "</aside>",
388		'before_title' => '<h3 class="widget-title">',
389		'after_title' => '</h3>',
390	) );
391
392	register_sidebar( array(
393		'name' => __( 'Footer Area One', 'twentyeleven' ),
394		'id' => 'sidebar-3',
395		'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
396		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
397		'after_widget' => "</aside>",
398		'before_title' => '<h3 class="widget-title">',
399		'after_title' => '</h3>',
400	) );
401
402	register_sidebar( array(
403		'name' => __( 'Footer Area Two', 'twentyeleven' ),
404		'id' => 'sidebar-4',
405		'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
406		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
407		'after_widget' => "</aside>",
408		'before_title' => '<h3 class="widget-title">',
409		'after_title' => '</h3>',
410	) );
411
412	register_sidebar( array(
413		'name' => __( 'Footer Area Three', 'twentyeleven' ),
414		'id' => 'sidebar-5',
415		'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
416		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
417		'after_widget' => "</aside>",
418		'before_title' => '<h3 class="widget-title">',
419		'after_title' => '</h3>',
420	) );
421}
422add_action( 'widgets_init', 'twentyeleven_widgets_init' );
423
424if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
425/**
426 * Display navigation to next/previous pages when applicable
427 */
428function twentyeleven_content_nav( $nav_id ) {
429	global $wp_query;
430
431	if ( $wp_query->max_num_pages > 1 ) : ?>
432		<nav id="<?php echo $nav_id; ?>">
433			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
434			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
435			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
436		</nav><!-- #nav-above -->
437	<?php endif;
438}
439endif; // twentyeleven_content_nav
440
441/**
442 * Return the URL for the first link found in the post content.
443 *
444 * @since Twenty Eleven 1.0
445 * @return string|bool URL or false when no link is present.
446 */
447function twentyeleven_url_grabber() {
448	if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
449		return false;
450
451	return esc_url_raw( $matches[1] );
452}
453
454/**
455 * Count the number of footer sidebars to enable dynamic classes for the footer
456 */
457function twentyeleven_footer_sidebar_class() {
458	$count = 0;
459
460	if ( is_active_sidebar( 'sidebar-3' ) )
461		$count++;
462
463	if ( is_active_sidebar( 'sidebar-4' ) )
464		$count++;
465
466	if ( is_active_sidebar( 'sidebar-5' ) )
467		$count++;
468
469	$class = '';
470
471	switch ( $count ) {
472		case '1':
473			$class = 'one';
474			break;
475		case '2':
476			$class = 'two';
477			break;
478		case '3':
479			$class = 'three';
480			break;
481	}
482
483	if ( $class )
484		echo 'class="' . $class . '"';
485}
486
487if ( ! function_exists( 'twentyeleven_comment' ) ) :
488/**
489 * Template for comments and pingbacks.
490 *
491 * To override this walker in a child theme without modifying the comments template
492 * simply create your own twentyeleven_comment(), and that function will be used instead.
493 *
494 * Used as a callback by wp_list_comments() for displaying the comments.
495 *
496 * @since Twenty Eleven 1.0
497 */
498function twentyeleven_comment( $comment, $args, $depth ) {
499	$GLOBALS['comment'] = $comment;
500	switch ( $comment->comment_type ) :
501		case 'pingback' :
502		case 'trackback' :
503	?>
504	<li class="post pingback">
505		<p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
506	<?php
507			break;
508		default :
509	?>
510	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
511		<article id="comment-<?php comment_ID(); ?>" class="comment">
512			<footer class="comment-meta">
513				<div class="comment-author vcard">
514					<?php
515						$avatar_size = 68;
516						if ( '0' != $comment->comment_parent )
517							$avatar_size = 39;
518
519						echo get_avatar( $comment, $avatar_size );
520
521						/* translators: 1: comment author, 2: date and time */
522						printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
523							sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
524							sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
525								esc_url( get_comment_link( $comment->comment_ID ) ),
526								get_comment_time( 'c' ),
527								/* translators: 1: date, 2: time */
528								sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
529							)
530						);
531					?>
532
533					<?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
534				</div><!-- .comment-author .vcard -->
535
536				<?php if ( $comment->comment_approved == '0' ) : ?>
537					<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em>
538					<br />
539				<?php endif; ?>
540
541			</footer>
542
543			<div class="comment-content"><?php comment_text(); ?></div>
544
545			<div class="reply">
546				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
547			</div><!-- .reply -->
548		</article><!-- #comment-## -->
549
550	<?php
551			break;
552	endswitch;
553}
554endif; // ends check for twentyeleven_comment()
555
556if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
557/**
558 * Prints HTML with meta information for the current post-date/time and author.
559 * Create your own twentyeleven_posted_on to override in a child theme
560 *
561 * @since Twenty Eleven 1.0
562 */
563function twentyeleven_posted_on() {
564	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' ),
565		esc_url( get_permalink() ),
566		esc_attr( get_the_time() ),
567		esc_attr( get_the_date( 'c' ) ),
568		esc_html( get_the_date() ),
569		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
570		esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
571		get_the_author()
572	);
573}
574endif;
575
576/**
577 * Adds two classes to the array of body classes.
578 * The first is if the site has only had one author with published posts.
579 * The second is if a singular post being displayed
580 *
581 * @since Twenty Eleven 1.0
582 */
583function twentyeleven_body_classes( $classes ) {
584
585	if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
586		$classes[] = 'single-author';
587
588	if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
589		$classes[] = 'singular';
590
591	return $classes;
592}
593add_filter( 'body_class', 'twentyeleven_body_classes' );
594