PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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