PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

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