jetpack.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package Dara
  8. */
  9. /**
  10. * Jetpack setup function.
  11. *
  12. * See: https://jetpack.me/support/infinite-scroll/
  13. * See: https://jetpack.me/support/responsive-videos/
  14. */
  15. function dara_jetpack_setup() {
  16. //The IS container changes depending on the archive type
  17. if ( is_post_type_archive( 'jetpack-testimonial' ) ) {
  18. $container = 'testimonials';
  19. }
  20. else {
  21. $container = 'main';
  22. }
  23. // Add theme support for Infinite Scroll.
  24. add_theme_support( 'infinite-scroll', array(
  25. 'container' => $container,
  26. 'render' => 'dara_infinite_scroll_render',
  27. 'footer' => 'page',
  28. ) );
  29. add_theme_support( 'featured-content', array(
  30. 'filter' => 'dara_get_featured_posts',
  31. 'max_posts' => 10,
  32. 'post_types' => array( 'post', 'page', 'jetpack-portfolio' ),
  33. ) );
  34. // Add theme support for Responsive Videos.
  35. add_theme_support( 'jetpack-responsive-videos' );
  36. // Add theme support for Social Menus
  37. add_theme_support( 'jetpack-social-menu', 'svg' );
  38. // Add theme support for Jetpack Testimonials
  39. add_theme_support( 'jetpack-testimonial' );
  40. // Add theme support for Content Options.
  41. add_theme_support( 'jetpack-content-options', array(
  42. 'blog-display' => 'content',
  43. 'author-bio' => true,
  44. 'post-details' => array(
  45. 'stylesheet' => 'dara-style',
  46. 'date' => '.posted-on',
  47. 'categories' => '.cat-links',
  48. 'tags' => '.tags-links',
  49. 'author' => '.byline',
  50. ),
  51. 'featured-images' => array(
  52. 'archive' => true, // enable or not the featured image check for archive pages: true or false
  53. 'post' => true, // enable or not the featured image check for single posts: true or false
  54. 'page' => true, // enable or not the featured image check for single pages: true or false
  55. 'fallback' => true,
  56. 'fallback-default' => false,
  57. ),
  58. ) );
  59. }
  60. add_action( 'after_setup_theme', 'dara_jetpack_setup' );
  61. /**
  62. * Footer widgets Callback for Infinite Scroll
  63. */
  64. if ( function_exists( 'jetpack_is_mobile' ) && class_exists( 'Jetpack_User_Agent_Info' ) ) {
  65. function dara_has_footer_widgets() {
  66. if ( ( Jetpack_User_Agent_Info::is_ipad() && is_active_sidebar( 'sidebar-1' ) ) || ( jetpack_is_mobile( '', true ) && is_active_sidebar( 'sidebar-1' ) ) ) {
  67. return true;
  68. }
  69. elseif ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) ) {
  70. return true;
  71. }
  72. return false;
  73. }
  74. add_filter( 'infinite_scroll_has_footer_widgets', 'dara_has_footer_widgets' );
  75. }
  76. /**
  77. * Custom render function for Infinite Scroll.
  78. */
  79. function dara_infinite_scroll_render() {
  80. if ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  81. dara_woocommerce_product_columns_wrapper();
  82. woocommerce_product_loop_start();
  83. }
  84. while ( have_posts() ) {
  85. the_post();
  86. if ( is_search() ) :
  87. get_template_part( 'components/post/content', 'search' );
  88. elseif ( is_post_type_archive( 'jetpack-testimonial' ) ) :
  89. get_template_part( 'components/testimonials/content', 'testimonial' );
  90. elseif ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
  91. wc_get_template_part( 'content', 'product' );
  92. else :
  93. get_template_part( 'components/post/content', get_post_format() );
  94. endif;
  95. }
  96. if ( class_exists( 'WooCommerce' ) && ( dara_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  97. woocommerce_product_loop_end();
  98. dara_woocommerce_product_columns_wrapper_close();
  99. }
  100. }
  101. function dara_get_featured_posts() {
  102. return apply_filters( 'dara_get_featured_posts', array() );
  103. }
  104. function dara_has_featured_posts( $minimum = 1 ) {
  105. if ( is_paged() )
  106. return false;
  107. $minimum = absint( $minimum );
  108. $featured_posts = apply_filters( 'dara_get_featured_posts', array() );
  109. if ( ! is_array( $featured_posts ) )
  110. return false;
  111. if ( $minimum > count( $featured_posts ) )
  112. return false;
  113. return true;
  114. }
  115. /**
  116. * Return early if Author Bio is not available.
  117. */
  118. function dara_author_bio() {
  119. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  120. get_template_part( 'components/post/content', 'author' );
  121. } else {
  122. jetpack_author_bio();
  123. }
  124. }
  125. /**
  126. * Author Bio Avatar Size.
  127. */
  128. function dara_author_bio_avatar_size() {
  129. return 90;
  130. }
  131. add_filter( 'jetpack_author_bio_avatar_size', 'dara_author_bio_avatar_size' );
  132. function dara_social_menu() {
  133. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  134. return;
  135. } else {
  136. jetpack_social_menu();
  137. }
  138. }
  139. /**
  140. * Custom function to check for a post thumbnail;
  141. * If Jetpack is not available, fall back to has_post_thumbnail()
  142. */
  143. function dara_has_post_thumbnail( $post = null ) {
  144. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  145. return jetpack_has_featured_image( $post );
  146. } else {
  147. return has_post_thumbnail( $post );
  148. }
  149. }