jetpack.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: http://jetpack.me/
  5. *
  6. * @package Illustratr
  7. */
  8. function illustratr_jetpack_setup() {
  9. /**
  10. * Add theme support for Infinite Scroll.
  11. * See: http://jetpack.me/support/infinite-scroll/
  12. */
  13. add_theme_support( 'infinite-scroll', array(
  14. 'container' => 'main',
  15. 'footer' => 'page',
  16. 'footer_widgets' => array( 'sidebar-1', ),
  17. 'render' => 'illustratr_infinite_scroll_render',
  18. ) );
  19. /**
  20. * Add theme support for Portfolio Custom Post Type.
  21. */
  22. add_theme_support( 'jetpack-portfolio', array(
  23. 'title' => true,
  24. 'content' => true,
  25. 'featured-image' => true,
  26. ) );
  27. /**
  28. * Add theme support for Logo upload.
  29. */
  30. add_image_size( 'illustratr-logo', 400, 180 );
  31. add_theme_support( 'site-logo', array(
  32. 'size' => 'illustratr-logo'
  33. ) );
  34. }
  35. add_action( 'after_setup_theme', 'illustratr_jetpack_setup' );
  36. /**
  37. * Define the code that is used to render the posts added by Infinite Scroll.
  38. *
  39. * Includes the whole loop. Used to include the correct template part for the Portfolio CPT.
  40. */
  41. function illustratr_infinite_scroll_render() {
  42. while ( have_posts() ) {
  43. the_post();
  44. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  45. get_template_part( 'content', 'portfolio' );
  46. } else {
  47. get_template_part( 'content', get_post_format() );
  48. }
  49. }
  50. }
  51. /**
  52. * Return early if Site Logo is not available.
  53. */
  54. function illustratr_the_site_logo() {
  55. if ( ! function_exists( 'jetpack_the_site_logo' ) ) {
  56. return;
  57. } else {
  58. jetpack_the_site_logo();
  59. }
  60. }
  61. /**
  62. * Portfolio Title.
  63. */
  64. function illustratr_portfolio_title( $before = '', $after = '' ) {
  65. $jetpack_portfolio_title = get_option( 'jetpack_portfolio_title' );
  66. $title = '';
  67. if ( is_post_type_archive( 'jetpack-portfolio' ) ) {
  68. if ( isset( $jetpack_portfolio_title ) && '' != $jetpack_portfolio_title ) {
  69. $title = esc_html( $jetpack_portfolio_title );
  70. } else {
  71. $title = post_type_archive_title( '', false );
  72. }
  73. } elseif ( is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  74. $title = single_term_title( '', false );
  75. }
  76. echo $before . $title . $after;
  77. }
  78. /**
  79. * Portfolio Content.
  80. */
  81. function illustratr_portfolio_content( $before = '', $after = '' ) {
  82. $jetpack_portfolio_content = get_option( 'jetpack_portfolio_content' );
  83. if ( is_tax() && get_the_archive_description() ) {
  84. echo $before . get_the_archive_description() . $after;
  85. } else if ( isset( $jetpack_portfolio_content ) && '' != $jetpack_portfolio_content ) {
  86. $content = convert_chars( convert_smilies( wptexturize( wp_kses_post( $jetpack_portfolio_content ) ) ) );
  87. echo $before . $content . $after;
  88. }
  89. }
  90. /**
  91. * Portfolio Featured Image.
  92. */
  93. function illustratr_portfolio_thumbnail( $before = '', $after = '' ) {
  94. $jetpack_portfolio_featured_image = get_option( 'jetpack_portfolio_featured_image' );
  95. if ( isset( $jetpack_portfolio_featured_image ) && '' != $jetpack_portfolio_featured_image ) {
  96. $featured_image = wp_get_attachment_image( (int) $jetpack_portfolio_featured_image, 'illustratr-featured-image' );
  97. echo $before . $featured_image . $after;
  98. }
  99. }
  100. /**
  101. * Filter Infinite Scroll text handle.
  102. */
  103. function illustratr_portfolio_infinite_scroll_navigation( $js_settings ) {
  104. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  105. $js_settings[ 'text' ] = esc_js( esc_html__( 'Older projects', 'illustratr' ) );
  106. }
  107. return $js_settings;
  108. }
  109. add_filter( 'infinite_scroll_js_settings', 'illustratr_portfolio_infinite_scroll_navigation' );
  110. /**
  111. * Load Jetpack scripts.
  112. */
  113. function illustratr_jetpack_scripts() {
  114. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) || is_page_template( 'page-templates/portfolio-page.php' ) ) {
  115. wp_enqueue_script( 'illustratr-portfolio', get_template_directory_uri() . '/js/portfolio.js', array( 'jquery', 'masonry' ), '20140325', true );
  116. }
  117. if ( is_singular() && 'jetpack-portfolio' == get_post_type() ) {
  118. wp_enqueue_script( 'illustratr-portfolio-single', get_template_directory_uri() . '/js/portfolio-single.js', array( 'jquery', 'underscore' ), '20140328', true );
  119. }
  120. if ( is_page_template( 'page-templates/portfolio-page.php' ) ) {
  121. wp_enqueue_script( 'illustratr-portfolio-page', get_template_directory_uri() . '/js/portfolio-page.js', array( 'jquery' ), '20140402', true );
  122. }
  123. }
  124. add_action( 'wp_enqueue_scripts', 'illustratr_jetpack_scripts' );