/** * Core render method, displays the form based on the shortcode input * * @param array $attr * * @return bool * @throws \Exception */ public function render($attr) { $defaults = array('type' => 'subscribe', 'fields' => '', 'database' => '', 'subscribegroup' => '', 'unsubscribegroup' => '', 'method' => 'move', 'id' => $this->getUniqueId(), 'submit' => false); $client = $this->getTripolisClient(); extract(shortcode_atts($defaults, $attr), EXTR_SKIP); switch (strtolower($attr['type'])) { case 'unsubscribe': $template = 'unsubscribe.php'; // Unsubscribe always requires the contact ID, tell people it is so. if (!isset($_GET['contactid'])) { if (isset($_GET['wptripolis-contact-removed'])) { $template = 'removed.php'; } else { _e('Please supply the Tripolis Contact ID in the link', 'tripolis'); return false; } } try { // Setup some stuff for templating $db = isset($attr['database']) ? $attr['database'] : false; $group = isset($attr['unsubscribegroup']) ? $attr['unsubscribegroup'] : false; TemplateWrapper::setContactId($_GET['contactid']); TemplateWrapper::setContactMeta($client->contact()->getById($_GET['contactid'], array(), $db)); TemplateWrapper::setSubscriptions($this->getContactGroupsAndSubscriptionStatus($client, $db, $_GET['contactid'], $group)); } catch (NotFoundException $e) { $template = 'removed.php'; } catch (\SoapFault $f) { _e('We could not find your subscriptions.', 'tripolis'); } catch (\TripolisException $e) { // Die gracefully if API barfs _e('We could not find your subscriptions.', 'tripolis'); return false; } catch (\Exception $e) { if (WP_DEBUG) { throw $e; } else { return false; } } break; case 'subscribe': default: if (!isset($fields)) { return false; } // Fields declared through extract(); $fields = explode(",", $fields); $fields = array_map('trim', $fields); $fieldDef = $this->getFieldDefinitions($client, $database, $fields); foreach ($fieldDef as $field) { if (isset($submit[$field['code']])) { $fieldDef[$field['code']]['class'][] = $submit[$field['code']]['class']; $fieldDef[$field['code']]['message'] = $submit[$field['code']]['message']; } } $template = 'subscribe.php'; TemplateWrapper::setFieldLoop($fieldDef); } $template = $this->findTemplate($template); require $template; return true; }