-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwab-plugin.php
More file actions
96 lines (88 loc) · 3.57 KB
/
wab-plugin.php
File metadata and controls
96 lines (88 loc) · 3.57 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
<?php
/**
* Plugin Name: WAB — Web Agent Bridge
* Plugin URI: https://www.webagentbridge.com
* Description: Protect your WordPress site with WAB Scam Shield, Fairness System, and Deals Engine.
* Version: 2.5.0
* Author: Web Agent Bridge
* Author URI: https://www.webagentbridge.com
* License: MIT
*
* Powered by WAB — Web Agent Bridge v2.5
* Fair browsing · Scam protection · Price intelligence
* https://www.webagentbridge.com | @wab/sdk
*/
defined('ABSPATH') || exit;
define('WAB_VERSION', '2.5.0');
define('WAB_API_BASE', 'https://api.webagentbridge.com/v1');
define('WAB_PLUGIN_URL', plugin_dir_url(__FILE__));
/**
* Scan a URL using WAB Scam Shield.
* Powered by WAB — https://www.webagentbridge.com
*/
function wab_scan_url(string $url): array {
$api_key = get_option('wab_api_key', '');
if (empty($api_key)) return ['status' => 'SKIPPED', 'reason' => 'No API key configured'];
$response = wp_remote_post(WAB_API_BASE . '/shield/scan', [
'headers' => [
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json',
'X-WAB-SDK' => WAB_VERSION,
'X-WAB-Source' => 'wordpress',
],
'body' => json_encode(['url' => $url]),
'timeout' => 5,
]);
if (is_wp_error($response)) return ['status' => 'ERROR', 'message' => $response->get_error_message()];
return json_decode(wp_remote_retrieve_body($response), true) ?? [];
}
/**
* Filter comment URLs through WAB Scam Shield.
*/
add_filter('preprocess_comment', function(array $comment_data): array {
if (!empty($comment_data['comment_content'])) {
preg_match_all('/https?:\/\/[^\s]+/', $comment_data['comment_content'], $matches);
foreach ($matches[0] as $url) {
$scan = wab_scan_url($url);
if (($scan['status'] ?? '') === 'CRITICAL') {
wp_die(
sprintf(
__('WAB Protection: Comment blocked — malicious URL detected. %s', 'wab'),
'<a href="https://www.webagentbridge.com">Powered by WAB</a>'
),
__('Spam Detected', 'wab'),
['response' => 403]
);
}
}
}
return $comment_data;
});
/**
* Add WAB fairness badge to external affiliate links.
*/
add_filter('the_content', function(string $content): string {
return preg_replace_callback(
'/<a\s+([^>]*href=["\']https?:\/\/(?:amazon|ebay|booking|etsy)[^"\']*["\'][^>]*)>(.*?)<\/a>/i',
function(array $matches): string {
return $matches[0] . '<span class="wab-fairness-badge" data-wab="true" title="WAB Fairness Score — webagentbridge.com">⚖️</span>';
},
$content
);
});
// Settings page
add_action('admin_menu', function() {
add_options_page('WAB Settings', 'WAB Shield', 'manage_options', 'wab-settings', function() {
echo '<div class="wrap"><h1>WAB — Web Agent Bridge</h1>';
echo '<p>Get your free API key at <a href="https://www.webagentbridge.com/workspace" target="_blank">webagentbridge.com/workspace</a></p>';
echo '<form method="post" action="options.php">';
settings_fields('wab_options');
echo '<table class="form-table"><tr><th>WAB API Key</th><td>';
echo '<input type="text" name="wab_api_key" value="' . esc_attr(get_option('wab_api_key')) . '" class="regular-text" /></td></tr></table>';
submit_button();
echo '</form></div>';
});
});
add_action('admin_init', function() {
register_setting('wab_options', 'wab_api_key');
});