add_security_headers(); // Add CORS headers for REST API $origin = get_http_origin(); $allowed_origins = apply_filters('ai_job_listing_allowed_origins', [ home_url(), site_url(), // Add any additional allowed origins here ]); if ($origin) { // Allow configured origins if (in_array($origin, $allowed_origins, true)) { header('Access-Control-Allow-Origin: ' . esc_url_raw($origin)); header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE'); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Headers: Authorization, Content-Type, X-WP-Nonce'); // Get and sanitize request method following WP core standards $request_method = ''; if (isset($_SERVER['REQUEST_METHOD'])) { $request_method = strtoupper(sanitize_key(wp_unslash($_SERVER['REQUEST_METHOD']))); } if ('OPTIONS' === $request_method) { status_header(200); exit(); } } } return $served; } }