jetpack.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package Affinity
  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 affinity_jetpack_setup() {
  16. // Add theme support for Infinite Scroll.
  17. add_theme_support( 'infinite-scroll', array(
  18. 'container' => 'main',
  19. 'render' => 'affinity_infinite_scroll_render',
  20. 'footer_widgets' => affinity_has_footer_widgets(),
  21. 'footer' => 'page',
  22. ) );
  23. // Add theme support for Responsive Videos.
  24. add_theme_support( 'jetpack-responsive-videos' );
  25. // Add theme support for Content Options.
  26. add_theme_support( 'jetpack-content-options', array(
  27. 'blog-display' => 'content',
  28. 'post-details' => array(
  29. 'stylesheet' => 'affinity-style',
  30. 'date' => '.posted-on',
  31. 'categories' => '.cat-links',
  32. 'tags' => '.tags-links',
  33. 'author' => '.byline',
  34. 'comment' => '.comments-link',
  35. ),
  36. 'featured-images' => array(
  37. 'archive' => true,
  38. 'post' => true,
  39. 'page' => true,
  40. 'fallback' => true,
  41. 'fallback-default' => false,
  42. ),
  43. ) );
  44. // Add theme support for Social Menus
  45. add_theme_support( 'jetpack-social-menu' );
  46. /*
  47. * Fall back to Jetpack Site Logo if no core custom logo exists
  48. *
  49. * @todo Remove after WP 4.7 release
  50. */
  51. if ( ! current_theme_supports( 'custom-logo' ) ) {
  52. add_image_size( 'affinity-logo', 800, 250 );
  53. add_theme_support( 'site-logo', array( 'size' => 'affinity-logo' ) );
  54. }
  55. }
  56. add_action( 'after_setup_theme', 'affinity_jetpack_setup' );
  57. /**
  58. * Custom render function for Infinite Scroll.
  59. */
  60. function affinity_infinite_scroll_render() {
  61. while ( have_posts() ) {
  62. the_post();
  63. if ( is_search() ) :
  64. get_template_part( 'components/post/content', 'search' );
  65. else :
  66. get_template_part( 'components/post/content', get_post_format() );
  67. endif;
  68. }
  69. }
  70. /**
  71. * Custom function to check for the presence of footer widgets or the social links menu
  72. */
  73. function affinity_has_footer_widgets() {
  74. if ( is_active_sidebar( 'footer-1' ) ||
  75. is_active_sidebar( 'footer-2' ) ||
  76. is_active_sidebar( 'footer-3' ) ||
  77. has_nav_menu( 'jetpack-social-menu' ) ) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. /*
  84. * Return early if no social menus are available
  85. */
  86. function affinity_social_menu() {
  87. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  88. return;
  89. } else {
  90. jetpack_social_menu();
  91. }
  92. }
  93. /**
  94. * Custom function to check for a post thumbnail;
  95. * If Jetpack is not available, fall back to has_post_thumbnail()
  96. */
  97. function affinity_has_post_thumbnail( $post = null ) {
  98. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  99. return jetpack_has_featured_image( $post );
  100. } else {
  101. return has_post_thumbnail( $post );
  102. }
  103. }
  104. /**
  105. * Show/Hide Featured Image on single posts view outside of the loop.
  106. */
  107. function affinity_jetpack_featured_image_display() {
  108. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  109. return true;
  110. } else {
  111. $options = get_theme_support( 'jetpack-content-options' );
  112. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  113. $settings = array(
  114. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  115. 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
  116. );
  117. $settings = array_merge( $settings, array(
  118. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  119. 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
  120. ) );
  121. if ( ( ! $settings['post-option'] && is_single() )
  122. || ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
  123. return false;
  124. } else {
  125. return true;
  126. }
  127. }
  128. }
  129. /**
  130. * Custom function to get the URL of a post thumbnail;
  131. * If Jetpack is not available, fall back to wp_get_attachment_image_src()
  132. */
  133. function affinity_get_attachment_image_src( $post_id, $post_thumbnail_id, $size ) {
  134. if ( function_exists( 'jetpack_featured_images_fallback_get_image_src' ) ) {
  135. return jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size );
  136. } else {
  137. $attachment = wp_get_attachment_image_src( $post_thumbnail_id, $size ); // Attachment array
  138. $url = $attachment[0]; // Attachment URL
  139. return $url;
  140. }
  141. }
  142. /**
  143. * Checks if Content Options: Blog display is set to 'excerpt' and returns true if it is
  144. */
  145. function affinity_content_options_show_excerpt() {
  146. $blog_display = get_option( 'jetpack_content_blog_display' );
  147. if ( 'excerpt' === $blog_display ) {
  148. return true;
  149. } else {
  150. return false;
  151. }
  152. }