jetpack.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: http://jetpack.com/
  5. *
  6. * @package Libretto
  7. */
  8. function libretto_jetpack_setup() {
  9. // Add theme support for Infinite Scroll.
  10. add_theme_support( 'infinite-scroll', array(
  11. 'container' => 'content',
  12. 'footer' => 'colophon',
  13. 'footer_widgets' => array( 'libretto_has_footer_widgets' ),
  14. ) );
  15. // Add theme support for Responsive Videos.
  16. add_theme_support( 'jetpack-responsive-videos' );
  17. // Add theme support for Content Options.
  18. add_theme_support( 'jetpack-content-options', array(
  19. 'blog-display' => 'content',
  20. 'post-details' => array(
  21. 'stylesheet' => 'libretto-style',
  22. 'date' => '.posted-on',
  23. 'categories' => '.cat-links',
  24. 'tags' => '.tags-links',
  25. 'author' => '.byline',
  26. ),
  27. 'featured-images' => array(
  28. 'archive' => true,
  29. 'post' => true,
  30. 'page' => true,
  31. 'fallback' => true,
  32. 'fallback-default' => false,
  33. ),
  34. ) );
  35. }
  36. add_action( 'after_setup_theme', 'libretto_jetpack_setup' );
  37. /**
  38. * If the social menu or the sidebar widgets are active, switch to click-to-scroll
  39. */
  40. function libretto_has_footer_widgets() {
  41. $l = libretto_get_active_sidebars();
  42. $l_count = is_countable( $l ) ? count( $l ) : 0;
  43. if ( 0 !== $l_count ) :
  44. return true;
  45. else :
  46. return false;
  47. endif;
  48. }
  49. add_filter( 'infinite_scroll_has_footer_widgets', 'libretto_has_footer_widgets' );
  50. /**
  51. * Enable support for site logo
  52. */
  53. add_theme_support( 'site-logo', array(
  54. 'size' => 'libretto-logo',
  55. ) );
  56. /**
  57. * Remove styles for contact form
  58. */
  59. function libretto_remove_jetpack_stylesheets() {
  60. wp_deregister_style( 'grunion.css' );
  61. }
  62. add_action( 'wp_enqueue_scripts', 'libretto_remove_jetpack_stylesheets' );
  63. /**
  64. * Show/Hide Featured Image on single posts view outside of the loop.
  65. */
  66. function libretto_jetpack_featured_image_display() {
  67. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
  68. return true;
  69. } else {
  70. $options = get_theme_support( 'jetpack-content-options' );
  71. $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
  72. $settings = array(
  73. 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1,
  74. 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1,
  75. );
  76. $settings = array_merge( $settings, array(
  77. 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ),
  78. 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ),
  79. ) );
  80. if ( ( ! $settings['post-option'] && is_single() )
  81. || ( ! $settings['page-option'] && is_singular() && is_page() ) ) {
  82. return false;
  83. } else {
  84. return true;
  85. }
  86. }
  87. }
  88. /**
  89. * Custom function to check for a post thumbnail;
  90. * If Jetpack is not available, fall back to has_post_thumbnail()
  91. */
  92. function libretto_has_post_thumbnail( $post = null ) {
  93. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  94. return jetpack_has_featured_image( $post );
  95. } else {
  96. return has_post_thumbnail( $post );
  97. }
  98. }
  99. /**
  100. * Custom function to get the URL of a post thumbnail;
  101. * If Jetpack is not available, fall back to wp_get_attachment_image_src()
  102. */
  103. function libretto_get_attachment_image_src( $post_id, $post_thumbnail_id, $size ) {
  104. if ( function_exists( 'jetpack_featured_images_fallback_get_image_src' ) ) {
  105. return jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size );
  106. } else {
  107. $attachment = wp_get_attachment_image_src( $post_thumbnail_id, $size ); // Attachment array
  108. $url = $attachment[0]; // Attachment URL
  109. return $url;
  110. }
  111. }