Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack_Boost\Compatibility\Revslider\exclude_revslider_scripts
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Compatibility for Revolution Slider
4 *
5 * @package automattic/jetpack-boost
6 */
7
8namespace Automattic\Jetpack_Boost\Compatibility\Revslider;
9
10/**
11 * Exclude Revolution Slider scripts from deferred JS.
12 * We can't use handles, since revslider doesn't have a standardized naming convention.
13 *
14 * @param array $scripts The scripts to exclude.
15 * @return array The scripts to exclude.
16 */
17function exclude_revslider_scripts( $scripts ) {
18    // Don't check scripts if Revolution Slider isn't active.
19    if ( ! class_exists( '\RevSliderFront' ) ) {
20        return $scripts;
21    }
22
23    // Filter out any revslider scripts
24    $scripts = array_filter(
25        $scripts,
26        function ( $script ) {
27            // Check if it's a script tag and contains revslider
28            if ( is_array( $script ) && isset( $script[0] ) && strpos( $script[0], '<script' ) !== false ) {
29                return strpos( $script[0], '/revslider/' ) === false;
30            }
31            return true;
32        }
33    );
34
35    return array_values( $scripts );
36}
37
38add_filter( 'jetpack_boost_render_blocking_js_exclude_scripts', __NAMESPACE__ . '\exclude_revslider_scripts', 10, 1 );