jetpack.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package Shoreditch
  8. */
  9. /**
  10. * Jetpack setup function.
  11. *
  12. * See: https://jetpack.me/support/infinite-scroll/
  13. * See: https://jetpack.me/support/featured-content/
  14. * See: https://jetpack.me/support/responsive-videos/
  15. * See: https://jetpack.me/support/social-menu/
  16. * See: https://jetpack.me/support/custom-content-types/#testimonials
  17. */
  18. function shoreditch_jetpack_setup() {
  19. // Add theme support for Infinite Scroll.
  20. add_theme_support( 'infinite-scroll', array(
  21. 'container' => 'main',
  22. 'render' => 'shoreditch_infinite_scroll_render',
  23. 'footer' => 'page',
  24. 'footer_widgets' => array(
  25. 'sidebar-2',
  26. 'sidebar-3',
  27. ),
  28. ) );
  29. //Add theme support for Featured Content.
  30. add_theme_support( 'featured-content', array(
  31. 'filter' => 'shoreditch_get_featured_posts',
  32. 'description' => esc_html__( 'The featured content section displays on the index page bellow the header.', 'shoreditch' ),
  33. 'max_posts' => 6,
  34. 'post_types' => array( 'post', 'page' ),
  35. ) );
  36. // Add theme support for Responsive Videos.
  37. add_theme_support( 'jetpack-responsive-videos' );
  38. // Add theme support for Social Menu.
  39. add_theme_support( 'jetpack-social-menu' );
  40. // Add theme support for Testimonials.
  41. add_theme_support( 'jetpack-testimonial' );
  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' => 'shoreditch-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. 'fallback' => true,
  58. 'fallback-default' => false,
  59. ),
  60. ) );
  61. }
  62. add_action( 'after_setup_theme', 'shoreditch_jetpack_setup' );
  63. /**
  64. * Custom render function for Infinite Scroll.
  65. */
  66. function shoreditch_infinite_scroll_render() {
  67. if ( class_exists( 'WooCommerce' ) && ( shoreditch_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  68. shoreditch_woocommerce_product_columns_wrapper();
  69. woocommerce_product_loop_start();
  70. }
  71. while ( have_posts() ) {
  72. the_post();
  73. if ( is_search() ) {
  74. get_template_part( 'template-parts/content', 'search' );
  75. } else if ( class_exists( 'WooCommerce' ) && ( shoreditch_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  76. wc_get_template_part( 'content', 'product' );
  77. } else if ( is_post_type_archive( 'jetpack-testimonial' ) ) {
  78. get_template_part( 'template-parts/content', 'testimonial' );
  79. } else {
  80. get_template_part( 'template-parts/content', get_post_format() );
  81. }
  82. }
  83. if ( class_exists( 'WooCommerce' ) && ( shoreditch_woocommerce_is_shop_page() || is_product_taxonomy() || is_product_category() || is_product_tag() ) ) {
  84. woocommerce_product_loop_end();
  85. shoreditch_woocommerce_product_columns_wrapper_close();
  86. }
  87. }
  88. /**
  89. * Featured Posts.
  90. */
  91. function shoreditch_has_multiple_featured_posts() {
  92. $featured_posts = apply_filters( 'shoreditch_get_featured_posts', array() );
  93. if ( is_array( $featured_posts ) && 1 < count( $featured_posts ) ) {
  94. return true;
  95. }
  96. return false;
  97. }
  98. function shoreditch_get_featured_posts() {
  99. return apply_filters( 'shoreditch_get_featured_posts', false );
  100. }
  101. /**
  102. * Return early if Social Menu is not available.
  103. */
  104. function shoreditch_social_menu() {
  105. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  106. return;
  107. } else {
  108. jetpack_social_menu();
  109. }
  110. }
  111. /**
  112. * Testimonials Title.
  113. */
  114. function shoreditch_testimonials_title( $before = '', $after = '' ) {
  115. $jetpack_options = get_theme_mod( 'jetpack_testimonials' );
  116. $title = esc_html__( 'Testimonials', 'shoreditch' );
  117. if ( isset( $jetpack_options['page-title'] ) && '' != $jetpack_options['page-title'] ) {
  118. $title = esc_html( $jetpack_options['page-title'] );
  119. }
  120. echo $before . $title . $after;
  121. }
  122. /**
  123. * Testimonials Content.
  124. */
  125. function shoreditch_testimonials_content( $before = '', $after = '' ) {
  126. $jetpack_options = get_theme_mod( 'jetpack_testimonials' );
  127. if ( isset( $jetpack_options['page-content'] ) && '' != $jetpack_options['page-content'] ) {
  128. $content = convert_chars( convert_smilies( wptexturize( wp_kses_post( $jetpack_options['page-content'] ) ) ) );
  129. echo $before . $content . $after;
  130. }
  131. }
  132. /**
  133. * Testimonials Featured Image.
  134. */
  135. function shoreditch_testimonials_image() {
  136. $jetpack_options = get_theme_mod( 'jetpack_testimonials' );
  137. if ( isset( $jetpack_options['featured-image'] ) && '' != $jetpack_options['featured-image'] ) {
  138. $image = wp_get_attachment_image_src( (int)$jetpack_options['featured-image'], 'post-thumbnail' );
  139. printf( ' style="background-image: url(\'%s\');"', esc_url( $image[0] ) );
  140. }
  141. }
  142. /**
  143. * Return early if Author Bio is not available.
  144. */
  145. function shoreditch_author_bio() {
  146. if ( ! function_exists( 'jetpack_author_bio' ) ) {
  147. get_template_part( 'template-parts/content', 'author' );
  148. } else {
  149. jetpack_author_bio();
  150. }
  151. }
  152. /**
  153. * Author Bio Avatar Size.
  154. */
  155. function shoreditch_author_bio_avatar_size() {
  156. return 60;
  157. }
  158. add_filter( 'jetpack_author_bio_avatar_size', 'shoreditch_author_bio_avatar_size' );
  159. /**
  160. * Load Jetpack scripts.
  161. */
  162. function shoreditch_jetpack_scripts() {
  163. if ( is_home() && ! is_paged() && false !== shoreditch_get_featured_posts() ) {
  164. wp_register_script( 'jquery-flexslider', get_template_directory_uri() . '/js/jquery.flexslider.js', array( 'jquery' ), '2.6.0', true );
  165. wp_enqueue_script( 'shoreditch-featured-content', get_template_directory_uri() . '/js/featured-content.js', array( 'jquery-flexslider' ), '20160411', true );
  166. }
  167. }
  168. add_action( 'wp_enqueue_scripts', 'shoreditch_jetpack_scripts' );
  169. /**
  170. * Hide Featured Image on single posts view outside of the loop.
  171. */
  172. function shoreditch_jetpack_featured_image_post() {
  173. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  174. return true;
  175. } else {
  176. $options = get_theme_support( 'jetpack-content-options' );
  177. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  178. $settings = array(
  179. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  180. );
  181. $settings = array_merge( $settings, array(
  182. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  183. ) );
  184. if ( ! $settings['post-option'] ) {
  185. return false;
  186. } else {
  187. return true;
  188. }
  189. }
  190. }
  191. /**
  192. * Custom function to check for a post thumbnail;
  193. * If Jetpack is not available, fall back to has_post_thumbnail()
  194. */
  195. function shoreditch_has_post_thumbnail( $post = null ) {
  196. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  197. return jetpack_has_featured_image( $post );
  198. } else {
  199. return has_post_thumbnail( $post );
  200. }
  201. }
  202. /**
  203. * Custom function to get the URL of a post thumbnail;
  204. * If Jetpack is not available, fall back to wp_get_attachment_image_src()
  205. */
  206. function shoreditch_get_attachment_image_src( $post_id, $post_thumbnail_id, $size ) {
  207. if ( function_exists( 'jetpack_featured_images_fallback_get_image_src' ) ) {
  208. return jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size );
  209. } else {
  210. $attachment = wp_get_attachment_image_src( $post_thumbnail_id, $size ); // Attachment array
  211. $url = $attachment[0]; // Attachment URL
  212. return $url;
  213. }
  214. }