jetpack.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if ( 0 !== count( libretto_get_active_sidebars() ) ) :
  42. return true;
  43. else :
  44. return false;
  45. endif;
  46. }
  47. add_filter( 'infinite_scroll_has_footer_widgets', 'libretto_has_footer_widgets' );
  48. /**
  49. * Enable support for site logo
  50. */
  51. add_theme_support( 'site-logo', array(
  52. 'size' => 'libretto-logo',
  53. ) );
  54. /**
  55. * Remove styles for contact form
  56. */
  57. function libretto_remove_jetpack_stylesheets() {
  58. wp_deregister_style( 'grunion.css' );
  59. }
  60. add_action( 'wp_enqueue_scripts', 'libretto_remove_jetpack_stylesheets' );
  61. /**
  62. * Show/Hide Featured Image on single posts view outside of the loop.
  63. */
  64. function libretto_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 function to check for a post thumbnail;
  88. * If Jetpack is not available, fall back to has_post_thumbnail()
  89. */
  90. function libretto_has_post_thumbnail( $post = null ) {
  91. if ( function_exists( 'jetpack_has_featured_image' ) ) {
  92. return jetpack_has_featured_image( $post );
  93. } else {
  94. return has_post_thumbnail( $post );
  95. }
  96. }
  97. /**
  98. * Custom function to get the URL of a post thumbnail;
  99. * If Jetpack is not available, fall back to wp_get_attachment_image_src()
  100. */
  101. function libretto_get_attachment_image_src( $post_id, $post_thumbnail_id, $size ) {
  102. if ( function_exists( 'jetpack_featured_images_fallback_get_image_src' ) ) {
  103. return jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size );
  104. } else {
  105. $attachment = wp_get_attachment_image_src( $post_thumbnail_id, $size ); // Attachment array
  106. $url = $attachment[0]; // Attachment URL
  107. return $url;
  108. }
  109. }