-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIntegrationsByClass.php
More file actions
executable file
·79 lines (66 loc) · 2.52 KB
/
Copy pathIntegrationsByClass.php
File metadata and controls
executable file
·79 lines (66 loc) · 2.52 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
<?php
namespace Cleantalk\Antispam;
use Cleantalk\Antispam\IntegrationsByClass\IntegrationByClassBase;
class IntegrationsByClass
{
/**
* @var array<string, array{plugin_path: string, plugin_class: string}>
* @psalm-suppress UnusedVariable, UnusedProperty
*/
private $integrations;
private $active_plugins;
private $active_plugins_wpms;
/**
* Integrations constructor.
*
* @param array $integrations
*/
public function __construct($integrations)
{
$this->integrations = $integrations;
$this->active_plugins = get_option('active_plugins', array());
$this->active_plugins_wpms = get_site_option('active_sitewide_plugins', array());
$this->active_plugins = is_array($this->active_plugins) ? $this->active_plugins : array();
$this->active_plugins_wpms = is_array($this->active_plugins_wpms) ? $this->active_plugins_wpms : array();
foreach ($this->integrations as $integration_name => $integration_info) {
// pre-check to skip integration by plugin path
if (!isset($integration_info['wp_includes'])) {
if ( isset($integration_info['plugin_path']) && !$this->isPluginActive($integration_info['plugin_path']) ) {
continue;
}
// pre-check to skip integration by plugin class
if ( isset($integration_info['plugin_class']) && !class_exists($integration_info['plugin_class']) ) {
continue;
}
}
$class = '\\Cleantalk\\Antispam\\IntegrationsByClass\\' . $integration_name;
if (!class_exists($class)) {
continue;
}
/**
* @var IntegrationByClassBase $integration
*/
$integration = new $class();
// Ajax work
if (apbct_is_ajax()) {
$integration->doAjaxWork();
continue;
}
// Admin work
if (is_admin() || is_network_admin()) {
$integration->doAdminWork();
continue;
}
// Public work
$skip_integration = $integration->isSkipIntegration();
if ($skip_integration) {
continue;
}
$integration->doPublicWork();
}
}
private function isPluginActive($plugin_path)
{
return in_array($plugin_path, $this->active_plugins) || in_array($plugin_path, $this->active_plugins_wpms);
}
}