is_static_asset()) { return; } // Get API key from database $api_key = get_option($this->option_name, ''); // Get selected continent $continent = get_option($this->continent_option, ''); // If no API key or continent is set, allow access if (empty($api_key) || empty($continent)) { return; } // Build URL with continent code $verification_url = 'https://engine-' . $continent . '-1.abyssguard.com'; // Collect visitor information from $_SERVER $visitor_ip = $this->get_visitor_ip(); $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : ''; $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : ''; $http_host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : ''; $referer = isset($_SERVER['HTTP_REFERER']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_REFERER'])) : ''; $request_method = isset($_SERVER['REQUEST_METHOD']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_METHOD'])) : ''; $accept = isset($_SERVER['HTTP_ACCEPT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT'])) : ''; $accept_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT_LANGUAGE'])) : ''; // Prepare HEAD request with visitor data in headers $response = wp_remote_head($verification_url, array( 'timeout' => 1, 'headers' => array( 'x-abyssguard' => $api_key, 'X-AbyssGuard-ip' => $visitor_ip, 'X-AbyssGuard-uri' => $request_uri, 'X-AbyssGuard-host' => $http_host, 'X-AbyssGuard-referer' => $referer, 'X-AbyssGuard-method' => $request_method, 'X-AbyssGuard-user-agent' => $user_agent, 'X-AbyssGuard-accept' => $accept, 'X-AbyssGuard-accept-language' => $accept_language, 'X-AbyssGuard-tech' => 'WordPress v1.0.0' ), 'sslverify' => true )); // Handle timeout or connection errors (allow access) if (is_wp_error($response)) { $error_message = $response->get_error_message(); // Log timeout/connection errors but allow access // error_log('AbyssGuard: Connection error - ' . $error_message); return; } // Get response code $response_code = wp_remote_retrieve_response_code($response); // If 403, block access if ($response_code === 403) { $this->block_access(); } // For 200 OK or any other response, continue normally // (including timeouts which are handled as wp_error above) return; } /** * Get visitor's real IP address * Checks for proxy headers first */ private function get_visitor_ip() { $ip_keys = array( 'HTTP_CF_CONNECTING_IP', // Cloudflare 'HTTP_X_FORWARDED_FOR', 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'REMOTE_ADDR' ); foreach ($ip_keys as $key) { if (isset($_SERVER[$key]) && !empty($_SERVER[$key])) { $ip = sanitize_text_field(wp_unslash($_SERVER[$key])); // Handle multiple IPs (X-Forwarded-For can contain multiple IPs) if (strpos($ip, ',') !== false) { $ip_list = explode(',', $ip); $ip = trim($ip_list[0]); } // Validate IP address if (filter_var($ip, FILTER_VALIDATE_IP)) { return $ip; } } } return ''; } /** * Check if current request is for a static asset */ private function is_static_asset() { $request_uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : ''; // Get file extension $path = parse_url($request_uri, PHP_URL_PATH); $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); // List of static file extensions to skip $static_extensions = array( // Images 'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'ico', 'bmp', 'tiff', // Stylesheets 'css', // Fonts 'woff', 'woff2', 'ttf', 'eot', 'otf', // Documents (if you want to skip them) 'pdf', 'doc', 'docx', 'xls', 'xlsx', // Media 'mp4', 'mp3', 'avi', 'mov', 'wmv', 'wav', 'ogg', // Archives 'zip', 'rar', 'tar', 'gz', ); // Check if the extension matches any static file type if (in_array($extension, $static_extensions)) { return true; } // Also check for common static file patterns $static_patterns = array( '/favicon\.ico$/', '/robots\.txt$/', '/sitemap.*\.xml$/', '/\.well-known\//', '/wp-content\/uploads\//', ); foreach ($static_patterns as $pattern) { if (preg_match($pattern, $request_uri)) { return true; } } return false; } /** * Block access with 403 response */ private function block_access() { status_header(403); nocache_headers(); exit; } /** * Add admin menu */ public function add_admin_menu() { add_options_page( esc_html__('AbyssGuard Settings', 'abyssguard'), esc_html__('AbyssGuard', 'abyssguard'), 'manage_options', 'abyssguard', array($this, 'render_admin_page') ); } /** * Register settings */ public function register_settings() { register_setting( 'svg_settings_group', $this->option_name, array( 'type' => 'string', 'sanitize_callback' => array($this, 'sanitize_api_key'), 'default' => '' ) ); register_setting( 'svg_settings_group', $this->continent_option, array( 'type' => 'string', 'sanitize_callback' => array($this, 'sanitize_continent'), 'default' => '' ) ); add_settings_section( 'svg_main_section', esc_html__('API Configuration', 'abyssguard'), array($this, 'render_section_description'), 'abyssguard' ); add_settings_field( 'abyssguard_api_key_field', esc_html__('API Key', 'abyssguard'), array($this, 'render_api_key_field'), 'abyssguard', 'svg_main_section' ); add_settings_field( 'svg_continent_field', esc_html__('GEO Node', 'abyssguard'), array($this, 'render_continent_field'), 'abyssguard', 'svg_main_section' ); } /** * Sanitize API key */ public function sanitize_api_key($value) { return sanitize_text_field($value); } /** * Sanitize continent code */ public function sanitize_continent($value) { $valid_continents = array('as', 'eu', 'na', 'oc', 'sa'); $value = strtolower(sanitize_text_field($value)); if (in_array($value, $valid_continents)) { return $value; } return ''; } /** * Get list of continents */ private function get_continents() { return array( '' => esc_html__('-- Select GEO Node --', 'abyssguard'), 'as' => esc_html__('Asia', 'abyssguard'), 'af' => esc_html__('Africa', 'abyssguard'), 'eu' => esc_html__('Europe', 'abyssguard'), 'na' => esc_html__('North America', 'abyssguard'), 'oc' => esc_html__('Oceania', 'abyssguard'), 'sa' => esc_html__('South America', 'abyssguard') ); } /** * Render section description */ public function render_section_description() { echo '

' .esc_html__('Get your API key by signing up for free at:', 'abyssguard') . ' AbyssGuard.

'; } /** * Render API key field */ public function render_api_key_field() { $api_key = get_option($this->option_name, ''); echo ''; } /** * Render continent field */ public function render_continent_field() { $selected_continent = get_option($this->continent_option, ''); $continents = $this->get_continents(); echo ''; } /** * Render admin page */ public function render_admin_page() { if (!current_user_can('manage_options')) { return; } settings_errors('svg_messages'); ?>

.

: option_name, ''); if (empty($api_key)) { echo '❌ ' . esc_html__('Not configured', 'abyssguard') . ''; } else { echo '✓ ' . esc_html__('Configured', 'abyssguard') . ''; } ?>

: continent_option, ''); if (empty($continent)) { echo '❌ ' . esc_html__('Not configured', 'abyssguard') . ''; } else { $continents = $this->get_continents(); echo '✓ ' . esc_html($continents[$continent]) . ''; } ?>

Settings'; array_unshift($links, $settings_link); return $links; } } // Initialize the plugin new AbyssGuard(); /** * Activation hook */ register_activation_hook(__FILE__, 'abyssguard_activate_plugin'); function abyssguard_activate_plugin() { // Set default options if needed if (get_option('abyssguard_api_key') === false) { add_option('abyssguard_api_key', ''); } } /** * Deactivation hook */ register_deactivation_hook(__FILE__, 'abyssguard_deactivate_plugin'); function abyssguard_deactivate_plugin() { // Cleanup if needed (optional) } /** * Uninstall hook - removes all data */ register_uninstall_hook(__FILE__, 'abyssguard_uninstall_plugin'); function abyssguard_uninstall_plugin() { delete_option('abyssguard_api_key'); }