/** * Process the form for backend and frontend * * 1. Validates the data * 2. Creates a KWSContact contact object * 3. Validate the email based on settings * 4. If valid, add/update * * @uses KWSConstantContact::addUpdateContact() To add/update contact * @todo Return contact on success. * @return WP_Error|KWSContact Returns a WP error if error, otherwise a contact object. */ function process() { $this->id = NULL; // Check that the form was submitted if (is_admin()) { // Validate nonce from the Profile page $valid_nonce = wp_verify_nonce($_POST['_wpnonce'], 'update-user_' . $_POST['user_id']); $this->id = !empty($_POST['user_id']) && $valid_nonce ? $_POST['user_id'] : false; } else { $this->id = isset($_POST['uniqueformid']) ? esc_attr($_POST['uniqueformid']) : false; } if (empty($this->id)) { return false; } // Validate the POST data $this->data = $this->sanitizePost(); // Create the contact $KWSContact = new KWSContact($this->data); $this->checkRequired(); $this->validatePhone($KWSContact); // Check If Email Is Real $this->validateEmail($KWSContact); $this->is_processed = true; // If validation failed, stop processing if (!empty($this->errors)) { return; } // Otherwise, let's Add/Update $result = KWSConstantContact::getInstance()->addUpdateContact($KWSContact); if (is_wp_error($result)) { $this->errors[] = $result; $this->results = false; } else { $this->results = $result; } if (empty($this->results)) { return; } $this->maybe_redirect(); }