request( '/plugin/privacy/email-export', array( 'email' => strtolower( trim( $email ) ), 'site_url' => $site_url, ) ); } /** * Request erasure of ActionPanel AI data by email. * * @param string $email Account email address. * @param string $site_url Site URL for scoping the request. */ public function erase_by_email( string $email, string $site_url ): array { return $this->request( '/plugin/privacy/email-erase', array( 'email' => strtolower( trim( $email ) ), 'site_url' => $site_url, ) ); } /** * Send a JSON request to a privacy API path. * * @param string $path API path. * @param array $payload Request payload. */ private function request( string $path, array $payload ): array { $url = $this->api_endpoint_resolver->get_base_url() . $path; $response = wp_remote_post( $url, array( 'timeout' => 15, 'redirection' => 0, 'headers' => array( 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-ActionPanel-AI-Service-Token' => $this->settings->ensure_privacy_service_token(), ), 'body' => wp_json_encode( $payload ), ) ); if ( is_wp_error( $response ) ) { return array( 'ok' => false, 'status' => 0, 'error' => $response->get_error_message(), 'data' => array(), ); } $status = (int) wp_remote_retrieve_response_code( $response ); $body = (string) wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); if ( ! is_array( $data ) ) { $data = array(); } $ok = $status >= 200 && $status < 300; $error = ''; if ( ! $ok ) { $error = (string) ( $data['detail'] ?? $data['message'] ?? __( 'Privacy API request failed.', 'actionpanel-ai' ) ); } return array( 'ok' => $ok, 'status' => $status, 'error' => $error, 'data' => $data, ); } }