PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

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