| 1 |
<?php |
| 2 |
/** |
| 3 |
* Theme Tools: Infinite Scroll functions. |
| 4 |
* |
| 5 |
* @package automattic/jetpack |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Load theme's infinite scroll annotation file, if present in the IS plugin. |
| 10 |
* The `setup_theme` action is used because the annotation files should be using `after_setup_theme` to register support for IS. |
| 11 |
* |
| 12 |
* 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. |
| 13 |
* |
| 14 |
* @uses is_admin, wp_get_theme, apply_filters |
| 15 |
* @action setup_theme |
| 16 |
* @return null |
| 17 |
*/ |
| 18 |
function jetpack_load_infinite_scroll_annotation() { |
| 19 |
if ( is_admin() && isset( $_GET['page'] ) && 'jetpack' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Function loads theme specific IS file provided by Jetpack if possible. |
| 20 |
$theme = wp_get_theme(); |
| 21 |
|
| 22 |
if ( ! is_a( $theme, 'WP_Theme' ) && ! is_array( $theme ) ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
/** This filter is already documented in modules/infinite-scroll/infinity.php */ |
| 27 |
$customization_file = apply_filters( 'infinite_scroll_customization_file', __DIR__ . "/infinite-scroll/themes/{$theme['Stylesheet']}.php", $theme['Stylesheet'] ); |
| 28 |
|
| 29 |
if ( is_readable( $customization_file ) ) { |
| 30 |
require_once $customization_file; |
| 31 |
} elseif ( ! empty( $theme['Template'] ) ) { |
| 32 |
$customization_file = __DIR__ . "/infinite-scroll/themes/{$theme['Template']}.php"; |
| 33 |
|
| 34 |
if ( is_readable( $customization_file ) ) { |
| 35 |
require_once $customization_file; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
add_action( 'setup_theme', 'jetpack_load_infinite_scroll_annotation' ); |
| 41 |
|
| 42 |
/** |
| 43 |
* Prevent IS from being activated if theme doesn't support it |
| 44 |
* |
| 45 |
* @filter jetpack_can_activate_infinite-scroll |
| 46 |
* @return bool |
| 47 |
*/ |
| 48 |
function jetpack_can_activate_infinite_scroll() { |
| 49 |
return (bool) current_theme_supports( 'infinite-scroll' ); |
| 50 |
} |
| 51 |
add_filter( 'jetpack_can_activate_infinite-scroll', 'jetpack_can_activate_infinite_scroll' ); |
| 52 |
|