activity_types = include plugin_dir_path(ATKAI_PLUGIN_FILE) . '/activities/types.php'; // Set up logger $this->logger = $logger; // Hook into the http_api_debug action to log HTTP requests add_action('http_api_debug', array($this, 'atk_log_http_requests'), 10, 5); } public function atk_log_http_requests($response, $context, $class, $args, $url) { // Only proceed for external requests if ($this->is_external_request($url)) { $user_id = get_current_user_id(); // Get the current user ID $method = isset($args['method']) ? strtolower($args['method']) : 'other'; $method = sanitize_text_field( $method ); // Determine activity type based on the request method $activity_type = isset($this->activity_types['api'][$method]) ? $this->activity_types['api'][$method] : 'unknown'; // Construct a description of the request $description = sprintf( "Response Code: %s; %s", is_wp_error($response) ? 'N/A' : '' . wp_remote_retrieve_response_code($response) . '', is_wp_error($response) ? 'Error: ' . $response->get_error_message() : (wp_remote_retrieve_response_code($response) == 200 ? 'Request was successful' : 'No error occurred') ); // Log the activity $this->logger->insert_log( $user_id, 'Api', $activity_type, $description, $method, $url ); } } private function is_external_request($url) { // Check if the request URL is external by comparing it to the site URL return strpos($url, home_url()) !== 0; } }