diff --git a/admin/partials/blocked-ips-page.php b/admin/partials/blocked-ips-page.php index f66cf64..5dbf785 100644 --- a/admin/partials/blocked-ips-page.php +++ b/admin/partials/blocked-ips-page.php @@ -5,6 +5,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included by blocked_ips_page(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/admin/partials/dashboard-widget.php b/admin/partials/dashboard-widget.php index 1d353e3..e079b98 100644 --- a/admin/partials/dashboard-widget.php +++ b/admin/partials/dashboard-widget.php @@ -5,6 +5,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included by render_dashboard_widget(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/admin/partials/detections-page.php b/admin/partials/detections-page.php index 98e308f..6954aaf 100644 --- a/admin/partials/detections-page.php +++ b/admin/partials/detections-page.php @@ -5,6 +5,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included by detections_page(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; @@ -90,7 +92,7 @@ fputcsv($output, ['Date', 'IP Address', 'Score', 'Threat Level', 'Source', 'User Agent', 'Flags']); $export_query = "SELECT * FROM {$table} WHERE {$where} ORDER BY created_at DESC"; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Query built dynamically with safe table/column names + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Filter SQL uses only literal clauses; every request value is bound by wpdb::prepare(). $export_results = $wpdb->get_results($wpdb->prepare($export_query, $params), ARRAY_A); foreach ($export_results as $row) { @@ -112,14 +114,14 @@ // Get total - always use prepare() $total_query = "SELECT COUNT(*) FROM {$table} WHERE {$where}"; -// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Query built dynamically with safe table/column names +// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Filter SQL uses only literal clauses; every request value is bound by wpdb::prepare(). $total = $wpdb->get_var($wpdb->prepare($total_query, $params)); $total_pages = ceil($total / $wd_per_page); // Get detections - always use prepare() $query = "SELECT * FROM {$table} WHERE {$where} ORDER BY created_at DESC LIMIT %d OFFSET %d"; $query_params = array_merge($params, [$wd_per_page, $offset]); -// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Query built dynamically with safe table/column names +// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Filter SQL uses only literal clauses; every request value is bound by wpdb::prepare(). $detections = $wpdb->get_results($wpdb->prepare($query, $query_params), ARRAY_A); // Get stats diff --git a/admin/partials/page-cache-notice.php b/admin/partials/page-cache-notice.php index d262b8d..2a6d3b5 100644 --- a/admin/partials/page-cache-notice.php +++ b/admin/partials/page-cache-notice.php @@ -5,6 +5,8 @@ * * @package WebDecoy */ + +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included through statistics_page(). Its variables stay in that method. if (!defined('ABSPATH')) { exit; } diff --git a/admin/partials/settings-page.php b/admin/partials/settings-page.php index a379467..174c908 100644 --- a/admin/partials/settings-page.php +++ b/admin/partials/settings-page.php @@ -5,6 +5,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included by settings_page(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/admin/partials/statistics-page.php b/admin/partials/statistics-page.php index b44986b..7d097fe 100644 --- a/admin/partials/statistics-page.php +++ b/admin/partials/statistics-page.php @@ -5,6 +5,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This partial is included by statistics_page(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/admin/partials/traffic-overview.php b/admin/partials/traffic-overview.php index 61569d6..63681cc 100644 --- a/admin/partials/traffic-overview.php +++ b/admin/partials/traffic-overview.php @@ -1,5 +1,7 @@ .*developers\.cloudflare\.com\/(security-center|browser-rendering\/rest-api\/crawl-endpoint)/s|$| // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- Crawler match or documentation metadata.|" \ + "$registry" fi # Create ZIP file (folder inside is always the slug, as WordPress requires) diff --git a/includes/class-webdecoy-ai-referrals.php b/includes/class-webdecoy-ai-referrals.php index 7cb8149..b19fbfb 100644 --- a/includes/class-webdecoy-ai-referrals.php +++ b/includes/class-webdecoy-ai-referrals.php @@ -52,19 +52,19 @@ class WebDecoy_AI_Referrals private static bool $cloud = false; /** - * The ai_referrals table name, prefixed and escaped for interpolation. + * The ai_referrals table name, including the current WordPress site prefix. */ public static function table(): string { global $wpdb; - return esc_sql($wpdb->prefix . 'webdecoy_ai_referrals'); + return $wpdb->prefix . 'webdecoy_ai_referrals'; } - /** The local daily counts table name, prefixed and escaped for interpolation. */ + /** The local daily counts table name, including the current WordPress site prefix. */ public static function days_table(): string { global $wpdb; - return esc_sql($wpdb->prefix . 'webdecoy_ai_referral_days'); + return $wpdb->prefix . 'webdecoy_ai_referral_days'; } /** @@ -141,7 +141,7 @@ private static function recordDay(string $platform, string $path): void return; } global $wpdb; - $table = self::days_table(); + $table = esc_sql(self::days_table()); $day = self::day(time()); // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $known = (int) $wpdb->get_var($wpdb->prepare( @@ -179,7 +179,7 @@ public static function summary(int $days): array return self::summarize([]); } global $wpdb; - $table = self::days_table(); + $table = esc_sql(self::days_table()); // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $rows = $wpdb->get_results($wpdb->prepare( "SELECT platform, landing_path, SUM(referrals) AS referrals FROM {$table} WHERE day >= %s GROUP BY platform, landing_path", @@ -235,7 +235,7 @@ public static function prune(): void return; } global $wpdb; - $table = self::days_table(); + $table = esc_sql(self::days_table()); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE day < %s", self::day(time() - self::LOCAL_RETENTION_DAYS * DAY_IN_SECONDS))); } @@ -281,7 +281,7 @@ public static function landingPath(string $uri): string private static function increment(string $platform, string $path): void { global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $rows = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$table}"); $key = sha1($platform . "\n" . $path); @@ -316,7 +316,7 @@ public static function flush(string $apiKey): void return; } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $batch = (string) $wpdb->get_var("SELECT batch_id FROM {$table} WHERE batch_id <> '' LIMIT 1"); if ($batch === '') { diff --git a/includes/class-webdecoy-blocker.php b/includes/class-webdecoy-blocker.php index 597a44b..0f7c082 100644 --- a/includes/class-webdecoy-blocker.php +++ b/includes/class-webdecoy-blocker.php @@ -442,7 +442,7 @@ public function get_blocked_ips(array $args = []): array $offset = ($args['page'] - 1) * $args['per_page']; - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Filtered, paginated operator block list needs current entries after block/unblock actions. + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The live block list uses an escaped table, a prepared time condition and allowlisted sort options. $results = $wpdb->get_results($wpdb->prepare( "SELECT * FROM {$table} WHERE {$where} ORDER BY {$orderby} {$order} LIMIT %d OFFSET %d", $args['per_page'], @@ -469,7 +469,7 @@ public function get_blocked_count(bool $include_expired = false): int $where .= $wpdb->prepare(" AND (expires_at IS NULL OR expires_at > %s)", gmdate('Y-m-d H:i:s')); } - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Operator list pagination uses current plugin block counts, including time-dependent expirations. + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- The live count uses an escaped table and a prepared time condition. return (int) $wpdb->get_var("SELECT COUNT(*) FROM {$table} WHERE {$where}"); } diff --git a/includes/class-webdecoy-crawler-visits.php b/includes/class-webdecoy-crawler-visits.php index 18ddd1e..8d18912 100644 --- a/includes/class-webdecoy-crawler-visits.php +++ b/includes/class-webdecoy-crawler-visits.php @@ -47,12 +47,12 @@ class WebDecoy_Crawler_Visits private const SEARCH_CATEGORIES = ['search_crawler']; /** - * The counters table name, prefixed and escaped for interpolation. + * The counters table name, including the current WordPress site prefix. */ public static function table(): string { global $wpdb; - return esc_sql($wpdb->prefix . 'webdecoy_crawler_visits'); + return $wpdb->prefix . 'webdecoy_crawler_visits'; } /** @@ -99,7 +99,7 @@ public static function observe(string $userAgent, array $flags, bool $ipUnreliab } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $wpdb->query($wpdb->prepare( "INSERT INTO {$table} (bucket, agent_id, verification, hits) VALUES (%s, %s, %s, 1) @@ -132,7 +132,7 @@ public static function summary(int $hours): array return self::summarize([]); } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $rows = $wpdb->get_results($wpdb->prepare( "SELECT agent_id, verification, SUM(hits) AS hits FROM {$table} WHERE bucket >= %s GROUP BY agent_id, verification", @@ -250,7 +250,7 @@ public static function prune(): void return; } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- table name from $wpdb->prefix $wpdb->query($wpdb->prepare( "DELETE FROM {$table} WHERE bucket < %s", diff --git a/includes/class-webdecoy-llms-txt.php b/includes/class-webdecoy-llms-txt.php index 66c437d..90b152b 100644 --- a/includes/class-webdecoy-llms-txt.php +++ b/includes/class-webdecoy-llms-txt.php @@ -142,6 +142,7 @@ private static function send(string $body): void // Full-page caches (WP Super Cache, W3TC, WP Rocket, LiteSpeed) honour // this: a cached copy would be served as HTML and stop crawler counts. if (!defined('DONOTCACHEPAGE')) { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Full-page caches read this shared constant. define('DONOTCACHEPAGE', true); } status_header(200); diff --git a/includes/class-webdecoy-page-cache.php b/includes/class-webdecoy-page-cache.php index f6f7bc2..4007cc5 100644 --- a/includes/class-webdecoy-page-cache.php +++ b/includes/class-webdecoy-page-cache.php @@ -134,6 +134,7 @@ public static function detect(): array if (defined('W3TC') && self::w3tc_page_cache_enabled()) { return self::plugin('W3 Total Cache', 'w3tc', true); } + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Read LiteSpeed Cache configuration through its published filter. if (defined('LSCWP_V') && function_exists('apply_filters') && apply_filters('litespeed_conf', 'cache')) { return self::plugin('LiteSpeed Cache', 'litespeed', true); } @@ -455,12 +456,14 @@ public static function adapters(): array }, 'wanted' => $same, 'read' => static function (): array { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Read LiteSpeed Cache configuration through its published filter. $list = apply_filters('litespeed_conf', self::LITESPEED_UA_KEY); return is_array($list) ? array_values(array_map('strval', $list)) : []; }, 'write' => static function (array $list): bool { // LiteSpeed's public API: saves the option and rewrites // its .htaccess "no cache" rule for these agents. + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoke LiteSpeed Cache's settings action. do_action('litespeed_save_conf', [self::LITESPEED_UA_KEY => $list]); return true; }, @@ -479,9 +482,11 @@ public static function adapters(): array 'write' => static function (array $list, array $old): bool { // WP Super Cache's own add and remove for plugin files it loads. foreach (array_diff($old, $list) as $file) { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoke WP Super Cache's own cache-plugin registration action. do_action('wpsc_delete_plugin', $file); } foreach (array_diff($list, $old) as $file) { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoke WP Super Cache's own cache-plugin registration action. do_action('wpsc_add_plugin', $file); } return true; diff --git a/includes/class-webdecoy-request-counts.php b/includes/class-webdecoy-request-counts.php index f91c0ee..15481b2 100644 --- a/includes/class-webdecoy-request-counts.php +++ b/includes/class-webdecoy-request-counts.php @@ -71,7 +71,7 @@ public static function matches_response(string $outcome, int $status): bool public static function table(): string { global $wpdb; - return esc_sql($wpdb->prefix . 'webdecoy_request_counts'); + return $wpdb->prefix . 'webdecoy_request_counts'; } /** Final response accounting cannot interfere with the protection response. */ @@ -97,7 +97,7 @@ public static function flush(): void if (!self::ready()) { return; } - $table = self::table(); + $table = esc_sql(self::table()); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned outcome counters; writes/retention must persist and setup/status summaries deliberately read current receipt totals. $wpdb->query($wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Identifier derives only from the trusted WordPress table prefix; values remain prepared. @@ -162,7 +162,7 @@ public static function summary(int $days): array return $result; } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); $detections = esc_sql($wpdb->prefix . 'webdecoy_detections'); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin-owned outcome counters; writes/retention must persist and setup/status summaries deliberately read current receipt totals. $rows = $wpdb->get_results($wpdb->prepare( @@ -188,7 +188,7 @@ public static function prune(): void return; } global $wpdb; - $table = self::table(); + $table = esc_sql(self::table()); $window = self::window(self::RETENTION_DAYS); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table identifier comes only from the trusted WordPress prefix; cutoff is prepared. $wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE bucket < %s", $window['from'])); diff --git a/includes/class-webdecoy-traffic-report.php b/includes/class-webdecoy-traffic-report.php index 3b9f382..470239f 100644 --- a/includes/class-webdecoy-traffic-report.php +++ b/includes/class-webdecoy-traffic-report.php @@ -35,7 +35,7 @@ public static function read(int $days): array $referral_ready = version_compare($version, WebDecoy_AI_Referrals::SINCE_DB_VERSION, '>='); // phpcs:disable WordPress.DB.DirectDatabaseQuery -- Admin-only aggregates cached for 60 seconds below. if ($crawler_ready) { - $table = WebDecoy_Crawler_Visits::table(); + $table = esc_sql(WebDecoy_Crawler_Visits::table()); $crawler_rows = $wpdb->get_results($wpdb->prepare( "SELECT DATE(bucket) AS day, agent_id, verification, SUM(hits) AS hits FROM {$table} WHERE bucket >= %s GROUP BY DATE(bucket), agent_id, verification", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped plugin-owned table name. $start . ' 00:00:00' @@ -43,7 +43,7 @@ public static function read(int $days): array $crawler_ready = is_array($crawler_rows); } if ($referral_ready) { - $table = WebDecoy_AI_Referrals::days_table(); + $table = esc_sql(WebDecoy_AI_Referrals::days_table()); $referral_rows = $wpdb->get_results($wpdb->prepare( "SELECT day, platform, landing_path, SUM(referrals) AS referrals FROM {$table} WHERE day >= %s GROUP BY day, platform, landing_path", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped plugin-owned table name. $start diff --git a/includes/class-webdecoy-violation-reporter.php b/includes/class-webdecoy-violation-reporter.php index 0b0d04d..4720409 100644 --- a/includes/class-webdecoy-violation-reporter.php +++ b/includes/class-webdecoy-violation-reporter.php @@ -190,7 +190,7 @@ private static function acquire_drain_lock(): bool private static function drain_locked(string $apiKey): void { global $wpdb; - $table = $wpdb->prefix . 'webdecoy_violation_queue'; + $table = esc_sql($wpdb->prefix . 'webdecoy_violation_queue'); // Enforce the hard cap first: discard the oldest overflow so a prolonged // ingest outage can't grow the table without bound. diff --git a/includes/wpsc-crawler-bypass.php b/includes/wpsc-crawler-bypass.php index 7e9cbed..040363f 100644 --- a/includes/wpsc-crawler-bypass.php +++ b/includes/wpsc-crawler-bypass.php @@ -40,7 +40,7 @@ function webdecoy_wpsc_cache_init(): void require_once __DIR__ . '/class-webdecoy-page-cache.php'; if (WebDecoy_Page_Cache::ua_matches($ua, WebDecoy_Page_Cache::crawler_tokens())) { - $cache_enabled = false; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- WP Super Cache's own per-request switch. + $cache_enabled = false; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WP Super Cache's own per-request switch. } } diff --git a/sdk/src/AgentRegistry.php b/sdk/src/AgentRegistry.php index 810374f..63ac41b 100644 --- a/sdk/src/AgentRegistry.php +++ b/sdk/src/AgentRegistry.php @@ -42,10 +42,7 @@ private static function table(): array if (self::$table === null) { $loaded = require __DIR__ . '/registry/agents.generated.php'; if (!is_array($loaded) || (int) ($loaded['schema'] ?? 0) !== self::SCHEMA) { - throw new \RuntimeException( - 'WebDecoy agent registry schema mismatch: expected ' . self::SCHEMA - . ', found ' . (string) ($loaded['schema'] ?? 'none') - ); + throw new \RuntimeException('WebDecoy agent registry schema mismatch. Rebuild the plugin with a compatible registry.'); } self::$table = $loaded; } diff --git a/templates/block-page.php b/templates/block-page.php index 6ee21d9..8887b20 100644 --- a/templates/block-page.php +++ b/templates/block-page.php @@ -8,6 +8,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This template is included by block_request(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/templates/challenge-page.php b/templates/challenge-page.php index d970bbe..45416a4 100644 --- a/templates/challenge-page.php +++ b/templates/challenge-page.php @@ -16,6 +16,8 @@ * @package WebDecoy */ +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- This template is included by serve_challenge_page(). Its variables stay in that method. + // Prevent direct access if (!defined('ABSPATH')) { exit; diff --git a/uninstall.php b/uninstall.php index cb97534..2231370 100644 --- a/uninstall.php +++ b/uninstall.php @@ -16,9 +16,9 @@ global $wpdb; // Load the activator class if not already loaded -$activator_file = __DIR__ . '/includes/class-webdecoy-activator.php'; -if (file_exists($activator_file)) { - require_once $activator_file; +$webdecoy_activator_file = __DIR__ . '/includes/class-webdecoy-activator.php'; +if (file_exists($webdecoy_activator_file)) { + require_once $webdecoy_activator_file; // Use the uninstall method if available if (class_exists('WebDecoy_Activator') && method_exists('WebDecoy_Activator', 'uninstall')) { @@ -28,7 +28,7 @@ // Fallback: manually clean up if activator not available // Drop custom tables - $tables = [ + $webdecoy_tables = [ $wpdb->prefix . 'webdecoy_blocked_ips', $wpdb->prefix . 'webdecoy_detections', $wpdb->prefix . 'webdecoy_rate_limits', @@ -39,9 +39,9 @@ $wpdb->prefix . 'webdecoy_ai_referral_days', ]; - foreach ($tables as $table) { + foreach ($webdecoy_tables as $webdecoy_table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name is safe, built from $wpdb->prefix - $wpdb->query("DROP TABLE IF EXISTS {$table}"); + $wpdb->query("DROP TABLE IF EXISTS {$webdecoy_table}"); } // Delete plugin options @@ -83,13 +83,13 @@ // For multisite, clean up each site if (is_multisite()) { - $sites = get_sites(['fields' => 'ids']); + $webdecoy_sites = get_sites(['fields' => 'ids']); - foreach ($sites as $site_id) { - switch_to_blog($site_id); + foreach ($webdecoy_sites as $webdecoy_site_id) { + switch_to_blog($webdecoy_site_id); // Drop tables for this site - $tables = [ + $webdecoy_tables = [ $wpdb->prefix . 'webdecoy_blocked_ips', $wpdb->prefix . 'webdecoy_detections', $wpdb->prefix . 'webdecoy_rate_limits', @@ -100,9 +100,9 @@ $wpdb->prefix . 'webdecoy_ai_referral_days', ]; - foreach ($tables as $table) { + foreach ($webdecoy_tables as $webdecoy_table) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name is safe, built from $wpdb->prefix - $wpdb->query("DROP TABLE IF EXISTS {$table}"); + $wpdb->query("DROP TABLE IF EXISTS {$webdecoy_table}"); } // Delete options for this site diff --git a/webdecoy.php b/webdecoy.php index 3609c34..59dba7a 100644 --- a/webdecoy.php +++ b/webdecoy.php @@ -53,51 +53,51 @@ function str_starts_with(string $haystack, string $needle): bool require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-diagnostics.php'; // Load the SDK (bundled) -$sdk_paths = [ +$webdecoy_sdk_paths = [ WEBDECOY_PLUGIN_DIR . 'sdk/', ]; -$sdk_loaded = false; -foreach ($sdk_paths as $sdk_path) { +$webdecoy_sdk_loaded = false; +foreach ($webdecoy_sdk_paths as $webdecoy_sdk_path) { // Try Composer autoloader first - if (file_exists($sdk_path . 'vendor/autoload.php')) { - require_once $sdk_path . 'vendor/autoload.php'; - $sdk_loaded = true; + if (file_exists($webdecoy_sdk_path . 'vendor/autoload.php')) { + require_once $webdecoy_sdk_path . 'vendor/autoload.php'; + $webdecoy_sdk_loaded = true; break; } // Fall back to manual includes - if (file_exists($sdk_path . 'src/Client.php')) { - require_once $sdk_path . 'src/Exception/WebDecoyException.php'; - require_once $sdk_path . 'src/Detection.php'; - require_once $sdk_path . 'src/DetectionResult.php'; - require_once $sdk_path . 'src/AgentRegistry.php'; - require_once $sdk_path . 'src/LlmReferral.php'; - require_once $sdk_path . 'src/HitExplanation.php'; - require_once $sdk_path . 'src/GoodBotList.php'; - require_once $sdk_path . 'src/RouteResolution.php'; - require_once $sdk_path . 'src/SignalCollector.php'; - require_once $sdk_path . 'src/BotDetector.php'; - require_once $sdk_path . 'src/Client.php'; + if (file_exists($webdecoy_sdk_path . 'src/Client.php')) { + require_once $webdecoy_sdk_path . 'src/Exception/WebDecoyException.php'; + require_once $webdecoy_sdk_path . 'src/Detection.php'; + require_once $webdecoy_sdk_path . 'src/DetectionResult.php'; + require_once $webdecoy_sdk_path . 'src/AgentRegistry.php'; + require_once $webdecoy_sdk_path . 'src/LlmReferral.php'; + require_once $webdecoy_sdk_path . 'src/HitExplanation.php'; + require_once $webdecoy_sdk_path . 'src/GoodBotList.php'; + require_once $webdecoy_sdk_path . 'src/RouteResolution.php'; + require_once $webdecoy_sdk_path . 'src/SignalCollector.php'; + require_once $webdecoy_sdk_path . 'src/BotDetector.php'; + require_once $webdecoy_sdk_path . 'src/Client.php'; // Rules engine (tripwires, filters, rate-limit rules) — pure logic. - require_once $sdk_path . 'src/Rules/RuleInterface.php'; - require_once $sdk_path . 'src/Rules/RuleContext.php'; - require_once $sdk_path . 'src/Rules/RuleResult.php'; - require_once $sdk_path . 'src/Rules/RuleEngineResult.php'; - require_once $sdk_path . 'src/Rules/ViolationEvent.php'; - require_once $sdk_path . 'src/Rules/RuleEngine.php'; - require_once $sdk_path . 'src/Rules/TripwireRule.php'; + require_once $webdecoy_sdk_path . 'src/Rules/RuleInterface.php'; + require_once $webdecoy_sdk_path . 'src/Rules/RuleContext.php'; + require_once $webdecoy_sdk_path . 'src/Rules/RuleResult.php'; + require_once $webdecoy_sdk_path . 'src/Rules/RuleEngineResult.php'; + require_once $webdecoy_sdk_path . 'src/Rules/ViolationEvent.php'; + require_once $webdecoy_sdk_path . 'src/Rules/RuleEngine.php'; + require_once $webdecoy_sdk_path . 'src/Rules/TripwireRule.php'; // Filter expression language (tokenizer → parser → evaluator). - require_once $sdk_path . 'src/Rules/Filter/FilterSyntaxException.php'; - require_once $sdk_path . 'src/Rules/Filter/Tokenizer.php'; - require_once $sdk_path . 'src/Rules/Filter/Parser.php'; - require_once $sdk_path . 'src/Rules/Filter/Evaluator.php'; - require_once $sdk_path . 'src/Rules/FilterRule.php'; - $sdk_loaded = true; + require_once $webdecoy_sdk_path . 'src/Rules/Filter/FilterSyntaxException.php'; + require_once $webdecoy_sdk_path . 'src/Rules/Filter/Tokenizer.php'; + require_once $webdecoy_sdk_path . 'src/Rules/Filter/Parser.php'; + require_once $webdecoy_sdk_path . 'src/Rules/Filter/Evaluator.php'; + require_once $webdecoy_sdk_path . 'src/Rules/FilterRule.php'; + $webdecoy_sdk_loaded = true; break; } } -if (!$sdk_loaded) { +if (!$webdecoy_sdk_loaded) { add_action('admin_notices', function () { echo '
'; echo '' . esc_html__('WebDecoy:', 'webdecoy') . ' ' . esc_html__('SDK not found. Please reinstall the plugin.', 'webdecoy');