jetpack.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: https://jetpack.me/
  5. *
  6. * @package Button 2
  7. */
  8. /**
  9. * Add theme support for Infinite Scroll.
  10. * See: https://jetpack.me/support/infinite-scroll/
  11. *
  12. * @since button 1.0
  13. */
  14. function button_2_jetpack_setup() {
  15. add_theme_support( 'infinite-scroll', array(
  16. 'container' => 'main',
  17. 'render' => 'button_2_infinite_scroll_render',
  18. 'footer' => 'page',
  19. ) );
  20. // Add theme support for Social Menu.
  21. add_theme_support( 'jetpack-social-menu', 'svg' );
  22. add_theme_support( 'jetpack-content-options', array(
  23. 'blog-display' => 'content',
  24. 'author-bio' => true,
  25. 'post-details' => array(
  26. 'stylesheet' => 'button-2-style',
  27. 'date' => '.posted-on',
  28. 'categories' => '.cat-links',
  29. 'tags' => '.tags-links',
  30. 'author' => '.byline',
  31. ),
  32. 'featured-images' => array(
  33. 'archive' => true,
  34. 'post' => true,
  35. 'post-default' => false,
  36. 'page' => true,
  37. 'page-default' => false,
  38. 'fallback' => true,
  39. 'fallback-default' => false,
  40. ),
  41. ) );
  42. add_theme_support( 'jetpack-responsive-videos' );
  43. } // end function button_2_jetpack_setup
  44. add_action( 'after_setup_theme', 'button_2_jetpack_setup' );
  45. // Turn off infinite scroll if mobile + sidebar, or if social menu is active
  46. if ( function_exists( 'jetpack_is_mobile' ) && ! function_exists( 'button_2_has_footer_widgets' ) ) {
  47. function button_2_has_footer_widgets() {
  48. if ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) || ( ( jetpack_is_mobile( '', true ) && is_active_sidebar( 'sidebar-1' ) ) ) )
  49. return true;
  50. return false;
  51. }
  52. } //endif
  53. add_filter( 'infinite_scroll_has_footer_widgets', 'button_2_has_footer_widgets' );
  54. /**
  55. * Custom render function for Infinite Scroll.
  56. *
  57. * @since button 1.0
  58. */
  59. function button_2_infinite_scroll_render() {
  60. if ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  61. button_2_woocommerce_product_columns_wrapper();
  62. woocommerce_product_loop_start();
  63. }
  64. while ( have_posts() ) {
  65. the_post();
  66. if ( is_search() ) :
  67. get_template_part( 'components/content', 'search' );
  68. elseif ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) :
  69. wc_get_template_part( 'content', 'product' );
  70. else :
  71. get_template_part( 'components/content', get_post_format() );
  72. endif;
  73. }
  74. if ( class_exists( 'WooCommerce' ) && ( button_2_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  75. woocommerce_product_loop_end();
  76. button_2_woocommerce_product_columns_wrapper_close();
  77. }
  78. } // end function button_2_infinite_scroll_render
  79. /**
  80. * Return early if Social Menu is not available.
  81. */
  82. function button_2_social_menu() {
  83. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  84. return;
  85. } else {
  86. jetpack_social_menu();
  87. }
  88. }
  89. /**
  90. * Return early if Author Bio is not available.
  91. */
  92. function button_2_author_bio() {
  93. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  94. get_template_part( 'components/content', 'author' );
  95. } else {
  96. jetpack_author_bio();
  97. }
  98. }
  99. /**
  100. * Author Bio Avatar Size.
  101. */
  102. function button_2_author_bio_avatar_size() {
  103. return 80;
  104. }
  105. add_filter( 'jetpack_author_bio_avatar_size', 'button_2_author_bio_avatar_size' );
  106. /**
  107. * Load Jetpack sharing buttons and likes.
  108. *
  109. * @since button 1.0
  110. */
  111. function button_2_post_flair() {
  112. // Sharing buttons
  113. if ( function_exists( 'sharing_display' ) ) {
  114. sharing_display( '', true );
  115. }
  116. // Likes
  117. if ( class_exists( 'Jetpack_Likes' ) ) {
  118. $custom_likes = new Jetpack_Likes;
  119. echo $custom_likes->post_likes( '' );
  120. }
  121. }
  122. /**
  123. * Custom function to check for a post thumbnail;
  124. * If Jetpack is not available, fall back to has_post_thumbnail()
  125. */
  126. function button_2_has_post_thumbnail( $post = null ) {
  127. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  128. return jetpack_has_featured_image( $post );
  129. } else {
  130. return has_post_thumbnail( $post );
  131. }
  132. }