jetpack.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: https://jetpack.me/
  5. *
  6. * @package Dyad
  7. */
  8. if ( ! function_exists( 'dyad_2_jetpack' ) ) {
  9. function dyad_2_jetpack() {
  10. //Responsive videos
  11. add_theme_support( 'jetpack-responsive-videos' );
  12. //Social Menu
  13. add_theme_support( 'jetpack-social-menu', 'svg' );
  14. //Featured content
  15. add_theme_support( 'featured-content' , array(
  16. 'featured_content_filter' => 'dyad_2_get_banner_posts',
  17. 'max_posts' => 6,
  18. 'post_types' => array( 'post' ),
  19. ) );
  20. //Infinite scroll
  21. add_theme_support( 'infinite-scroll', array(
  22. 'container' => 'posts',
  23. 'footer' => 'primary',
  24. 'footer_widgets' => array( 'sidebar-1'),
  25. 'render' => 'dyad_2_infinite_scroll_render',
  26. 'wrapper' => false,
  27. ) );
  28. //Content options
  29. add_theme_support( 'jetpack-content-options', array(
  30. 'author-bio' => true,
  31. 'author-bio-default' => false,
  32. 'post-details' => array(
  33. 'stylesheet' => 'dyad-2-style',
  34. 'date' => '.posted-on',
  35. 'categories' => '.cat-links',
  36. 'tags' => '.tags-links',
  37. 'author' => '.byline, .date-published-word',
  38. ),
  39. 'featured-images' => array(
  40. 'archive' => true,
  41. 'post' => true,
  42. 'page' => true,
  43. 'fallback' => true,
  44. ),
  45. ) );
  46. }
  47. } // /dyad_2_jetpack
  48. add_action( 'after_setup_theme', 'dyad_2_jetpack' );
  49. /**
  50. * Custom render function for Infinite Scroll.
  51. */
  52. function dyad_2_infinite_scroll_render() {
  53. if ( class_exists( 'WooCommerce' ) && ( dyad_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  54. dyad_2_woocommerce_product_columns_wrapper();
  55. woocommerce_product_loop_start();
  56. }
  57. while ( have_posts() ) {
  58. the_post();
  59. if ( class_exists( 'WooCommerce' ) && ( dyad_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
  60. wc_get_template_part( 'content', 'product' );
  61. else :
  62. get_template_part( 'template-parts/content', 'blocks' );
  63. endif;
  64. }
  65. if ( class_exists( 'WooCommerce' ) && ( dyad_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  66. woocommerce_product_loop_end();
  67. dyad_2_woocommerce_product_columns_wrapper_close();
  68. }
  69. } // end function dyad_2_infinite_scroll_render
  70. /**
  71. * Getter function for Featured Content.
  72. * See http://jetpack.me/support/featured-content/
  73. */
  74. function dyad_2_get_banner_posts() {
  75. return apply_filters( 'dyad_2_get_banner_posts', array() );
  76. }
  77. /**
  78. * Check for minimum number of featured posts
  79. */
  80. function dyad_2_has_banner_posts( $minimum = 1 ) {
  81. $minimum = absint( $minimum );
  82. $featured_posts = apply_filters( 'dyad_2_get_banner_posts', array() );
  83. if ( ! is_array( $featured_posts ) ) {
  84. return false;
  85. }
  86. if ( $minimum > count( $featured_posts ) ) {
  87. return false;
  88. }
  89. return true;
  90. }
  91. /**
  92. * Return early if Social Menu is not available.
  93. */
  94. function dyad_2_social_menu() {
  95. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  96. return;
  97. } else {
  98. jetpack_social_menu();
  99. }
  100. }
  101. /**
  102. * Return early if Author Bio is not available.
  103. */
  104. function dyad_2_author_bio() {
  105. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  106. get_template_part( 'content', 'author' );
  107. } else {
  108. jetpack_author_bio();
  109. }
  110. }
  111. /**
  112. * Show/Hide Featured Image on single posts view outside of the loop.
  113. */
  114. function dyad_2_jetpack_featured_image_display() {
  115. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  116. return true;
  117. } else {
  118. $options = get_theme_support( 'jetpack-content-options' );
  119. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  120. $settings = array(
  121. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  122. 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
  123. );
  124. $settings = array_merge( $settings, array(
  125. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  126. 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
  127. ) );
  128. if ( ( ! $settings['post-option'] && is_single() )
  129. || ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
  130. return false;
  131. } else {
  132. return true;
  133. }
  134. }
  135. }
  136. /**
  137. * Custom function to check for a post thumbnail;
  138. * If Jetpack is not available, fall back to has_post_thumbnail()
  139. */
  140. function dyad_2_has_post_thumbnail( $post = null ) {
  141. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  142. return jetpack_has_featured_image( $post );
  143. } else {
  144. return has_post_thumbnail( $post );
  145. }
  146. }
  147. /**
  148. * Custom function to get the URL of a post thumbnail;
  149. * If Jetpack is not available, fall back to wp_get_attachment_image_src()
  150. */
  151. function dyad_2_get_attachment_image_src( $post_id, $post_thumbnail_id, $size ) {
  152. if ( function_exists( 'jetpack_featured_images_fallback_get_image_src' ) ) {
  153. return jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size );
  154. } else {
  155. $attachment = wp_get_attachment_image_src( $post_thumbnail_id, $size ); // Attachment array
  156. $url = $attachment[0]; // Attachment URL
  157. return $url;
  158. }
  159. }