/** * Proccess submission * * @since 0.1.0 * * @param array $config Processor config * @param array $form Form config * * @return array */ function cf_postmatic_process($config, $form, $transdata) { if (!class_exists('Prompt_Api')) { $x = 1; return array('type' => 'error', 'note' => __('Postmatic is not active.', 'cf-postmatic')); } global $cf_postmatic_notice; $_message = Caldera_Forms::do_magic_tags($config['success_message']); if (!empty($_message)) { $message = $_message; } else { $message = __('Please check your email to confirm subscription.', 'cf-postmatic'); } $subscriber_data = array('email_address' => Caldera_Forms::do_magic_tags($config['email_address']), 'first_name' => Caldera_Forms::do_magic_tags($config['first_name']), 'last_name' => Caldera_Forms::do_magic_tags($config['last_name'])); $status = Prompt_Api::subscribe($subscriber_data); switch ($status) { case Prompt_Api::INVALID_EMAIL: return array('type' => 'error', 'note' => __("Invalid email address.", 'cf-postmatic')); break; case Prompt_Api::ALREADY_SUBSCRIBED: return array('type' => 'error', 'note' => __("This email address is already subscribed.", 'cf-postmatic')); break; case Prompt_Api::CONFIRMATION_SENT: $cf_postmatic_notice = array('type' => 'success', 'note' => $message); break; case Prompt_Api::OPT_IN_SENT: $cf_postmatic_notice = array('type' => 'success', 'note' => $message); break; } }
/** * The function that actually subscribe user to Postmatic * * @param $lead * @param $box_opts * * @return bool|string */ public function subscribe($lead, $box_opts) { // retrieve error global $postmatic_msg; $data = array('user_email' => $lead['email'], 'firs_tname' => '', 'last_name' => ''); // Setup name if set if (!empty($lead['name'])) { $names = explode(' ', $lead['name']); if (isset($names[0])) { $data['first_name'] = $names[0]; } if (isset($names[1])) { $data['last_name'] = $names[1]; } if (isset($names[2])) { $data['first_name'] = $names[0] . ' ' . $names[1]; $data['last_name'] = $names[2]; } } try { $result = Prompt_Api::subscribe($data); if (Prompt_Api::INVALID_EMAIL == $result || Prompt_Api::ALREADY_SUBSCRIBED == $result) { return $result; } return true; } catch (Exception $e) { return $e->getMessage(); } return true; }
function process_feed($feed, $entry, $form) { $first_name = $this->get_field_value($form, $entry, $feed['meta']['first_name']); $last_name = $this->get_field_value($form, $entry, $feed['meta']['last_name']); $email = $this->get_field_value($form, $entry, $feed['meta']['email']); $subscriber_data = array('email_address' => $email, 'first_name' => $first_name, 'last_name' => $last_name); Prompt_Api::subscribe($subscriber_data); }
/** * Process Postmatic submit * @param $result * @param $data * * @return bool */ function mab_process_postmatic_optin_submit($result, $data) { if (!class_exists('Prompt_Api') || empty($data['postmatic-action'])) { // postmatic plugin not installed or activated MAB_Ajax::addMessage('Something went wrong. Please contact the website owner.'); return false; } $user = array('user_email' => $data['email']); if (!empty($data['fname'])) { $user['first_name'] = $data['fname']; } if (!empty($data['lname'])) { $user['last_name'] = $data['lname']; } if ($data['postmatic-action'] == 'unsubscribe') { $status = Prompt_Api::unsubscribe($data['email']); switch ($status) { case Prompt_Api::NEVER_SUBSCRIBED: $result = false; MAB_Ajax::addMessage("Is that address correct? It wasn't ever subscribed."); break; case Prompt_Api::ALREADY_UNSUBSCRIBED: $result = true; MAB_Ajax::addMessage("You've already unsubscribed."); break; case Prompt_Api::CONFIRMATION_SENT: $result = true; MAB_Ajax::addMessage("You're now unsubscribed, and you'll get one last email confirming this."); break; } } else { $status = Prompt_Api::subscribe($user); switch ($status) { case Prompt_Api::INVALID_EMAIL: MAB_Ajax::addMessage('Email address is invalid.'); $result = false; break; case Prompt_Api::ALREADY_SUBSCRIBED: MAB_Ajax::addMessage("You are already subscribed, but we're glad you wanted to make sure."); $result = true; break; case Prompt_Api::CONFIRMATION_SENT: MAB_Ajax::addMessage("You're subscribed. Now check your email for confirmation."); $result = true; break; case Prompt_Api::OPT_IN_SENT: MAB_Ajax::addMessage("Great! Now check your email for the final step."); $result = true; break; } } return $result; }