host = $options['host']; $this->endpoint = $options['endpoint']; $this->timeout = isset( $options['timeout'] ) ? $options['timeout'] : 30; $this->protocol = isset( $options['use_ssl'] ) && ( true === $options['use_ssl'] ) ? 'https' : 'http'; } /** * Send post request to the given host/endpoint using WordPress's HTTP API * * @param mixed[] $batch Batch of data to send to mixpanel. * * @return bool */ public function persist( $batch ) { if ( count( $batch ) <= 0 ) { return true; } $url = $this->protocol . '://' . $this->host . $this->endpoint; $data = 'data=' . $this->_encode( $batch ); $response = wp_remote_post( $url, [ 'timeout' => $this->timeout, 'body' => $data, ] ); if ( is_wp_error( $response ) ) { $this->_handleError( $response->get_error_code(), $response->get_error_message() ); return false; } return true; } }