-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathcompatibility.php
More file actions
186 lines (167 loc) · 4.9 KB
/
compatibility.php
File metadata and controls
186 lines (167 loc) · 4.9 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* Check if certain plugins or themes are installed and activated
* and if found dynamically load the relevant /includes/compatibility/ files.
*/
function pmpro_compatibility_checker() {
$compat_checks = [
[
'file' => 'siteorigin.php',
'check_type' => 'constant',
'check_value' => 'SITEORIGIN_PANELS_VERSION',
],
[
'file' => 'elementor.php',
'check_type' => 'constant',
'check_value' => 'ELEMENTOR_VERSION',
],
[
'file' => 'beaver-builder.php',
'check_type' => 'constant',
'check_value' => 'FL_BUILDER_VERSION',
],
[
'file' => 'theme-my-login.php',
'check_type' => 'class',
'check_value' => 'Theme_My_Login',
],
[
'file' => 'woocommerce.php',
'check_type' => 'constant',
'check_value' => 'WC_PLUGIN_FILE',
],
[
'file' => 'wp-engine.php',
'check_type' => 'function',
'check_value' => 'wpe_filter_site_url',
],
[
'file' => 'divi.php',
'check_type' => 'constant',
'check_value' => 'ET_BUILDER_PLUGIN_DIR',
],
[
'file' => 'jetpack.php',
'check_type' => 'class',
'check_value' => 'Jetpack',
],
[
'file' => 'avada.php',
'check_type' => 'constant',
'check_value' => 'FUSION_BUILDER_VERSION'
],
[
'file' => 'oxygen-builder.php',
'check_type' => 'class',
'check_value' => 'OxyEl'
],
[
'file' => 'lifterlms.php',
'check_type' => 'function',
'check_value' => 'llms'
],
[
'file' => 'buddypress.php',
'check_type' => 'class',
'check_value' => 'BuddyPress' //BuddyBoss uses this class, too.
],
[
'file' => 'wp-bakery.php',
'check_type' => 'function',
'check_value' => 'vc_add_param'
],
];
foreach ( $compat_checks as $value ) {
if ( pmpro_compatibility_checker_is_requirement_met( $value ) ) {
include_once( PMPRO_DIR . '/includes/compatibility/' . $value['file'] ) ;
}
}
}
add_action( 'plugins_loaded', 'pmpro_compatibility_checker' );
/**
* Check whether the requirement is met.
*
* @since 2.6.4
*
* @param array $requirement The requirement config (check_type, check_value, check_constant_true).
*
* @return bool Whether the requirement is met.
*/
function pmpro_compatibility_checker_is_requirement_met( $requirement ) {
// Make sure we have the keys that we expect.
if ( ! isset( $requirement['check_type'], $requirement['check_value'] ) ) {
return false;
}
// Check for a constant and maybe check if the constant is true-ish.
if ( 'constant' === $requirement['check_type'] ) {
return (
defined( $requirement['check_value'] )
&& (
empty( $requirement['check_constant_true'] )
|| constant( $requirement['check_value'] )
)
);
}
// Check for a function.
if ( 'function' === $requirement['check_type'] ) {
return function_exists( $requirement['check_value'] );
}
// Check for a class.
if ( 'class' === $requirement['check_type'] ) {
return class_exists( $requirement['check_value'] );
}
return false;
}
function pmpro_compatibility_checker_themes(){
$compat_checks = array(
array(
'file' => 'divi.php',
'check_type' => 'constant',
'check_value' => 'ET_BUILDER_THEME' //Adds support for the Divi theme.
)
);
foreach ( $compat_checks as $key => $value ) {
if ( pmpro_compatibility_checker_is_requirement_met( $value ) ) {
include_once( PMPRO_DIR . '/includes/compatibility/' . $value['file'] ) ;
}
}
}
add_action( 'after_setup_theme', 'pmpro_compatibility_checker_themes' );
/**
* Keep track of plugins that load libraries before PMPro loads its version.
*
* @param string $name The name of the library.
* @param string $path The path of the loaded library.
* @param string $version The version of the loaded library.
*
* @since 2.8
*/
function pmpro_track_library_conflict( $name, $path, $version ) {
// Ignore when PMPro is trying to load.
if ( strpos( $path, '/plugins/paid-memberships-pro/' ) !== false ) {
return;
}
// Use a static var for timestamp so we can avoid multiple updates per pageload.
static $now = null;
if ( empty( $now ) ) {
$now = current_time( 'Y-m-d H:i:s' );
}
// Get the current list of library conflicts.
$library_conflicts = get_option( 'pmpro_library_conflicts', array() );
// Make sure we have an entry for this library.
if ( ! isset( $library_conflicts[ $name ] ) ) {
$library_conflicts[ $name ] = array();
}
// Make sure we have an entry for this path.
if ( ! isset( $library_conflicts[ $name ][ $path ] ) ) {
$library_conflicts[ $name ][ $path ] = array();
}
// Don't save conflict if no time has passed.
if ( ! empty( $library_conflicts[ $name ][ $path ]['timestamp'] ) && $library_conflicts[ $name ][ $path ]['timestamp'] === $now ) {
return;
}
// Update the library conflict information.
$library_conflicts[ $name ][ $path ]['version'] = $version;
$library_conflicts[ $name ][ $path ]['timestamp'] = $now;
update_option( 'pmpro_library_conflicts', $library_conflicts, false );
}