|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
4
|
|
|
exit; |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Holds the speed optimization functions for LSX. |
|
9
|
|
|
* |
|
10
|
|
|
* @author LightSpeed |
|
11
|
|
|
* @category Widgets |
|
12
|
|
|
* @package LSX |
|
13
|
|
|
* @return LSX_Optimisation |
|
14
|
|
|
*/ |
|
15
|
|
|
class LSX_Optimisation { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Holds class instance |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0.0 |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
protected static $instance = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() { |
|
29
|
|
|
//add_filter( 'style_loader_tag', array( $this, 'preload_css' ), 100, 4 ); |
|
|
|
|
|
|
30
|
|
|
//add_filter( 'script_loader_tag', array( $this, 'defer_parsing_of_js' ), 100, 3 ); |
|
|
|
|
|
|
31
|
|
|
add_action( 'init', array( $this, 'pum_remove_admin_bar_tools' ), 100 ); |
|
32
|
|
|
} |
|
33
|
|
|
/** |
|
34
|
|
|
* Return an instance of this class. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.0.0 |
|
37
|
|
|
* @return object A single instance of this class. |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function get_instance() { |
|
40
|
|
|
// If the single instance hasn't been set, set it now. |
|
41
|
|
|
if ( null === self::$instance ) { |
|
42
|
|
|
self::$instance = new self; |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
return self::$instance; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
|
|
|
|
|
48
|
|
|
* Defers the JS loading till Last |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $url The url to check and defer. |
|
|
|
|
|
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function preload_css( $tag, $handle, $href, $media ) { |
|
|
|
|
|
|
54
|
|
|
if ( 'lsx_fonts' === $handle || 'fontawesome' === $handle ) { |
|
55
|
|
|
$tag = str_replace( 'href', ' preload href', $tag ); |
|
56
|
|
|
} |
|
57
|
|
|
return $tag; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
|
|
|
|
|
61
|
|
|
* Defers the JS loading till Last |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $url The url to check and defer. |
|
|
|
|
|
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function defer_parsing_of_js( $tag, $handle, $href ) { |
|
67
|
|
|
$skip_defer = apply_filters( 'lsx_defer_parsing_of_js', false, $tag, $handle, $href ); |
|
68
|
|
|
if ( ! is_admin() && false !== stripos( $href, '.js' ) && false === stripos( $href, 'jquery.js' ) && false === $skip_defer ) { |
|
69
|
|
|
$tag = str_replace( 'src=', ' defer src=', $tag ); |
|
70
|
|
|
} |
|
71
|
|
|
return $tag; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function pum_remove_admin_bar_tools() { |
|
|
|
|
|
|
75
|
|
|
remove_action( 'admin_bar_menu', array( 'PUM_Modules_Admin_Bar', 'toolbar_links' ), 999 ); |
|
76
|
|
|
remove_action( 'wp_footer', array( 'PUM_Modules_Admin_Bar', 'admin_bar_styles' ), 999 ); |
|
77
|
|
|
remove_action( 'init', array( 'PUM_Modules_Admin_Bar', 'show_debug_bar' ) ); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
LSX_Optimisation::get_instance(); |
|
81
|
|
|
|