/**
  * @return bool
  */
 public function process()
 {
     $api = mc4wp_get_api();
     do_action('mc4wp_before_subscribe', $this->data['EMAIL'], $this->data, 0);
     $result = false;
     $email_type = $this->get_email_type();
     // loop through selected lists
     foreach ($this->list_fields_map as $list_id => $list_field_data) {
         // allow plugins to alter merge vars for each individual list
         $list_merge_vars = $this->get_list_merge_vars($list_id, $list_field_data);
         // send a subscribe request to MailChimp for each list
         $result = $api->subscribe($list_id, $this->data['EMAIL'], $list_merge_vars, $email_type, $this->form->settings['double_optin'], $this->form->settings['update_existing'], $this->form->settings['replace_interests'], $this->form->settings['send_welcome']);
         do_action('mc4wp_subscribe', $this->data['EMAIL'], $list_id, $list_merge_vars, $result, 'form', 'form', 0);
     }
     do_action('mc4wp_after_subscribe', $this->data['EMAIL'], $this->data, 0, $result);
     // did we succeed in subscribing with the parsed data?
     if (!$result) {
         $this->message_type = $api->get_error_code() === 214 ? 'already_subscribed' : 'error';
         $this->mailchimp_error = $api->get_error_message();
     } else {
         $this->message_type = 'subscribed';
         // store user email in a cookie
         MC4WP_Tools::remember_email($this->data['EMAIL']);
     }
     $this->success = $result;
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Process the request
  *
  * @return bool
  */
 public function process()
 {
     $api = mc4wp_get_api();
     if ($this->type === 'subscribe') {
         $success = $api->subscribe($this->list_id, $this->email, $this->merge_vars, $this->config['email_type'], $this->config['double_optin'], $this->config['update_existing'], $this->config['replace_interests'], $this->config['send_welcome']);
     } else {
         $success = $api->unsubscribe($this->list_id, $this->email, $this->config['send_goodbye'], $this->config['send_notification'], $this->config['delete_member']);
     }
     if ($success) {
         // store user email in a cookie
         // todo: decouple this
         MC4WP_Tools::remember_email($this->email);
     }
     // convert API response to our own response object
     $response = new MC4WP_API_Response($this->type, $success, $api->get_last_response());
     $this->response = $response;
     /**
      * @api
      * @action 'mc4wp_request_processed'
      *
      * @param Request
      * @param Response
      */
     do_action('mc4wp_request_processed', $this, $response);
     return $response;
 }