jetpack.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Jetpack Compatibility File.
  4. *
  5. * @link https://jetpack.me/
  6. *
  7. * @package Toujours
  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 toujours_jetpack_setup() {
  16. // Add theme support for Infinite Scroll.
  17. add_theme_support( 'infinite-scroll', array(
  18. 'container' => 'main',
  19. 'render' => 'toujours_infinite_scroll_render',
  20. 'footer' => 'page',
  21. ) );
  22. // Add theme support for Responsive Videos.
  23. add_theme_support( 'jetpack-responsive-videos' );
  24. //Site logo
  25. add_image_size( 'toujours-site-logo', 1200, 400 );
  26. add_theme_support( 'site-logo', array(
  27. 'header-text' => array(
  28. 'site-title',
  29. 'site-description',
  30. ),
  31. 'size' => 'toujours-site-logo',
  32. ) );
  33. //Featured content
  34. add_theme_support( 'featured-content' , array(
  35. 'featured_content_filter' => 'toujours_get_banner_posts',
  36. 'max_posts' => 8,
  37. 'post_types' => array( 'post' ),
  38. ) );
  39. // Social menu
  40. add_theme_support( 'jetpack-social-menu' );
  41. } // end function toujours_jetpack_setup
  42. add_action( 'after_setup_theme', 'toujours_jetpack_setup' );
  43. /**
  44. * Custom render function for Infinite Scroll.
  45. */
  46. function toujours_infinite_scroll_render() {
  47. while ( have_posts() ) {
  48. the_post();
  49. if ( is_search() ) :
  50. get_template_part( 'template-parts/content', 'search' );
  51. else :
  52. get_template_part( 'template-parts/content', get_post_format() );
  53. endif;
  54. }
  55. }
  56. /**
  57. * Getter function for Featured Content.
  58. * See http://jetpack.me/support/featured-content/
  59. */
  60. function toujours_get_banner_posts() {
  61. return apply_filters( 'toujours_get_banner_posts', array() );
  62. }
  63. /**
  64. * Check for minimum number of featured posts
  65. */
  66. function toujours_has_banner_posts( $minimum = 1 ) {
  67. if ( is_paged() ) {
  68. return false;
  69. }
  70. $minimum = absint( $minimum );
  71. $featured_posts = apply_filters( 'toujours_get_banner_posts', array() );
  72. if ( ! is_array( $featured_posts ) ) {
  73. return false;
  74. }
  75. if ( $minimum > count( $featured_posts ) ) {
  76. return false;
  77. }
  78. return true;
  79. }
  80. /**
  81. * If there is a social menu set, make IS click to scroll
  82. */
  83. if ( function_exists( 'jetpack_is_mobile' ) && ! function_exists( 'toujours_footer_widgets' ) ) :
  84. function toujours_footer_widgets() {
  85. if ( has_nav_menu( 'jetpack-social-menu' ) || is_active_sidebar( 'footer' ) || ( ( jetpack_is_mobile( '', true ) && is_active_sidebar( 'sidebar-1' ) ) ) ) {
  86. return true;
  87. }
  88. return;
  89. }
  90. endif;
  91. add_filter( 'infinite_scroll_has_footer_widgets', 'toujours_footer_widgets' );
  92. /**
  93. * Return early if Social Menu is not available.
  94. */
  95. function toujours_social_menu() {
  96. if ( ! function_exists( 'jetpack_social_menu' ) ) {
  97. return;
  98. } else {
  99. jetpack_social_menu();
  100. }
  101. }