Completed
Push — develop ( 6659d7...0a0f85 )
by David
03:06
created

Wordlift_WpRocket_Adapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A exclude_js() 0 7 1
A excluded_inline_js_content() 0 6 1
1
<?php
2
/**
3
 * Adapters: WP-Rocket Adapter.
4
 *
5
 * The WP-Rocket Adapter tunes the Apdex index for Wordlift.
6
 *
7
 * @since   3.19.4
8
 *
9
 * @see https://github.com/insideout10/wordlift-plugin/issues/842.
10
 * @see https://github.com/wp-media/wp-rocket-helpers/blob/master/static-files/wp-rocket-static-exclude-defer-js/wp-rocket-static-exclude-defer-js.php.
11
 *
12
 * @package Wordlift
13
 * @subpackage Wordlift/includes
14
 */
15
16
/**
17
 * Define the {@link Wordlift_WP-Rocket_Adapter} class.
18
 *
19
 * @since   3.19.4
20
 */
21
class Wordlift_WpRocket_Adapter {
22
23
	/**
24
	 * Create a {@link Wordlift_WpRocket_Adapter} instance.
25
	 *
26
	 * @since 3.19.4
27
	 */
28
	public function __construct() {
29
30
		add_filter( 'rocket_exclude_js', array( $this, 'exclude_js' ) );
31
		add_filter( 'rocket_excluded_inline_js_content', array( $this, 'excluded_inline_js_content' ) );
32
33
	}
34
35
	/**
36
	 * Hook to `rocket_exclude_defer_js` filter.
37
	 *
38
	 * @since 3.20.0 hook to `rocket_exclude_js`.
39
	 * @since 3.19.4
40
	 *
41
	 * @param array $js_files The preset excluded files.
42
	 *
43
	 * @return array The updated excluded files array.
44
	 */
45
	public function exclude_js( $js_files = array() ) {
46
47
		// Exclude our own public JS.
48
		$js_files[] = Wordlift_Public::get_public_js_url();
49
50
		return $js_files;
51
	}
52
53
	/**
54
	 * Filters inline JS excluded from being combined
55
	 *
56
	 * @link https://github.com/insideout10/wordlift-plugin/issues/868
57
	 *
58
	 * @since 3.20.0
59
	 *
60
	 * @param array $pattern Patterns to match.
61
	 *
62
	 * @return array Patterns to match.
63
	 */
64
	public function excluded_inline_js_content( $pattern = array() ) {
65
66
		$pattern[] = 'wlSettings';
67
68
		return $pattern;
69
	}
70
71
}
72