PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

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