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

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

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 554 lines | 325 code | 52 blank | 177 comment | 30 complexity | 11bcd71bb08008a82d51ee76df648abe MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Set the content width based on the theme's design and stylesheet.
  4. */
  5. if ( ! isset( $content_width ) )
  6. $content_width = 500;
  7. $themecolors = array(
  8. 'bg' => 'ffffff',
  9. 'text' => '000000',
  10. 'link' => '0060ff'
  11. );
  12. /** Tell WordPress to run coraline_setup() when the 'after_setup_theme' hook is run. */
  13. add_action( 'after_setup_theme', 'coraline_setup' );
  14. if ( ! function_exists( 'coraline_setup' ) ):
  15. /**
  16. * Sets up theme defaults and registers support for various WordPress features.
  17. *
  18. * To override coraline_setup() in a child theme, add your own coraline_setup to your child theme's
  19. * functions.php file.
  20. *
  21. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  22. * @uses register_nav_menus() To add support for navigation menus.
  23. * @uses add_custom_background() To add support for a custom background.
  24. * @uses add_editor_style() To style the visual editor.
  25. * @uses load_theme_textdomain() For translation/localization support.
  26. * @uses add_custom_image_header() To add support for a custom header.
  27. * @uses register_default_headers() To register the default custom header images provided with the theme.
  28. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  29. *
  30. * @since Coraline 1.0
  31. */
  32. function coraline_setup() {
  33. // This theme has some pretty cool theme options
  34. require_once ( get_template_directory() . '/inc/theme-options.php' );
  35. // This theme styles the visual editor with editor-style.css to match the theme style.
  36. add_editor_style();
  37. // Post Format support. Legacy category chooser will display in Theme Options for sites that set a category before post formats were added.
  38. add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
  39. // This theme uses post thumbnails
  40. add_theme_support( 'post-thumbnails' );
  41. // Add default posts and comments RSS feed links to head
  42. add_theme_support( 'automatic-feed-links' );
  43. // Make theme available for translation
  44. // Translations can be filed in the /languages/ directory
  45. load_theme_textdomain( 'coraline', TEMPLATEPATH . '/languages' );
  46. $locale = get_locale();
  47. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  48. if ( is_readable( $locale_file ) )
  49. require_once( $locale_file );
  50. // This theme uses wp_nav_menu() in one location.
  51. register_nav_menus( array(
  52. 'primary' => __( 'Primary Navigation', 'coraline' ),
  53. ) );
  54. // This theme allows users to set a custom background
  55. add_custom_background();
  56. // Your changeable header business starts here
  57. define( 'HEADER_TEXTCOLOR', '000' );
  58. // No CSS, just an IMG call. The %s is a placeholder for the theme template directory URI.
  59. define( 'HEADER_IMAGE', '%s/images/headers/water-drops.jpg' );
  60. // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  61. // Add a filter to coraline_header_image_width and coraline_header_image_height to change these values.
  62. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'coraline_header_image_width', 990 ) );
  63. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'coraline_header_image_height', 180 ) );
  64. // We'll be using post thumbnails for custom header images on posts and pages.
  65. // We want them to be 940 pixels wide by 198 pixels tall.
  66. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  67. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  68. // Add a way for the custom header to be styled in the admin panel that controls
  69. // custom headers. See coraline_admin_header_style(), below.
  70. add_custom_image_header( 'coraline_header_style', 'coraline_admin_header_style', 'coraline_admin_header_image' );
  71. // ... and thus ends the changeable header business.
  72. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  73. register_default_headers( array(
  74. 'water-drops' => array(
  75. 'url' => '%s/images/headers/water-drops.jpg',
  76. 'thumbnail_url' => '%s/images/headers/water-drops-thumbnail.jpg',
  77. /* translators: header image description */
  78. 'description' => __( 'Water drops', 'coraline' )
  79. ),
  80. 'limestone-cave' => array(
  81. 'url' => '%s/images/headers/limestone-cave.jpg',
  82. 'thumbnail_url' => '%s/images/headers/limestone-cave-thumbnail.jpg',
  83. /* translators: header image description */
  84. 'description' => __( 'Limestone cave', 'coraline' )
  85. ),
  86. 'Cactii' => array(
  87. 'url' => '%s/images/headers/cactii.jpg',
  88. 'thumbnail_url' => '%s/images/headers/cactii-thumbnail.jpg',
  89. /* translators: header image description */
  90. 'description' => __( 'Cactii', 'coraline' )
  91. )
  92. ) );
  93. }
  94. endif;
  95. if ( ! function_exists( 'coraline_header_style' ) ) :
  96. /**
  97. * Styles the header image and text displayed on the blog
  98. *
  99. * @since Coraline 1.0
  100. */
  101. function coraline_header_style() {
  102. // If no custom options for text are set, let's bail
  103. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  104. if ( HEADER_TEXTCOLOR == get_header_textcolor() )
  105. return;
  106. // If we get this far, we have custom styles. Let's do this.
  107. ?>
  108. <style type="text/css">
  109. <?php
  110. // Has the text been hidden?
  111. if ( 'blank' == get_header_textcolor() ) :
  112. ?>
  113. #site-title,
  114. #site-description {
  115. position: absolute;
  116. left: -9000px;
  117. }
  118. <?php
  119. // If the user has set a custom color for the text use that
  120. else :
  121. ?>
  122. #site-title a,
  123. #site-description {
  124. color: #<?php echo get_header_textcolor(); ?> !important;
  125. }
  126. <?php endif; ?>
  127. </style>
  128. <?php
  129. }
  130. endif;
  131. if ( ! function_exists( 'coraline_admin_header_style' ) ) :
  132. /**
  133. * Styles the header image displayed on the Appearance > Header admin panel.
  134. *
  135. * Referenced via add_custom_image_header() in coraline_setup().
  136. *
  137. * @since Coraline 1.0
  138. */
  139. function coraline_admin_header_style() {
  140. ?>
  141. <style type="text/css">
  142. .appearance_page_custom-header #headimg {
  143. background: #<?php echo get_background_color(); ?>;
  144. border: none;
  145. text-align: center;
  146. }
  147. #headimg h1,
  148. #desc {
  149. font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
  150. }
  151. #headimg h1 {
  152. margin: 0;
  153. }
  154. #headimg h1 a {
  155. font-size: 36px;
  156. letter-spacing: -0.03em;
  157. line-height: 42px;
  158. text-decoration: none;
  159. }
  160. #desc {
  161. font-size: 18px;
  162. line-height: 31px;
  163. padding: 0 0 9px 0;
  164. }
  165. <?php
  166. // If the user has set a custom color for the text use that
  167. if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
  168. ?>
  169. #site-title a,
  170. #site-description {
  171. color: #<?php echo get_header_textcolor(); ?>;
  172. }
  173. <?php endif; ?>
  174. #headimg img {
  175. max-width: 990px;
  176. width: 100%;
  177. }
  178. </style>
  179. <?php
  180. }
  181. endif;
  182. if ( ! function_exists( 'coraline_admin_header_image' ) ) :
  183. /**
  184. * Custom header image markup displayed on the Appearance > Header admin panel.
  185. *
  186. * Referenced via add_custom_image_header() in coraline_setup().
  187. *
  188. * @since Coraline 1.0
  189. */
  190. function coraline_admin_header_image() { ?>
  191. <div id="headimg">
  192. <?php
  193. if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
  194. $style = ' style="display:none;"';
  195. else
  196. $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
  197. ?>
  198. <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo home_url( '/' ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  199. <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  200. <img src="<?php esc_url ( header_image() ); ?>" alt="" />
  201. </div>
  202. <?php }
  203. endif;
  204. /**
  205. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  206. *
  207. * @since Coraline 1.0
  208. */
  209. function coraline_page_menu_args( $args ) {
  210. $args['show_home'] = true;
  211. return $args;
  212. }
  213. add_filter( 'wp_page_menu_args', 'coraline_page_menu_args' );
  214. /**
  215. * Sets the post excerpt length to 40 characters.
  216. *
  217. * @since Coraline 1.0
  218. * @return int
  219. */
  220. function coraline_excerpt_length( $length ) {
  221. return 40;
  222. }
  223. add_filter( 'excerpt_length', 'coraline_excerpt_length' );
  224. /**
  225. * Returns a "Continue Reading" link for excerpts
  226. *
  227. * @since Coraline 1.0
  228. * @return string "Continue Reading" link
  229. */
  230. function coraline_continue_reading_link() {
  231. return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'coraline' ) . '</a>';
  232. }
  233. /**
  234. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and coraline_continue_reading_link().
  235. *
  236. * @since Coraline 1.0
  237. * @return string An ellipsis
  238. */
  239. function coraline_auto_excerpt_more( $more ) {
  240. return ' &hellip;' . coraline_continue_reading_link();
  241. }
  242. add_filter( 'excerpt_more', 'coraline_auto_excerpt_more' );
  243. /**
  244. * Adds a pretty "Continue Reading" link to custom post excerpts.
  245. *
  246. * @since Coraline 1.0
  247. * @return string Excerpt with a pretty "Continue Reading" link
  248. */
  249. function coraline_custom_excerpt_more( $output ) {
  250. if ( has_excerpt() && ! is_attachment() ) {
  251. $output .= coraline_continue_reading_link();
  252. }
  253. return $output;
  254. }
  255. add_filter( 'get_the_excerpt', 'coraline_custom_excerpt_more' );
  256. /**
  257. * Remove inline styles printed when the gallery shortcode is used.
  258. *
  259. * Galleries are styled by the theme in Coraline's style.css.
  260. *
  261. * @since Coraline 1.0
  262. * @return string The gallery style filter, with the styles themselves removed.
  263. */
  264. function coraline_remove_gallery_css( $css ) {
  265. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  266. }
  267. add_filter( 'gallery_style', 'coraline_remove_gallery_css' );
  268. if ( ! function_exists( 'coraline_comment' ) ) :
  269. /**
  270. * Template for comments and pingbacks.
  271. *
  272. * To override this walker in a child theme without modifying the comments template
  273. * simply create your own coraline_comment(), and that function will be used instead.
  274. *
  275. * @since Coraline 1.0
  276. */
  277. function coraline_comment( $comment, $args, $depth ) {
  278. $GLOBALS['comment'] = $comment;
  279. switch ( $comment->comment_type ) :
  280. case '' :
  281. ?>
  282. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  283. <div id="comment-<?php comment_ID(); ?>">
  284. <div class="comment-author vcard">
  285. <?php echo get_avatar( $comment, 48 ); ?>
  286. <cite class="fn"><?php comment_author_link(); ?></cite>
  287. <span class="comment-meta commentmetadata">
  288. |
  289. <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', 'coraline' ),
  293. get_comment_date(),
  294. get_comment_time()
  295. ); ?></a>
  296. |
  297. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  298. <?php edit_comment_link( __( 'Edit', 'coraline' ), ' | ' );
  299. ?>
  300. </span><!-- .comment-meta .commentmetadata -->
  301. </div><!-- .comment-author .vcard -->
  302. <?php if ( $comment->comment_approved == '0' ) : ?>
  303. <em><?php _e( 'Your comment is awaiting moderation.', 'coraline' ); ?></em>
  304. <br />
  305. <?php endif; ?>
  306. <div class="comment-body"><?php comment_text(); ?></div>
  307. </div><!-- #comment-## -->
  308. <?php
  309. break;
  310. case 'pingback' :
  311. case 'trackback' :
  312. ?>
  313. <li class="post pingback">
  314. <p><?php _e( 'Pingback:', 'coraline' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'coraline' ), ' ' ); ?></p>
  315. <?php
  316. break;
  317. endswitch;
  318. }
  319. endif;
  320. /**
  321. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  322. *
  323. * @since Coraline 1.0
  324. * @uses register_sidebar
  325. */
  326. function coraline_widgets_init() {
  327. // Area 1, located at the top of the sidebar.
  328. register_sidebar( array(
  329. 'name' => __( 'Primary Widget Area', 'coraline' ),
  330. 'id' => 'sidebar-1',
  331. 'description' => __( 'The primary widget area', 'coraline' ),
  332. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  333. 'after_widget' => '</li>',
  334. 'before_title' => '<h3 class="widget-title">',
  335. 'after_title' => '</h3>',
  336. ) );
  337. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  338. register_sidebar( array(
  339. 'name' => __( 'Secondary Widget Area', 'coraline' ),
  340. 'id' => 'secondary-widget-area',
  341. 'description' => __( 'The secondary widget area appears in 3-column layouts', 'coraline' ),
  342. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  343. 'after_widget' => '</li>',
  344. 'before_title' => '<h3 class="widget-title">',
  345. 'after_title' => '</h3>',
  346. ) );
  347. // Area 3, located above the primary and secondary sidebars in Content-Sidebar-Sidebar and Sidebar-Sidebar-Content layouts. Empty by default.
  348. register_sidebar( array(
  349. 'name' => __( 'Feature Widget Area', 'coraline' ),
  350. 'id' => 'feature-widget-area',
  351. 'description' => __( 'The feature widget above the sidebars in Content-Sidebar-Sidebar and Sidebar-Sidebar-Content layouts', 'coraline' ),
  352. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  353. 'after_widget' => '</li>',
  354. 'before_title' => '<h3 class="widget-title">',
  355. 'after_title' => '</h3>',
  356. ) );
  357. // Area 4, located in the footer. Empty by default.
  358. register_sidebar( array(
  359. 'name' => __( 'First Footer Widget Area', 'coraline' ),
  360. 'id' => 'first-footer-widget-area',
  361. 'description' => __( 'The first footer widget area', 'coraline' ),
  362. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  363. 'after_widget' => '</li>',
  364. 'before_title' => '<h3 class="widget-title">',
  365. 'after_title' => '</h3>',
  366. ) );
  367. // Area 5, located in the footer. Empty by default.
  368. register_sidebar( array(
  369. 'name' => __( 'Second Footer Widget Area', 'coraline' ),
  370. 'id' => 'second-footer-widget-area',
  371. 'description' => __( 'The second footer widget area', 'coraline' ),
  372. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  373. 'after_widget' => '</li>',
  374. 'before_title' => '<h3 class="widget-title">',
  375. 'after_title' => '</h3>',
  376. ) );
  377. // Area 6, located in the footer. Empty by default.
  378. register_sidebar( array(
  379. 'name' => __( 'Third Footer Widget Area', 'coraline' ),
  380. 'id' => 'third-footer-widget-area',
  381. 'description' => __( 'The third footer widget area', 'coraline' ),
  382. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  383. 'after_widget' => '</li>',
  384. 'before_title' => '<h3 class="widget-title">',
  385. 'after_title' => '</h3>',
  386. ) );
  387. // Area 7, located in the footer. Empty by default.
  388. register_sidebar( array(
  389. 'name' => __( 'Fourth Footer Widget Area', 'coraline' ),
  390. 'id' => 'fourth-footer-widget-area',
  391. 'description' => __( 'The fourth footer widget area', 'coraline' ),
  392. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  393. 'after_widget' => '</li>',
  394. 'before_title' => '<h3 class="widget-title">',
  395. 'after_title' => '</h3>',
  396. ) );
  397. }
  398. /** Register sidebars by running coraline_widgets_init() on the widgets_init hook. */
  399. add_action( 'widgets_init', 'coraline_widgets_init' );
  400. /**
  401. * Removes the default styles that are packaged with the Recent Comments widget.
  402. *
  403. * @since Coraline 1.0
  404. */
  405. function coraline_remove_recent_comments_style() {
  406. global $wp_widget_factory;
  407. remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  408. }
  409. add_action( 'widgets_init', 'coraline_remove_recent_comments_style' );
  410. if ( ! function_exists( 'coraline_posted_on' ) ) :
  411. /**
  412. * Prints HTML with meta information for the current post—date/time and author.
  413. *
  414. * @since Coraline 1.0
  415. */
  416. function coraline_posted_on() {
  417. // use the "byline" class to hide the author name and link. We should make this appear automatically with a multi-author conditional tag in the future
  418. printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="%4$s"><span class="meta-sep">by</span> %3$s</span>', 'coraline' ),
  419. 'meta-prep meta-prep-author',
  420. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  421. get_permalink(),
  422. esc_attr( get_the_time() ),
  423. get_the_date()
  424. ),
  425. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  426. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  427. sprintf( esc_attr__( 'View all posts by %s', 'coraline' ), get_the_author() ),
  428. get_the_author()
  429. ),
  430. 'byline'
  431. );
  432. }
  433. endif;
  434. if ( ! function_exists( 'coraline_posted_in' ) ) :
  435. /**
  436. * Prints HTML with meta information for the current post (category, tags and permalink).
  437. *
  438. * @since Coraline 1.0
  439. */
  440. function coraline_posted_in() {
  441. // Retrieves tag list of current post, separated by commas.
  442. $tag_list = get_the_tag_list( '', ', ' );
  443. if ( $tag_list ) {
  444. $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>.', 'coraline' );
  445. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  446. $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'coraline' );
  447. } else {
  448. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'coraline' );
  449. }
  450. // Prints the string, replacing the placeholders.
  451. printf(
  452. $posted_in,
  453. get_the_category_list( ', ' ),
  454. $tag_list,
  455. get_permalink(),
  456. the_title_attribute( 'echo=0' )
  457. );
  458. }
  459. endif;
  460. /**
  461. * Returns the current Coraline color scheme as selected in the theme options
  462. *
  463. * @since Coraline 1.0
  464. */
  465. function coraline_current_color_scheme() {
  466. $options = get_option( 'coraline_theme_options' );
  467. return $options['color_scheme'];
  468. }
  469. /**
  470. * Register our color schemes and add them to the queue
  471. */
  472. function coraline_color_registrar() {
  473. if ( 'dark' == coraline_current_color_scheme() ) {
  474. wp_register_style( 'dark', get_template_directory_uri() . '/colors/dark.css', null, null );
  475. wp_enqueue_style( 'dark' );
  476. }
  477. }
  478. add_action( 'wp_print_styles', 'coraline_color_registrar' );
  479. /**
  480. * Returns the current Coraline layout as selected in the theme options
  481. *
  482. * @since Coraline 1.0
  483. */
  484. function coraline_current_layout() {
  485. $options = get_option( 'coraline_theme_options' );
  486. $current_layout = $options['theme_layout'];
  487. $two_columns = array( 'content-sidebar', 'sidebar-content' );
  488. if ( in_array( $current_layout, $two_columns ) )
  489. return 'two-column ' . $current_layout;
  490. else
  491. return 'three-column ' . $current_layout;
  492. }
  493. /**
  494. * Adds coraline_current_layout() to the array of body classes
  495. *
  496. * @since Coraline 1.0
  497. */
  498. function coraline_body_class($classes) {
  499. $classes[] = coraline_current_layout();
  500. return $classes;
  501. }
  502. add_filter( 'body_class', 'coraline_body_class' );