infinite-scroll.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * INFINITE SCROLL
  4. */
  5. /**
  6. * Load theme's infinite scroll annotation file, if present in the IS plugin.
  7. * The `setup_theme` action is used because the annotation files should be using `after_setup_theme` to register support for IS.
  8. *
  9. * As released in Jetpack 2.0, a child theme's parent wasn't checked for in the plugin's bundled support, hence the convoluted way the parent is checked for now.
  10. *
  11. * @uses is_admin, wp_get_theme, apply_filters
  12. * @action setup_theme
  13. * @return null
  14. */
  15. function jetpack_load_infinite_scroll_annotation() {
  16. if ( is_admin() && isset( $_GET['page'] ) && 'jetpack' == $_GET['page'] ) {
  17. $theme = wp_get_theme();
  18. if ( ! is_a( $theme, 'WP_Theme' ) && ! is_array( $theme ) )
  19. return;
  20. /** This filter is already documented in modules/infinite-scroll/infinity.php */
  21. $customization_file = apply_filters( 'infinite_scroll_customization_file', dirname( __FILE__ ) . "/infinite-scroll/themes/{$theme['Stylesheet']}.php", $theme['Stylesheet'] );
  22. if ( is_readable( $customization_file ) ) {
  23. require_once( $customization_file );
  24. } elseif ( ! empty( $theme['Template'] ) ) {
  25. $customization_file = dirname( __FILE__ ) . "/infinite-scroll/themes/{$theme['Template']}.php";
  26. if ( is_readable( $customization_file ) )
  27. require_once( $customization_file );
  28. }
  29. }
  30. }
  31. add_action( 'setup_theme', 'jetpack_load_infinite_scroll_annotation' );
  32. /**
  33. * Prevent IS from being activated if theme doesn't support it
  34. *
  35. * @param bool $can_activate
  36. * @filter jetpack_can_activate_infinite-scroll
  37. * @return bool
  38. */
  39. function jetpack_can_activate_infinite_scroll() {
  40. return (bool) current_theme_supports( 'infinite-scroll' );
  41. }
  42. add_filter( 'jetpack_can_activate_infinite-scroll', 'jetpack_can_activate_infinite_scroll' );