jetpack.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.com/
  6. *
  7. * @package Karuna
  8. */
  9. /**
  10. * Jetpack setup function.
  11. */
  12. function karuna_jetpack_setup() {
  13. // Add theme support for Infinite Scroll.
  14. add_theme_support( 'infinite-scroll', array(
  15. 'container' => 'main',
  16. 'render' => 'karuna_infinite_scroll_render',
  17. 'footer' => 'page',
  18. 'footer_widgets' => array( 'sidebar-2', 'sidebar-3', 'sidebar-5', 'sidebar-6', 'sidebar-7' ),
  19. ) );
  20. // Add theme support for Responsive Videos.
  21. add_theme_support( 'jetpack-responsive-videos' );
  22. // Add theme support for Social Menus
  23. add_theme_support( 'jetpack-social-menu', 'svg' );
  24. // Add theme support for Testimonials
  25. add_theme_support( 'jetpack-testimonial' );
  26. //Add theme support for Content Options.
  27. add_theme_support( 'jetpack-content-options', array(
  28. 'blog-display' => 'content',
  29. 'author-bio' => true,
  30. 'author-bio-default' => false,
  31. 'post-details' => array(
  32. 'stylesheet' => 'karuna-style',
  33. 'date' => '.posted-on',
  34. 'categories' => '.cat-links',
  35. 'tags' => '.tags-links',
  36. 'author' => '.byline',
  37. ),
  38. 'featured-images' => array(
  39. 'archive' => true,
  40. 'post' => true,
  41. 'page' => true,
  42. 'fallback' => true,
  43. 'fallback-default' => false,
  44. ),
  45. ) );
  46. }
  47. add_action( 'after_setup_theme', 'karuna_jetpack_setup' );
  48. /**
  49. * Custom render function for Infinite Scroll.
  50. */
  51. function karuna_infinite_scroll_render() {
  52. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  53. karuna_woocommerce_product_columns_wrapper();
  54. woocommerce_product_loop_start();
  55. }
  56. while ( have_posts() ) {
  57. the_post();
  58. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
  59. wc_get_template_part( 'content', 'product' );
  60. elseif ( is_search() ) :
  61. get_template_part( 'components/post/content', 'search' );
  62. else :
  63. get_template_part( 'components/post/content', get_post_format() );
  64. endif;
  65. }
  66. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  67. woocommerce_product_loop_end();
  68. karuna_woocommerce_product_columns_wrapper_close();
  69. }
  70. }
  71. /*
  72. * Only display social menu if function exists
  73. */
  74. function karuna_social_menu() {
  75. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  76. return;
  77. } else {
  78. jetpack_social_menu();
  79. }
  80. }
  81. /**
  82. * Return early if Author Bio is not available.
  83. */
  84. function karuna_author_bio() {
  85. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  86. return;
  87. } else {
  88. jetpack_author_bio();
  89. }
  90. }
  91. /**
  92. * Author Bio Avatar Size.
  93. */
  94. function karuna_author_bio_avatar_size() {
  95. return 60;
  96. }
  97. add_filter( 'jetpack_author_bio_avatar_size', 'karuna_author_bio_avatar_size' );
  98. /**
  99. * Show/Hide Featured Image on single posts view outside of the loop.
  100. */
  101. function karuna_jetpack_featured_image_display() {
  102. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  103. return true;
  104. } else {
  105. $options = get_theme_support( 'jetpack-content-options' );
  106. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  107. $settings = array(
  108. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  109. 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
  110. );
  111. $settings = array_merge( $settings, array(
  112. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  113. 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
  114. ) );
  115. if ( ( ! $settings['post-option'] && is_single() )
  116. || ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
  117. return false;
  118. } else {
  119. return true;
  120. }
  121. }
  122. }
  123. /**
  124. * Custom function to check for a post thumbnail;
  125. * If Jetpack is not available, fall back to has_post_thumbnail()
  126. */
  127. function karuna_has_post_thumbnail( $post = null ) {
  128. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  129. return jetpack_has_featured_image( $post );
  130. } else {
  131. return has_post_thumbnail( $post );
  132. }
  133. }