jetpack.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package TextBook
  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 textbook_jetpack_setup() {
  16. // Add theme support for core logo
  17. add_theme_support( 'custom-logo', array(
  18. 'height' => 100,
  19. 'width' => 200,
  20. 'flex-width' => true,
  21. ) );
  22. add_theme_support( 'featured-content', array(
  23. 'filter' => 'textbook_get_featured_content',
  24. 'max_posts' => 4,
  25. 'post_types' => array( 'post', 'page', 'jetpack-portfolio' ),
  26. ) );
  27. // Add theme support for Infinite Scroll.
  28. add_theme_support( 'infinite-scroll', array(
  29. 'container' => 'main',
  30. 'wrapper' => false,
  31. 'type' => 'click',
  32. 'render' => 'textbook_infinite_scroll_render',
  33. 'footer' => 'page',
  34. ) );
  35. // Add theme support for Responsive Videos.
  36. add_theme_support( 'jetpack-responsive-videos' );
  37. // Add theme support for Social Menus
  38. add_theme_support( 'jetpack-social-menu', 'svg' );
  39. // Add JetPack Content Options
  40. add_theme_support( 'jetpack-content-options', array(
  41. 'blog-display' => false,
  42. 'author-bio' => true,
  43. 'post-details' => array(
  44. 'stylesheet' => 'textbook-style',
  45. 'date' => '.posted-on, .entry-meta .meta-sep',
  46. 'categories' => '.cat-links',
  47. 'tags' => false,
  48. ),
  49. ) );
  50. // Add theme support for testimonials
  51. add_theme_support( 'jetpack-testimonial' );
  52. }
  53. add_action( 'after_setup_theme', 'textbook_jetpack_setup' );
  54. /*
  55. * Custom render function for Infinite Scroll.
  56. */
  57. function textbook_infinite_scroll_render() {
  58. while ( have_posts() ) {
  59. the_post();
  60. get_template_part( 'components/post/content', 'card' );
  61. }
  62. }
  63. /**
  64. * Force Infinite Scroll on Search result pages
  65. */
  66. function textbook_is_search_support() {
  67. $supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_archive() || is_search() );
  68. return $supported;
  69. }
  70. add_filter( 'infinite_scroll_archive_supported', 'textbook_is_search_support' );
  71. /*
  72. * Site logo display function.
  73. */
  74. function textbook_the_custom_logo() {
  75. if ( function_exists( 'the_custom_logo' ) ) {
  76. the_custom_logo();
  77. }
  78. }
  79. /*
  80. * Social menu display function.
  81. */
  82. function textbook_social_menu() {
  83. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  84. return;
  85. } else {
  86. jetpack_social_menu();
  87. }
  88. }
  89. /**
  90. * Helper function to check for Featured Content
  91. *
  92. * @param (integer)
  93. * @return (boolean) true/false
  94. */
  95. function textbook_has_featured_posts( $minimum = 1 ) {
  96. if ( is_paged() )
  97. return false;
  98. $minimum = absint( $minimum );
  99. $featured_content = apply_filters( 'textbook_get_featured_content', array() );
  100. if ( ! is_array( $featured_content ) )
  101. return false;
  102. if ( $minimum > count( $featured_content ) )
  103. return false;
  104. return true;
  105. }
  106. /**
  107. * Getter function for Featured Content
  108. *
  109. * @return (string) The value of the filter defined in add_theme_support( 'featured-content' ).
  110. */
  111. function textbook_get_featured_content() {
  112. return apply_filters( 'textbook_get_featured_content', array() );
  113. }
  114. function textbook_get_featured_content_ids() {
  115. // Get array of cached results if they exist.
  116. $featured_ids = get_transient( 'featured_content_ids' );
  117. if ( false === $featured_ids ) {
  118. $featured_options = get_option( 'featured-content', FALSE );
  119. $featured_tag_name = $featured_options[ 'tag-name' ];
  120. $term = get_term_by( 'name', $featured_tag_name, 'post_tag' );
  121. if ( $term ) {
  122. // Query for featured posts.
  123. $featured_ids = get_posts( array(
  124. 'fields' => 'ids',
  125. 'numberposts' => $max_posts,
  126. 'post_type' => array( 'post', 'page', 'jetpack-portfolio' ),
  127. 'suppress_filters' => false,
  128. 'tax_query' => array(
  129. array(
  130. 'field' => 'term_id',
  131. 'taxonomy' => 'post_tag',
  132. 'terms' => $term->term_id,
  133. ),
  134. ),
  135. )
  136. );
  137. }
  138. set_transient( 'featured_content_ids', $featured_ids );
  139. }
  140. // Ensure correct format before return.
  141. return array_map( 'absint', $featured_ids );
  142. }
  143. /*
  144. * Add breadcrumbs to a page (not blog post)
  145. */
  146. function textbook_breadcrumbs() {
  147. if ( function_exists( 'jetpack_breadcrumbs' ) ) {
  148. jetpack_breadcrumbs();
  149. }
  150. }
  151. /**
  152. * Return early if Author Bio is not available.
  153. */
  154. function textbook_author_bio() {
  155. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  156. return;
  157. } else {
  158. jetpack_author_bio();
  159. }
  160. }
  161. /**
  162. * Author Bio Avatar Size.
  163. */
  164. function textbook_author_bio_avatar_size() {
  165. return 48; // in px
  166. }
  167. add_filter( 'jetpack_author_bio_avatar_size', 'textbook_author_bio_avatar_size' );