extras.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Custom functions that act independently of the theme templates.
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features.
  6. *
  7. * @package Dara
  8. */
  9. /**
  10. * Adds custom classes to the array of body classes.
  11. *
  12. * @param array $classes Classes for the body element.
  13. * @return array
  14. */
  15. function dara_body_classes( $classes ) {
  16. // Adds a class of group-blog to blogs with more than 1 published author.
  17. if ( is_multi_author() ) {
  18. $classes[] = 'group-blog';
  19. }
  20. // Adds a class of hfeed to non-singular pages.
  21. if ( ! is_singular() ) {
  22. $classes[] = 'hfeed';
  23. }
  24. // Add a class of no-sidebar when there is no sidebar present
  25. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  26. $classes[] = 'no-sidebar';
  27. }
  28. if ( is_page_template( 'full-width-page.php' ) || is_page_template( 'grid-page.php' ) )
  29. $classes[] = 'full-width-page';
  30. if ( ! is_multi_author() ) {
  31. $classes[] = 'not-multi-author';
  32. }
  33. if ( display_header_text() ) {
  34. $classes[] = 'display-header-text';
  35. }
  36. if ( is_page() && ! comments_open() && '0' == get_comments_number() ) {
  37. $classes[] = 'comments-closed';
  38. }
  39. return $classes;
  40. }
  41. add_filter( 'body_class', 'dara_body_classes' );
  42. /**
  43. * Adds custom classes to the array of post classes.
  44. */
  45. function dara_post_classes( $classes ) {
  46. if ( ( 'post' !== get_post_type() && ! has_post_thumbnail() ) ||
  47. ( 'post' === get_post_type() && ! dara_has_post_thumbnail() ) ||
  48. ! dara_activate_featured_image() ) {
  49. $classes[] = 'without-featured-image';
  50. } else {
  51. $classes[] = 'with-featured-image';
  52. }
  53. return $classes;
  54. }
  55. add_filter( 'post_class', 'dara_post_classes' );
  56. /*
  57. * Check Jetpack Content Options for Featured Image settings to aid
  58. * in setting post_class and other classes.
  59. * If Jetpack is not active, images are activated by default.
  60. */
  61. function dara_activate_featured_image() {
  62. if ( function_exists( 'jetpack_featured_images_get_settings' ) ) {
  63. $jetpackopts = jetpack_featured_images_get_settings();
  64. if (
  65. ( true == $jetpackopts['page-option'] && is_page() && has_post_thumbnail() ) ||
  66. ( true == $jetpackopts['post-option'] && is_single() && dara_has_post_thumbnail() ) ||
  67. ( true == $jetpackopts['archive-option'] && ( is_home() || is_archive() || is_search() && dara_has_post_thumbnail() ) )
  68. ) {
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. else {
  75. return true;
  76. }
  77. }
  78. /**
  79. * Add a pingback url auto-discovery header for singularly identifiable articles.
  80. */
  81. function dara_pingback_header() {
  82. if ( is_singular() && pings_open() ) {
  83. echo '<link rel="pingback" href="', bloginfo( 'pingback_url' ), '">';
  84. }
  85. }
  86. add_action( 'wp_head', 'dara_pingback_header' );