-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvael-performance.php
More file actions
114 lines (93 loc) · 2.79 KB
/
Copy pathvael-performance.php
File metadata and controls
114 lines (93 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* VAEL Board performance optimizations.
*/
defined( 'ABSPATH' ) || exit;
/**
* Check whether the current frontend page is the VAEL Board.
*/
function vael_me_is_board_page() {
return ! is_admin() && is_page( 'board' );
}
/**
* Check whether an asset URL contains one of the supplied paths.
*/
function vael_me_asset_matches( $src, $needles ) {
$src = (string) $src;
if ( '' === $src ) {
return false;
}
foreach ( $needles as $needle ) {
if ( false !== strpos( $src, $needle ) ) {
return true;
}
}
return false;
}
/**
* Remove assets that are not required on the VAEL Board.
*/
function vael_me_optimize_board_assets() {
if ( ! vael_me_is_board_page() ) {
return;
}
/*
* WordPress core assets.
* Remove Dashicons only for normal frontend users.
*/
if ( ! current_user_can( 'manage_options' ) ) {
wp_dequeue_style( 'dashicons' );
}
/*
* Board is rendered through Elementor/shortcode,
* so Gutenberg block styles are normally unnecessary.
*/
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'classic-theme-styles' );
/*
* WordPress embed script is not required on the Board.
*/
wp_dequeue_script( 'wp-embed' );
/*
* Remove clearly unrelated styles by their source URL.
*/
$unused_style_paths = array(
'/buddyboss-theme/assets/css/bbpress.css',
'/buddyboss-platform-pro/includes/integrations/zoom/assets/css/',
);
$styles = wp_styles();
foreach ( (array) $styles->queue as $handle ) {
if ( empty( $styles->registered[ $handle ] ) ) {
continue;
}
$src = $styles->registered[ $handle ]->src;
if ( vael_me_asset_matches( $src, $unused_style_paths ) ) {
wp_dequeue_style( $handle );
}
}
/*
* Remove integrations not used on the Board page.
*/
$unused_script_paths = array(
'/buddyboss-platform-pro/includes/integrations/tutorlms/',
'/buddyboss-platform-pro/includes/integrations/meprlms/',
'/buddyboss-platform/bp-core/js/vendor/dropzone.min.js',
'/miniorange-login-openid/includes/js/',
);
$scripts = wp_scripts();
foreach ( (array) $scripts->queue as $handle ) {
if ( empty( $scripts->registered[ $handle ] ) ) {
continue;
}
$src = $scripts->registered[ $handle ]->src;
if ( vael_me_asset_matches( $src, $unused_script_paths ) ) {
wp_dequeue_script( $handle );
}
}
}
add_action(
'wp_enqueue_scripts',
'vael_me_optimize_board_assets',
999
);