PageRenderTime 365ms CodeModel.GetById 101ms app.highlight 149ms RepoModel.GetById 73ms app.codeStats 1ms

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

https://bitbucket.org/aqge/deptandashboard
PHP | 508 lines | 248 code | 41 blank | 219 comment | 18 complexity | e27c0756392fe44e3ef6cb6c75eac44e MD5 | raw file
  1<?php
  2/**
  3 * TwentyTen 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, twentyten_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', 'twentyten_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_Ten
 38 * @since Twenty Ten 1.0
 39 */
 40
 41/**
 42 * Set the content width based on the theme's design and stylesheet.
 43 *
 44 * Used to set the width of images and content. Should be equal to the width the theme
 45 * is designed for, generally via the style.css stylesheet.
 46 */
 47if ( ! isset( $content_width ) )
 48	$content_width = 640;
 49
 50/** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
 51add_action( 'after_setup_theme', 'twentyten_setup' );
 52
 53if ( ! function_exists( 'twentyten_setup' ) ):
 54/**
 55 * Sets up theme defaults and registers support for various WordPress features.
 56 *
 57 * Note that this function is hooked into the after_setup_theme hook, which runs
 58 * before the init hook. The init hook is too late for some features, such as indicating
 59 * support post thumbnails.
 60 *
 61 * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
 62 * functions.php file.
 63 *
 64 * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
 65 * @uses register_nav_menus() To add support for navigation menus.
 66 * @uses add_custom_background() To add support for a custom background.
 67 * @uses add_editor_style() To style the visual editor.
 68 * @uses load_theme_textdomain() For translation/localization support.
 69 * @uses add_custom_image_header() To add support for a custom header.
 70 * @uses register_default_headers() To register the default custom header images provided with the theme.
 71 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 72 *
 73 * @since Twenty Ten 1.0
 74 */
 75function twentyten_setup() {
 76
 77	// This theme styles the visual editor with editor-style.css to match the theme style.
 78	add_editor_style();
 79
 80	// Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
 81	add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
 82
 83	// This theme uses post thumbnails
 84	add_theme_support( 'post-thumbnails' );
 85
 86	// Add default posts and comments RSS feed links to head
 87	add_theme_support( 'automatic-feed-links' );
 88
 89	// Make theme available for translation
 90	// Translations can be filed in the /languages/ directory
 91	load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' );
 92
 93	$locale = get_locale();
 94	$locale_file = get_template_directory() . "/languages/$locale.php";
 95	if ( is_readable( $locale_file ) )
 96		require_once( $locale_file );
 97
 98	// This theme uses wp_nav_menu() in one location.
 99	register_nav_menus( array(
100		'primary' => __( 'Primary Navigation', 'twentyten' ),
101	) );
102
103	// This theme allows users to set a custom background
104	add_custom_background();
105
106	// Your changeable header business starts here
107	if ( ! defined( 'HEADER_TEXTCOLOR' ) )
108		define( 'HEADER_TEXTCOLOR', '' );
109
110	// No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
111	if ( ! defined( 'HEADER_IMAGE' ) )
112		define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
113
114	// The height and width of your custom header. You can hook into the theme's own filters to change these values.
115	// Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
116	define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
117	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
118
119	// We'll be using post thumbnails for custom header images on posts and pages.
120	// We want them to be 940 pixels wide by 198 pixels tall.
121	// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
122	set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
123
124	// Don't support text inside the header image.
125	if ( ! defined( 'NO_HEADER_TEXT' ) )
126		define( 'NO_HEADER_TEXT', true );
127
128	// Add a way for the custom header to be styled in the admin panel that controls
129	// custom headers. See twentyten_admin_header_style(), below.
130	add_custom_image_header( '', 'twentyten_admin_header_style' );
131
132	// ... and thus ends the changeable header business.
133
134	// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
135	register_default_headers( array(
136		'berries' => array(
137			'url' => '%s/images/headers/berries.jpg',
138			'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
139			/* translators: header image description */
140			'description' => __( 'Berries', 'twentyten' )
141		),
142		'cherryblossom' => array(
143			'url' => '%s/images/headers/cherryblossoms.jpg',
144			'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
145			/* translators: header image description */
146			'description' => __( 'Cherry Blossoms', 'twentyten' )
147		),
148		'concave' => array(
149			'url' => '%s/images/headers/concave.jpg',
150			'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
151			/* translators: header image description */
152			'description' => __( 'Concave', 'twentyten' )
153		),
154		'fern' => array(
155			'url' => '%s/images/headers/fern.jpg',
156			'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
157			/* translators: header image description */
158			'description' => __( 'Fern', 'twentyten' )
159		),
160		'forestfloor' => array(
161			'url' => '%s/images/headers/forestfloor.jpg',
162			'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
163			/* translators: header image description */
164			'description' => __( 'Forest Floor', 'twentyten' )
165		),
166		'inkwell' => array(
167			'url' => '%s/images/headers/inkwell.jpg',
168			'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
169			/* translators: header image description */
170			'description' => __( 'Inkwell', 'twentyten' )
171		),
172		'path' => array(
173			'url' => '%s/images/headers/path.jpg',
174			'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
175			/* translators: header image description */
176			'description' => __( 'Path', 'twentyten' )
177		),
178		'sunset' => array(
179			'url' => '%s/images/headers/sunset.jpg',
180			'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
181			/* translators: header image description */
182			'description' => __( 'Sunset', 'twentyten' )
183		)
184	) );
185}
186endif;
187
188if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
189/**
190 * Styles the header image displayed on the Appearance > Header admin panel.
191 *
192 * Referenced via add_custom_image_header() in twentyten_setup().
193 *
194 * @since Twenty Ten 1.0
195 */
196function twentyten_admin_header_style() {
197?>
198<style type="text/css">
199/* Shows the same border as on front end */
200#headimg {
201	border-bottom: 1px solid #000;
202	border-top: 4px solid #000;
203}
204/* If NO_HEADER_TEXT is false, you would style the text with these selectors:
205	#headimg #name { }
206	#headimg #desc { }
207*/
208</style>
209<?php
210}
211endif;
212
213/**
214 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
215 *
216 * To override this in a child theme, remove the filter and optionally add
217 * your own function tied to the wp_page_menu_args filter hook.
218 *
219 * @since Twenty Ten 1.0
220 */
221function twentyten_page_menu_args( $args ) {
222	$args['show_home'] = true;
223	return $args;
224}
225add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
226
227/**
228 * Sets the post excerpt length to 40 characters.
229 *
230 * To override this length in a child theme, remove the filter and add your own
231 * function tied to the excerpt_length filter hook.
232 *
233 * @since Twenty Ten 1.0
234 * @return int
235 */
236function twentyten_excerpt_length( $length ) {
237	return 40;
238}
239add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
240
241/**
242 * Returns a "Continue Reading" link for excerpts
243 *
244 * @since Twenty Ten 1.0
245 * @return string "Continue Reading" link
246 */
247function twentyten_continue_reading_link() {
248	return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
249}
250
251/**
252 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
253 *
254 * To override this in a child theme, remove the filter and add your own
255 * function tied to the excerpt_more filter hook.
256 *
257 * @since Twenty Ten 1.0
258 * @return string An ellipsis
259 */
260function twentyten_auto_excerpt_more( $more ) {
261	return ' &hellip;' . twentyten_continue_reading_link();
262}
263add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
264
265/**
266 * Adds a pretty "Continue Reading" link to custom post excerpts.
267 *
268 * To override this link in a child theme, remove the filter and add your own
269 * function tied to the get_the_excerpt filter hook.
270 *
271 * @since Twenty Ten 1.0
272 * @return string Excerpt with a pretty "Continue Reading" link
273 */
274function twentyten_custom_excerpt_more( $output ) {
275	if ( has_excerpt() && ! is_attachment() ) {
276		$output .= twentyten_continue_reading_link();
277	}
278	return $output;
279}
280add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
281
282/**
283 * Remove inline styles printed when the gallery shortcode is used.
284 *
285 * Galleries are styled by the theme in Twenty Ten's style.css. This is just
286 * a simple filter call that tells WordPress to not use the default styles.
287 *
288 * @since Twenty Ten 1.2
289 */
290add_filter( 'use_default_gallery_style', '__return_false' );
291
292/**
293 * Deprecated way to remove inline styles printed when the gallery shortcode is used.
294 *
295 * This function is no longer needed or used. Use the use_default_gallery_style
296 * filter instead, as seen above.
297 *
298 * @since Twenty Ten 1.0
299 * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
300 *
301 * @return string The gallery style filter, with the styles themselves removed.
302 */
303function twentyten_remove_gallery_css( $css ) {
304	return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
305}
306// Backwards compatibility with WordPress 3.0.
307if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
308	add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
309
310if ( ! function_exists( 'twentyten_comment' ) ) :
311/**
312 * Template for comments and pingbacks.
313 *
314 * To override this walker in a child theme without modifying the comments template
315 * simply create your own twentyten_comment(), and that function will be used instead.
316 *
317 * Used as a callback by wp_list_comments() for displaying the comments.
318 *
319 * @since Twenty Ten 1.0
320 */
321function twentyten_comment( $comment, $args, $depth ) {
322	$GLOBALS['comment'] = $comment;
323	switch ( $comment->comment_type ) :
324		case '' :
325	?>
326	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
327		<div id="comment-<?php comment_ID(); ?>">
328		<div class="comment-author vcard">
329			<?php echo get_avatar( $comment, 40 ); ?>
330			<?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
331		</div><!-- .comment-author .vcard -->
332		<?php if ( $comment->comment_approved == '0' ) : ?>
333			<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
334			<br />
335		<?php endif; ?>
336
337		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
338			<?php
339				/* translators: 1: date, 2: time */
340				printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
341			?>
342		</div><!-- .comment-meta .commentmetadata -->
343
344		<div class="comment-body"><?php comment_text(); ?></div>
345
346		<div class="reply">
347			<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
348		</div><!-- .reply -->
349	</div><!-- #comment-##  -->
350
351	<?php
352			break;
353		case 'pingback'  :
354		case 'trackback' :
355	?>
356	<li class="post pingback">
357		<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
358	<?php
359			break;
360	endswitch;
361}
362endif;
363
364/**
365 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
366 *
367 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
368 * function tied to the init hook.
369 *
370 * @since Twenty Ten 1.0
371 * @uses register_sidebar
372 */
373function twentyten_widgets_init() {
374	// Area 1, located at the top of the sidebar.
375	register_sidebar( array(
376		'name' => __( 'Primary Widget Area', 'twentyten' ),
377		'id' => 'primary-widget-area',
378		'description' => __( 'The primary widget area', 'twentyten' ),
379		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
380		'after_widget' => '</li>',
381		'before_title' => '<h3 class="widget-title">',
382		'after_title' => '</h3>',
383	) );
384
385	// Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
386	register_sidebar( array(
387		'name' => __( 'Secondary Widget Area', 'twentyten' ),
388		'id' => 'secondary-widget-area',
389		'description' => __( 'The secondary widget area', 'twentyten' ),
390		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
391		'after_widget' => '</li>',
392		'before_title' => '<h3 class="widget-title">',
393		'after_title' => '</h3>',
394	) );
395
396	// Area 3, located in the footer. Empty by default.
397	register_sidebar( array(
398		'name' => __( 'First Footer Widget Area', 'twentyten' ),
399		'id' => 'first-footer-widget-area',
400		'description' => __( 'The first footer widget area', 'twentyten' ),
401		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
402		'after_widget' => '</li>',
403		'before_title' => '<h3 class="widget-title">',
404		'after_title' => '</h3>',
405	) );
406
407	// Area 4, located in the footer. Empty by default.
408	register_sidebar( array(
409		'name' => __( 'Second Footer Widget Area', 'twentyten' ),
410		'id' => 'second-footer-widget-area',
411		'description' => __( 'The second footer widget area', 'twentyten' ),
412		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
413		'after_widget' => '</li>',
414		'before_title' => '<h3 class="widget-title">',
415		'after_title' => '</h3>',
416	) );
417
418	// Area 5, located in the footer. Empty by default.
419	register_sidebar( array(
420		'name' => __( 'Third Footer Widget Area', 'twentyten' ),
421		'id' => 'third-footer-widget-area',
422		'description' => __( 'The third footer widget area', 'twentyten' ),
423		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
424		'after_widget' => '</li>',
425		'before_title' => '<h3 class="widget-title">',
426		'after_title' => '</h3>',
427	) );
428
429	// Area 6, located in the footer. Empty by default.
430	register_sidebar( array(
431		'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
432		'id' => 'fourth-footer-widget-area',
433		'description' => __( 'The fourth footer widget area', 'twentyten' ),
434		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
435		'after_widget' => '</li>',
436		'before_title' => '<h3 class="widget-title">',
437		'after_title' => '</h3>',
438	) );
439}
440/** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
441add_action( 'widgets_init', 'twentyten_widgets_init' );
442
443/**
444 * Removes the default styles that are packaged with the Recent Comments widget.
445 *
446 * To override this in a child theme, remove the filter and optionally add your own
447 * function tied to the widgets_init action hook.
448 *
449 * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
450 * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
451 * but they won't have any effect on the widget in default Twenty Ten styling.
452 *
453 * @since Twenty Ten 1.0
454 */
455function twentyten_remove_recent_comments_style() {
456	add_filter( 'show_recent_comments_widget_style', '__return_false' );
457}
458add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
459
460if ( ! function_exists( 'twentyten_posted_on' ) ) :
461/**
462 * Prints HTML with meta information for the current post-date/time and author.
463 *
464 * @since Twenty Ten 1.0
465 */
466function twentyten_posted_on() {
467	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
468		'meta-prep meta-prep-author',
469		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
470			get_permalink(),
471			esc_attr( get_the_time() ),
472			get_the_date()
473		),
474		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
475			get_author_posts_url( get_the_author_meta( 'ID' ) ),
476			esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
477			get_the_author()
478		)
479	);
480}
481endif;
482
483if ( ! function_exists( 'twentyten_posted_in' ) ) :
484/**
485 * Prints HTML with meta information for the current post (category, tags and permalink).
486 *
487 * @since Twenty Ten 1.0
488 */
489function twentyten_posted_in() {
490	// Retrieves tag list of current post, separated by commas.
491	$tag_list = get_the_tag_list( '', ', ' );
492	if ( $tag_list ) {
493		$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
494	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
495		$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
496	} else {
497		$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
498	}
499	// Prints the string, replacing the placeholders.
500	printf(
501		$posted_in,
502		get_the_category_list( ', ' ),
503		$tag_list,
504		get_permalink(),
505		the_title_attribute( 'echo=0' )
506	);
507}
508endif;