/** * Verify if coupon is valid. * * Checks for maximun number of uses, date range and membership_id restriction. * * @since 1.0.0 * * @param int $membership_id The membership id for which coupon is applied * @return boolean True if valid coupon. */ public function is_valid($membership_id = 0) { $valid = true; $this->coupon_message = null; if ($this->_empty) { // No coupon-code entered, so don't do anything return; } $timestamp = MS_Helper_Period::current_time('timestamp'); if (empty($this->code)) { $this->coupon_message = __('Coupon code not found.', 'membership2'); $valid = false; } elseif ($this->max_uses && $this->used >= $this->max_uses) { $this->coupon_message = __('No Coupons remaining for this code.', 'membership2'); $valid = false; } elseif (!empty($this->start_date) && strtotime($this->start_date) > $timestamp) { $this->coupon_message = __('This Coupon is not valid yet.', 'membership2'); $valid = false; } elseif (!empty($this->expire_date) && strtotime($this->expire_date) < $timestamp) { $this->coupon_message = __('This Coupon has expired.', 'membership2'); $valid = false; } else { if (is_array($this->membership_id)) { foreach ($this->membership_id as $valid_id) { if (0 == $valid_id || $valid_id == $membership_id) { $membership_allowed = true; break; } } } elseif ('0' == $this->membership_id) { $membership_allowed = true; } if (!$membership_allowed) { $this->coupon_message = __('This Coupon is not valid for this membership.', 'membership2'); $valid = false; } } $this->_valid = $valid; return apply_filters('ms_coupon_model_is_valid', $valid, $membership_id, $this); }
/** * Subscribe a user to a Mailchimp list * * @since 1.0.0 * * @param MS_Model_Member $member * @param int $list_id */ public static function subscribe_user($member, $list_id) { if (is_email($member->email) && self::get_api_status()) { $auto_opt_in = self::$settings->get_custom_setting('mailchimp', 'auto_opt_in'); $auto_opt_in = lib2()->is_true($auto_opt_in); $update = apply_filters('ms_addon_mailchimp_subscribe_user_update', true, $member, $list_id); $merge_vars = array(); $merge_vars['FNAME'] = $member->first_name; $merge_vars['LNAME'] = $member->last_name; if ($auto_opt_in) { $merge_vars['optin_ip'] = $_SERVER['REMOTE_ADDR']; $merge_vars['optin_time'] = MS_Helper_Period::current_time(); } if (empty($merge_vars['FNAME'])) { unset($merge_vars['FNAME']); } if (empty($merge_vars['LNAME'])) { unset($merge_vars['LNAME']); } $merge_vars = apply_filters('ms_addon_mailchimp_subscribe_user_merge_vars', $merge_vars, $member, $list_id); $email_field = array('email' => $member->email); $res = self::$mailchimp_api->lists->subscribe($list_id, $email_field, $merge_vars, 'html', !$auto_opt_in, $update); } }
/** * Remove from queue. * * Delete history of sent messages after max is reached. * * @since 1.0.0 * * @param int $subscription_id The membership relationship ID to remove from queue. */ public function remove_from_queue($subscription_id) { do_action('ms_model_communication_remove_from_queue_before', $this); // Delete history if (count($this->sent_queue) > $max_history) { $this->sent_queue = array_slice($this->sent_queue, -100, $max_history, true); } $this->sent_queue[$subscription_id] = MS_Helper_Period::current_time(); unset($this->queue[$subscription_id]); $max_history = apply_filters('ms_model_communication_sent_queue_max_history', 200); do_action('ms_model_communication_remove_from_queue_after', $this); }
/** * Sets the manual-state value of the transaction log entry. * * @since 1.0.0 * @param string $state The new state of the item. * @return bool True on success. */ public function manual_state($state) { if ('err' != $this->_state) { // Not allowed: Only error state can be manually corrected. return false; } switch ($state) { case 'ignore': if ($this->manual_state) { // Not allowed: Manual state was defined already. return false; } break; case 'clear': if ('ignore' != $this->manual_state) { // Not allowed: Only "ingored" state can be cleared. return false; } break; case 'ok': if ($this->manual) { // Not allowed: Manual state is already defined. return false; } if (!$this->invoice_id || !$this->subscription_id) { // Not allowed: Required data is missing for OK status. return false; } break; default: // Not allowed: Unknown state. return false; } if ('clear' == $state) { $this->manual_state = ''; $this->manual_date = ''; $this->manual_user = 0; } else { $this->manual_state = $state; $this->manual_date = MS_Helper_Period::current_time(); $this->manual_user = get_current_user_id(); } return true; }
/** * Verify if invitation is valid. * * Checks for maximun number of uses, date range, if the user has used it * and if it exists. * * @since 1.0.0 * * @param int $membership_id * @return bool True if the invitation can be used for the membership. */ public function is_valid($membership_id = 0) { $valid = true; if (empty($this->code)) { $valid = false; } $timestamp = MS_Helper_Period::current_time('timestamp'); if ($this->max_uses && $this->used >= $this->max_uses) { $this->invitation_message = __('This invitation code is no longer valid.', 'membership2'); $valid = false; } elseif (!empty($this->start_date) && strtotime($this->start_date) > $timestamp) { $this->invitation_message = __('This invitation is not valid yet.', 'membership2'); $valid = false; } elseif (!empty($this->expire_date) && strtotime($this->expire_date) < $timestamp) { $this->invitation_message = __('This invitation has expired.', 'membership2'); $valid = false; } elseif (!$this->check_invitation_user_usage()) { $this->invitation_message = __('You have already used this invitation code.', 'membership2'); $valid = false; } elseif ($membership_id) { $membership_allowed = false; if (is_array($this->membership_id)) { foreach ($this->membership_id as $valid_id) { if (0 == $valid_id || $valid_id == $membership_id) { $membership_allowed = true; break; } } } elseif ('0' == $this->membership_id) { $membership_allowed = true; } if (!$membership_allowed) { $this->invitation_message = __('This Invitation is not valid for this membership.', 'membership2'); $valid = false; } else { $this->add_invitation_check(); } } return apply_filters('ms_invitation_model_is_valid', $valid, $this); }