-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmfe-bot-checker.php
More file actions
53 lines (44 loc) · 1.72 KB
/
cmfe-bot-checker.php
File metadata and controls
53 lines (44 loc) · 1.72 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
<?php
function cmfe_is_bot_or_user()
{
// Get plugin options
$CMFE_OPTIONS = get_option('cmfe_settings_options', array());
if (empty($CMFE_OPTIONS)) {
return 'unknown';
}
static $visitor_type = null;
// If the visitor type is already determined, return it
if ($visitor_type !== null) {
return $visitor_type;
}
// Set the necessary global variables
$GLOBALS['_ta_campaign_key'] = $CMFE_OPTIONS['cmfe_campaign_key'];
$GLOBALS['_ta_debug_mode'] = $CMFE_OPTIONS['cmfe_debug_mode'];
// Include the bootloader
if (file_exists(plugin_dir_path(__FILE__) . $CMFE_OPTIONS['cmfe_bootloader_name'] . '.php')) {
require_once plugin_dir_path(__FILE__) . $CMFE_OPTIONS['cmfe_bootloader_name'] . '.php';
} else {
error_log('Bootloader file not exist: ' . plugin_dir_path(__FILE__) . $CMFE_OPTIONS['cmfe_bootloader_name'] . '.php');
return 'unknown';
}
// Load the campaign
$campaign_id = $CMFE_OPTIONS['cmfe_campaign_id'];
$ta = new TALoader($campaign_id);
// Check if the response should be suppressed
if ($ta->suppress_response()) {
error_log('TALoader suppressed the response.');
$visitor_type = 'unknown';
return $visitor_type;
}
// Retrieve the response data
$response = $ta->get_response();
error_log('TALoader response: ' . print_r($response, true));
// Determine the visitor type
$visitor_type = empty($response['cloak_reason']) ? 'user' : 'bot';
return $visitor_type;
}
// Display the visitor type in the console
add_action('wp_footer', function () {
$visitor_type = cmfe_is_bot_or_user();
echo "<script>console.log('CMFE Cloaking from: " . $visitor_type . "');</script>";
}, 100);