/** * Override Email send * * @param SendGrid\Email $email Email object with email info * @param SendGrid $sendgrid Sendgrid object with credentials info * @return array Array of results */ function wp_send(SendGrid\Email $email, $sendgrid) { $form = $email->toWebFormat(); $form['api_user'] = Sendgrid_Tools::get_username(); $form['api_key'] = Sendgrid_Tools::get_password(); $url = $sendgrid->url . $sendgrid->endpoint; $files = preg_grep('/files/', array_keys($form)); if (count($files) > 0) { if (in_array('curl', get_loaded_extensions())) { $response = $sendgrid->postRequest($sendgrid->endpoint, $form); $response = array('body' => $response->raw_body); } else { update_option('sendgrid_curl_option', 'disabled'); foreach ($files as $key => $value) { unset($form[$value]); } $data = array('body' => $form); $response = wp_remote_post($url, $data); } } else { $data = array('body' => $form); $response = wp_remote_post($url, $data); } return $response; }