plugin_version = $plugin_version; } public function post( string $url, string $body, int $maximum_response_bytes, int $timeout_seconds ): array { if ( self::ENDPOINT !== $url || strlen( $body ) < 2 || strlen( $body ) > 524288 || $maximum_response_bytes < 2 || $maximum_response_bytes > 16384 || $timeout_seconds < 1 || $timeout_seconds > 20 ) { throw new \InvalidArgumentException( 'review_transport_boundary_invalid' ); } $response = wp_safe_remote_post( $url, array( 'timeout' => $timeout_seconds, 'redirection' => 0, 'sslverify' => true, 'headers' => array( 'Accept' => 'application/json', 'Content-Type' => 'application/json; charset=utf-8', 'User-Agent' => '320px-Site-Audit/' . $this->plugin_version . ' review-request', 'Cache-Control' => 'no-store', ), 'body' => $body, 'data_format' => 'body', 'limit_response_size' => $maximum_response_bytes, ) ); if ( is_wp_error( $response ) ) { throw new ExternalRequestException( 'review_request_failed' ); } $status = (int) wp_remote_retrieve_response_code( $response ); $reply = (string) wp_remote_retrieve_body( $response ); if ( strlen( $reply ) > $maximum_response_bytes ) { throw new ExternalRequestException( 'review_response_too_large' ); } return array( 'status' => $status, 'body' => $reply, ); } }