jetpack.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package Lodestar
  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 lodestar_jetpack_setup() {
  16. // Add theme support for Infinite Scroll.
  17. add_theme_support( 'infinite-scroll', array(
  18. 'container' => 'main',
  19. 'render' => 'lodestar_infinite_scroll_render',
  20. 'footer' => 'page',
  21. 'wrapper' => false,
  22. 'footer_widgets' => array( 'sidebar-2', 'sidebar-3', 'sidebar-4' ),
  23. ) );
  24. // Add theme support for Responsive Videos.
  25. add_theme_support( 'jetpack-responsive-videos' );
  26. // Add theme support for Social Menus
  27. add_theme_support( 'jetpack-social-menu', 'svg' );
  28. // Add theme support for testimonials
  29. add_theme_support( 'jetpack-testimonial' );
  30. /*
  31. * Adding theme support for Jetpack Portfolio CPT.
  32. * Not essential to add this but this does a few nice things.
  33. * 1. Turns the CPT on when the theme is activated.
  34. * 2. Displays an admin notice if the option is turned off, but the theme is activated.
  35. * 3. When the theme is switched away, if no CPTs are populated, it turns it back off.
  36. */
  37. add_theme_support( 'jetpack-portfolio', array(
  38. 'title' => true,
  39. 'content' => true,
  40. 'featured-image' => true,
  41. ) );
  42. //Add theme support for Content Options.
  43. add_theme_support( 'jetpack-content-options', array(
  44. 'blog-display' => 'content',
  45. 'author-bio' => true,
  46. 'post-details' => array(
  47. 'stylesheet' => 'lodestar-style',
  48. 'date' => '.posted-on',
  49. 'categories' => '.cat-links',
  50. 'tags' => '.tags-links',
  51. 'author' => '.byline',
  52. ),
  53. 'featured-images' => array(
  54. 'archive' => true,
  55. 'post' => true,
  56. 'page' => true,
  57. ),
  58. ) );
  59. }
  60. add_action( 'after_setup_theme', 'lodestar_jetpack_setup' );
  61. /**
  62. * Show/Hide Featured Image outside of the loop.
  63. */
  64. function lodestar_jetpack_featured_image_display() {
  65. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  66. return true;
  67. } else {
  68. $options = get_theme_support( 'jetpack-content-options' );
  69. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  70. $settings = array(
  71. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  72. 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
  73. );
  74. $settings = array_merge( $settings, array(
  75. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  76. 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
  77. ) );
  78. if ( ( ! $settings['post-option'] && is_single() )
  79. || ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
  80. return false;
  81. } else {
  82. return true;
  83. }
  84. }
  85. }
  86. /**
  87. * Custom render function for Infinite Scroll.
  88. */
  89. function lodestar_infinite_scroll_render() {
  90. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  91. lodestar_woocommerce_product_columns_wrapper();
  92. woocommerce_product_loop_start();
  93. }
  94. while ( have_posts() ) {
  95. the_post();
  96. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  97. wc_get_template_part( 'content', 'product' );
  98. } else if ( is_search() ) {
  99. get_template_part( 'components/post/content', 'search' );
  100. } else if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-tag' ) || is_tax( 'jetpack-portfolio-type' ) ) {
  101. get_template_part( 'components/features/portfolio/content', 'portfolio' );
  102. } else if ( is_post_type_archive( 'jetpack-testimonial' ) ) {
  103. get_template_part( 'components/features/testimonials/content', 'testimonials' );
  104. } else {
  105. get_template_part( 'components/post/content', get_post_format() );
  106. }
  107. }
  108. if ( class_exists( 'WooCommerce' ) && ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  109. woocommerce_product_loop_end();
  110. lodestar_woocommerce_product_columns_wrapper_close();
  111. }
  112. }
  113. /**
  114. * Return early if Social Menu is not available
  115. */
  116. function lodestar_social_menu() {
  117. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  118. return;
  119. } else {
  120. jetpack_social_menu();
  121. }
  122. }
  123. /**
  124. * Return early if Author Bio is not available.
  125. */
  126. function lodestar_author_bio() {
  127. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  128. return;
  129. } else {
  130. jetpack_author_bio();
  131. }
  132. }
  133. /**
  134. * Author Bio Avatar Size.
  135. */
  136. function lodestar_author_bio_avatar_size() {
  137. return 100;
  138. }
  139. add_filter( 'jetpack_author_bio_avatar_size', 'lodestar_author_bio_avatar_size' );
  140. /**
  141. * Portfolio Title.
  142. */
  143. function lodestar_portfolio_title( $before = '', $after = '' ) {
  144. $jetpack_portfolio_title = get_option( 'jetpack_portfolio_title' );
  145. $title = '';
  146. if ( is_post_type_archive( 'jetpack-portfolio' ) ) {
  147. if ( isset( $jetpack_portfolio_title ) && '' != $jetpack_portfolio_title ) {
  148. $title = esc_html( $jetpack_portfolio_title );
  149. } else {
  150. $title = post_type_archive_title( '', false );
  151. }
  152. } elseif ( is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  153. $title = single_term_title( '', false );
  154. }
  155. echo $before . $title . $after;
  156. }
  157. /**
  158. * Portfolio Content.
  159. */
  160. function lodestar_portfolio_content( $before = '', $after = '' ) {
  161. $jetpack_portfolio_content = get_option( 'jetpack_portfolio_content' );
  162. if ( is_tax() && get_the_archive_description() ) {
  163. echo $before . get_the_archive_description() . $after;
  164. } else if ( isset( $jetpack_portfolio_content ) && '' != $jetpack_portfolio_content ) {
  165. $content = convert_chars( convert_smilies( wptexturize( wp_kses_post( $jetpack_portfolio_content ) ) ) );
  166. echo $before . $content . $after;
  167. }
  168. }
  169. /**
  170. * Porfolio Archive Navigation
  171. */
  172. function lodestar_project_terms() {
  173. $terms = get_terms(
  174. 'jetpack-portfolio-type',
  175. array(
  176. 'number' => 20,
  177. 'orderby' => 'count',
  178. 'order' => 'DESC',
  179. )
  180. );
  181. // Highlight currently selected page.
  182. $class = 'current-type';
  183. // Get the term for the current page.
  184. $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  185. // We're on a project category page, and not the main portfolio page, so reset the class.
  186. if ( $current_term ) {
  187. $class = '';
  188. }
  189. // Make sure the term exists and has some results.
  190. if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) : ?>
  191. <div class="project-terms">
  192. <span class="screen-reader-text">
  193. <?php esc_html_e( 'Types:', 'lodestar' ); ?>
  194. </span>
  195. <ul>
  196. <li><a class="<?php echo esc_attr( $class ); ?> types-all" href="<?php echo esc_url( home_url( '/portfolio/' ) ); ?>"><?php esc_html_e( 'All', 'lodestar' ); ?></a></li>
  197. <?php
  198. foreach ( $terms as $t ) {
  199. $class = '';
  200. if ( $current_term && $current_term->term_id === (int) $t->term_id ) {
  201. $class = 'current-type';
  202. } ?>
  203. <li><a class="<?php echo esc_attr( $class ); ?>" data-get-typeid="gettypeid-<?php echo esc_attr( $t->term_id ); ?>" href="<?php echo esc_url( get_term_link( $t ) ); ?>"><?php echo esc_html( $t->name ); ?></a></li>
  204. <?php } ?>
  205. </ul>
  206. </div>
  207. <?php endif;
  208. }
  209. /**
  210. * Porfolio archive data attributes
  211. */
  212. function lodestar_portfolio_data() {
  213. $terms = get_the_terms( get_the_ID(), 'jetpack-portfolio-type' );
  214. if ( empty( $terms) ) {
  215. return;
  216. }
  217. $typeid[] = '';
  218. foreach ( $terms as $term ) {
  219. $typeid[] = 'typeid-' . $term->term_id;
  220. }
  221. return implode( " ", $typeid );
  222. }