/** * Prepare html fields. * * @since 1.0.0 * * @return array */ function prepare_fields() { $invoice = $this->data['invoice']; $currency = MS_Plugin::instance()->settings->currency; $user_name = ''; $transaction_link = ''; $user_id = 0; $user_list = array(); if ($invoice->id) { $member = $invoice->get_member(); $user_id = $member->id; $user_name = $member->name; $transaction_link = sprintf('<a href="%s" target="_blank">%s</a>', MS_Controller_Plugin::get_admin_url('billing', array('show' => 'logs', 'invoice' => $invoice->id)), __('Show Transactions', 'membership2')); } else { $user_list = MS_Model_Member::get_usernames(null, MS_Model_Member::SEARCH_ALL_USERS); } $fields = array('link_transactions' => array('id' => 'link_transactions', 'title' => $transaction_link, 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'wrapper_class' => 'ms-transactions-link'), 'txt_user' => array('id' => 'txt_user', 'title' => __('Invoice for member', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TEXT, 'value' => sprintf('<a href="%s">%s</a>', MS_Controller_Plugin::get_admin_url('add-member', array('user_id' => $user_id)), $user_name)), 'txt_membership' => array('id' => 'txt_membership', 'title' => __('Payment for membership', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TEXT), 'txt_created' => array('id' => 'txt_created', 'title' => __('Invoice created on', 'membership2'), 'type' => MS_Helper_Html::TYPE_HTML_TEXT), 'txt_separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'status' => array('id' => 'status', 'title' => __('Invoice status', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'field_options' => MS_Model_Invoice::get_status_types(true), 'value' => $invoice->status), 'user_id' => array('id' => 'user_id', 'title' => __('Invoice for member', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $invoice->user_id, 'field_options' => $user_list), 'membership_id' => array('id' => 'membership_id', 'title' => __('Payment for membership', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $invoice->membership_id, 'field_options' => $this->data['memberships']), 'amount' => array('id' => 'amount', 'title' => sprintf(__('Amount (%s)', 'membership2'), $currency), 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER, 'value' => MS_Helper_Billing::format_price($invoice->amount), 'config' => array('step' => 'any', 'min' => 0)), 'discount' => array('id' => 'discount', 'title' => sprintf(__('Discount (%s)', 'membership2'), $currency), 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER, 'value' => MS_Helper_Billing::format_price($invoice->discount), 'config' => array('step' => 'any', 'min' => 0)), 'due_date' => array('id' => 'due_date', 'title' => __('Due date', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $invoice->due_date), 'description' => array('id' => 'description', 'title' => __('Description', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'class' => 'widefat', 'value' => $invoice->description), 'notes' => array('id' => 'notes', 'title' => __('Notes', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT_AREA, 'class' => 'widefat', 'value' => $invoice->get_notes_desc()), 'invoice_id' => array('id' => 'invoice_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $invoice->id), '_wpnonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce($this->data['action'])), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $this->data['action']), 'separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'execute' => array('id' => 'execute', 'title' => __('Execute status change actions on Save (add/remove membership)', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX, 'value' => true), 'cancel' => array('id' => 'cancel', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'title' => __('Cancel', 'membership2'), 'value' => __('Cancel', 'membership2'), 'url' => esc_url_raw(remove_query_arg(array('action', 'invoice_id'))), 'class' => 'wpmui-field-button button'), 'submit' => array('id' => 'submit', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save Changes', 'membership2'))); if ($invoice->id > 0) { $fields['user_id']['type'] = MS_Helper_Html::INPUT_TYPE_HIDDEN; $fields['membership_id']['type'] = MS_Helper_Html::INPUT_TYPE_HIDDEN; $fields['txt_membership']['value'] = $this->data['memberships'][$invoice->membership_id]; $fields['txt_created']['value'] = MS_Helper_Period::format_date($invoice->invoice_date); } else { unset($fields['txt_user']); unset($fields['txt_membership']); unset($fields['txt_created']); unset($fields['txt_separator']); } return apply_filters('ms_view_billing_edit_prepare_fields', $fields, $this); }
/** * Prepare html fields. * * @since 1.0.0 * * @return array */ function prepare_fields() { $invitation = $this->data['invitation']; if (!$invitation->is_valid()) { $invitation->code = substr(md5(time()), 0, 20); } $fields = array('code' => array('id' => 'code', 'title' => __('Invitation code', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'value' => $invitation->code, 'class' => 'widefat'), 'start_date' => array('id' => 'start_date', 'title' => __('Start date', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $invitation->start_date ? $invitation->start_date : MS_Helper_Period::current_date(), 'class' => 'ms-date'), 'expire_date' => array('id' => 'expire_date', 'title' => __('Expire date', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $invitation->expire_date, 'class' => 'ms-date'), 'membership_id' => array('id' => 'membership_id', 'title' => __('Invitation can be applied to these Memberships', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX, 'field_options' => $this->data['memberships'], 'value' => $invitation->membership_id), 'max_uses' => array('id' => 'max_uses', 'title' => __('Max uses', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER, 'value' => $invitation->max_uses, 'config' => array('step' => '1', 'min' => 0)), 'invitation_id' => array('id' => 'invitation_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $invitation->id), '_wpnonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce($this->data['action'])), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $this->data['action']), 'separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'cancel' => array('id' => 'cancel', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'title' => __('Cancel', MS_TEXT_DOMAIN), 'value' => __('Cancel', MS_TEXT_DOMAIN), 'url' => remove_query_arg(array('action', 'invitation_id')), 'class' => 'wpmui-field-button button'), 'submit' => array('id' => 'submit', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save Changes', MS_TEXT_DOMAIN))); return apply_filters('ms_addon_invitation_view_edit_prepare_fields', $fields, $this); }
/** * Check membership status. * * Execute actions when time/period condition are met. * E.g. change membership status, add communication to queue, create invoices. * * This check is called via a cron job. * * @since 1.0.0 * @internal Used by Cron * @see MS_Model_Plugin::check_membership_status() */ public function check_membership_status() { do_action('ms_model_relationship_check_membership_status_before', $this); /** * Use `define( 'MS_LOCK_SUBSCRIPTIONS', true );` in wp-config.php to prevent * Membership2 from sending *any* emails to users. * Also any currently enqueued message is removed from the queue * * @since 1.0.0 */ if (MS_Plugin::get_modifier('MS_LOCK_SUBSCRIPTIONS')) { return false; } $membership = $this->get_membership(); $remaining_days = $this->get_remaining_period(); $remaining_trial_days = $this->get_remaining_trial_period(); $comms = MS_Model_Communication::get_communications($membership); $invoice_before_days = 5; //@todo create a setting to configure this period. $deactivate_expired_after_days = 30; //@todo create a setting to configure this period. $deactivate_pending_after_days = 30; //@todo create a setting to configure this period. $deactivate_trial_expired_after_days = 5; //@todo create a setting to configure this period. //@todo: Add a flag to subscriptions with sent communications. Then improve the conditions below to prevent multiple emails. do_action('ms_check_membership_status-' . $this->status, $this, $remaining_days, $remaining_trial_days); // Update the Subscription status. $next_status = $this->calculate_status(null); switch ($next_status) { case self::STATUS_TRIAL: if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL) && MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_AUTO_MSGS_PLUS)) { // Send trial end communication. $comm = $comms[MS_Model_Communication::COMM_TYPE_BEFORE_TRIAL_FINISHES]; if ($comm->enabled) { $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); //@todo: This will send out the reminder multiple times on the reminder-day (4 times or more often) if ($days == $remaining_trial_days) { $comm->add_to_queue($this->id); MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_BEFORE_TRIAL_FINISHES, $this); } } } // Check for card expiration $gateway = $this->get_gateway(); $gateway->check_card_expiration($this); break; case self::STATUS_TRIAL_EXPIRED: if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_TRIAL)) { // Mark the trial period as completed. $this->save() is below. $this->trial_period_completed = true; // Request payment to the gateway (for gateways that allows it). $gateway = $this->get_gateway(); /* * The subscription will be either automatically activated * or set to pending. * * Important: Set trial_period_completed=true before calling * request_payment()! */ if ($gateway->request_payment($this)) { $next_status = self::STATUS_ACTIVE; $this->status = $next_status; $this->config_period(); // Needed because of status change. } // Check for card expiration $gateway->check_card_expiration($this); // Deactivate expired memberships after a period of time. if ($deactivate_trial_expired_after_days < -$remaining_trial_days) { $this->deactivate_membership(); } } break; case self::STATUS_ACTIVE: case self::STATUS_EXPIRED: case self::STATUS_CANCELED: /* * Make sure the expire date has a correct value, in case the user * changed the payment_type of the parent membership after this * subscription was created. */ if ($this->payment_type != $membership->payment_type) { $this->payment_type = $membership->payment_type; switch ($this->payment_type) { case MS_Model_Membership::PAYMENT_TYPE_PERMANENT: $this->expire_date = false; break; default: // Either keep the current expire date (if valid) or // calculate a new expire date, based on current date. if (!$this->expire_date) { $this->expire_date = $this->calc_expire_date(MS_Helper_Period::current_date()); } break; } // Recalculate the days until the subscription expires. $remaining_days = $this->get_remaining_period(); // Recalculate the new Subscription status. $next_status = $this->calculate_status(); } /* * Only "Recurring" memberships will ever try to automatically * renew the subscription. All other types will expire when the * end date is reached. */ $auto_renew = $membership->payment_type == MS_Model_Membership::PAYMENT_TYPE_RECURRING; $deactivate = false; $invoice = null; if ($auto_renew && $membership->pay_cycle_repetitions > 0) { /* * The membership has a payment-repetition limit. * When this limit is reached then we do not auto-renew the * subscription but expire it. */ $payments = $this->get_payments(); if (count($payments) >= $membership->pay_cycle_repetitions) { $auto_renew = false; } } if ($auto_renew) { if ($remaining_days < $invoice_before_days) { // Create a new invoice. $invoice = $this->get_next_invoice(); } else { $invoice = $this->get_current_invoice(); } } else { $invoice = $this->get_current_invoice(); } // Advanced communications Add-on. if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_AUTO_MSGS_PLUS)) { // Before finishes communication. $comm = $comms[MS_Model_Communication::COMM_TYPE_BEFORE_FINISHES]; $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); if ($days == $remaining_days) { $comm->add_to_queue($this->id); MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_BEFORE_FINISHES, $this); } // After finishes communication. $comm = $comms[MS_Model_Communication::COMM_TYPE_AFTER_FINISHES]; $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); if ($remaining_days < 0 && $days == abs($remaining_days)) { $comm->add_to_queue($this->id); MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_AFTER_FINISHES, $this); } // Before payment due. $comm = $comms[MS_Model_Communication::COMM_TYPE_BEFORE_PAYMENT_DUE]; $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); $invoice_days = MS_Helper_Period::subtract_dates($invoice->due_date, MS_Helper_Period::current_date()); if (MS_Model_Invoice::STATUS_BILLED == $invoice->status && $days == $invoice_days) { $comm->add_to_queue($this->id); MS_Model_Event::save_event(MS_Model_Event::TYPE_PAYMENT_BEFORE_DUE, $this); } // After payment due event $comm = $comms[MS_Model_Communication::COMM_TYPE_AFTER_PAYMENT_DUE]; $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); $invoice_days = MS_Helper_Period::subtract_dates($invoice->due_date, MS_Helper_Period::current_date()); if (MS_Model_Invoice::STATUS_BILLED == $invoice->status && $days == $invoice_days) { $comm->add_to_queue($this->id); MS_Model_Event::save_event(MS_Model_Event::TYPE_PAYMENT_AFTER_DUE, $this); } } // -- End of advanced communications Add-on // Subscription ended. See if we can renew it. if ($remaining_days <= 0) { if ($auto_renew) { /* * The membership can be renewed. Try to renew it * automatically by requesting the next payment from the * payment gateway (only works if gateway supports this) */ $gateway = $this->get_gateway(); $gateway->check_card_expiration($this); $gateway->request_payment($this); // Check if the payment was successful. $remaining_days = $this->get_remaining_period(); } /* * User did not renew the membership. Give him some time to * react before restricting his access. */ if ($deactivate_expired_after_days < -$remaining_days) { $deactivate = true; } } $next_status = $this->calculate_status(null); /* * When the subscription expires the first time then create a * new event that triggers the "Expired" email. */ if (self::STATUS_EXPIRED == $next_status && $next_status != $this->status) { MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_EXPIRED, $this); } elseif ($deactivate) { $this->deactivate_membership(); $next_status = $this->status; // Move membership to configured membership. $membership = $this->get_membership(); $new_membership = MS_Factory::load('MS_Model_Membership', $membership->on_end_membership_id); if ($new_membership->is_valid()) { $member = MS_Factory::load('MS_Model_Member', $this->user_id); $new_subscription = $member->add_membership($membership->on_end_membership_id, $this->gateway_id); MS_Model_Event::save_event(MS_Model_Event::TYPE_MS_MOVED, $new_subscription); /* * If the new membership is paid we want that the user * confirms the payment in his account. So we set it * to "Pending" first. */ if (!$new_membership->is_free()) { $new_subscription->status = self::STATUS_PENDING; } } } break; case self::STATUS_DEACTIVATED: /* * A subscription was finally deactivated. * Lets check if the member has any other active subscriptions, * or (if not) his account should be deactivated. * * First get a list of all subscriptions that do not have status * Pending / Deactivated. */ $subscriptions = self::get_subscriptions(array('user_id' => $this->user_id)); // Check if there is a subscription that keeps the user active. $deactivate = true; foreach ($subscriptions as $item) { if ($item->id == $this->id) { continue; } $deactivate = false; } if ($deactivate) { $member = $this->get_member(); $member->is_member = false; $member->save(); } break; case self::STATUS_PENDING: default: // Do nothing. break; } // Save the new status. $this->status = $next_status; $this->save(); // Save the changed email queue. foreach ($comms as $comm) { $comm->save(); } do_action('ms_model_relationship_check_membership_status_after', $this); }
/** * Prepare html fields. * * @since 1.0.0 * * @return array */ protected function prepare_fields() { $coupon = $this->data['coupon']; $fields = array('code' => array('id' => 'code', 'title' => __('Coupon code', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'value' => $coupon->code, 'class' => 'widefat'), 'discount' => array('id' => 'discount', 'title' => __('Discount', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER, 'value' => $coupon->discount, 'config' => array('step' => 'any', 'min' => 0)), 'discount_type' => array('id' => 'discount_type', 'title' => __('Discount Type', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'field_options' => $coupon->get_discount_types(), 'value' => $coupon->discount_type), 'start_date' => array('id' => 'start_date', 'title' => __('Start date', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $coupon->start_date ? $coupon->start_date : MS_Helper_Period::current_date(), 'class' => 'ms-date'), 'expire_date' => array('id' => 'expire_date', 'title' => __('Expire date', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'value' => $coupon->expire_date, 'class' => 'ms-date'), 'membership_id' => array('id' => 'membership_id', 'title' => __('Coupon can be applied to these Memberships', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX, 'field_options' => $this->data['memberships'], 'value' => $coupon->membership_id), 'max_uses' => array('id' => 'max_uses', 'title' => __('Max uses', 'membership2'), 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER, 'value' => $coupon->max_uses, 'config' => array('step' => '1', 'min' => 0)), 'coupon_id' => array('id' => 'coupon_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $coupon->id), '_wpnonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce($this->data['action'])), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $this->data['action']), 'separator' => array('type' => MS_Helper_Html::TYPE_HTML_SEPARATOR), 'cancel' => array('id' => 'cancel', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'title' => __('Cancel', 'membership2'), 'value' => __('Cancel', 'membership2'), 'url' => esc_url_raw(remove_query_arg(array('action', 'coupon_id'))), 'class' => 'wpmui-field-button button'), 'submit' => array('id' => 'submit', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => __('Save Changes', 'membership2'))); return apply_filters('ms_addon_coupon_view_edit_prepare_fields', $fields, $this); }
/** * Returns property associated with the render. * * @since 1.0.0 * @internal * * @param string $property The name of a property. * @return mixed Returns mixed value of a property or NULL if a property doesn't exist. */ public function __get($property) { $value = null; switch ($property) { case 'type': if (!self::is_valid_type($this->type)) { $this->type = self::TYPE_STANDARD; } $value = $this->type; break; case 'payment_type': $types = self::get_payment_types(); if (!array_key_exists($this->payment_type, $types)) { $this->payment_type = self::PAYMENT_TYPE_PERMANENT; } $value = $this->payment_type; break; case 'trial_period_enabled': case 'active': case 'private': case 'is_free': $value = lib3()->is_true($this->{$property}); break; case 'type_description': $value = $this->get_type_description(); break; case 'period_unit': $value = MS_Helper_Period::get_period_value($this->period, 'period_unit'); break; case 'period_type': $value = MS_Helper_Period::get_period_value($this->period, 'period_type'); break; case 'pay_cycle_period_unit': $value = MS_Helper_Period::get_period_value($this->pay_cycle_period, 'period_unit'); break; case 'pay_cycle_period_type': $value = MS_Helper_Period::get_period_value($this->pay_cycle_period, 'period_type'); break; case 'trial_period_unit': $value = MS_Helper_Period::get_period_value($this->trial_period, 'period_unit'); break; case 'trial_period_type': $value = MS_Helper_Period::get_period_value($this->trial_period, 'period_type'); break; case 'price': if ($this->is_free()) { $value = 0; } else { $value = $this->price; } break; case 'total_price': if ($this->is_free()) { $value = 0; } else { $value = $this->price; } $value = apply_filters('ms_apply_taxes', $value, $this); break; case 'pay_cycle_repetitions': $value = absint($this->pay_cycle_repetitions); break; case 'disabled_gateways': $value = lib3()->array->get($this->disabled_gateways); break; case 'is_paid': $value = !$this->is_free; break; case 'public': $value = !$this->private; break; default: if (property_exists($this, $property)) { $value = $this->{$property}; } break; } return apply_filters('ms_model_membership__get', $value, $property, $this); }
public function to_html() { /** * Provide a customized invoice. * * @since 1.0.0 */ $html = apply_filters('ms_shortcode_custom_invoice', '', $this->data); if (!empty($html)) { return $html; } else { $html = ''; } $invoice = $this->data['invoice']; $member = $this->data['member']; $subscription = $this->data['ms_relationship']; $membership = $this->data['membership']; $gateway = $this->data['gateway']; $is_free = false; $invoice_number = $invoice->get_invoice_number(); $inv_title = sprintf('<a href="%s">%s</a>', get_permalink($invoice->id), esc_html(__('Invoice ', MS_TEXT_DOMAIN) . $invoice_number)); if ($invoice->amount > 0) { $inv_amount = sprintf('%1$s %2$s', $invoice->currency, MS_Helper_Billing::format_price($invoice->amount)); } else { $inv_amount = __('Free', MS_TEXT_DOMAIN); $is_free = true; } if ($invoice->tax) { $inv_taxes = sprintf('%s %s', $invoice->currency, MS_Helper_Billing::format_price($invoice->tax)); } else { $inv_taxes = ''; } if ($invoice->discount) { $inv_discount = sprintf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->discount)); } else { $inv_discount = ''; } if ($invoice->pro_rate) { $inv_pro_rate = sprintf('%s -%s', $invoice->currency, MS_Helper_Billing::format_price($invoice->pro_rate)); } else { $inv_pro_rate = ''; } $inv_total = sprintf('%s %s', $invoice->currency, MS_Helper_Billing::format_price($invoice->total)); $inv_title = apply_filters('ms_invoice_title', $inv_title, $invoice); $inv_from = apply_filters('ms_invoice_sender', MS_Plugin::instance()->settings->invoice_sender_name, $invoice); $inv_to = apply_filters('ms_invoice_recipient', $member->username, $invoice, $member); $inv_status = apply_filters('ms_invoice_status', $invoice->status_text(), $invoice); $inv_item_name = apply_filters('ms_invoice_item_name', $membership->name, $invoice, $membership); $inv_amount = apply_filters('ms_invoice_amount', $inv_amount, $invoice); $inv_taxes = apply_filters('ms_invoice_taxes', $inv_taxes, $invoice); $inv_discount = apply_filters('ms_invoice_discount', $inv_discount, $invoice); $inv_pro_rate = apply_filters('ms_invoice_pro_rate', $inv_pro_rate, $invoice); $inv_total = apply_filters('ms_invoice_total', $inv_total, $invoice); $inv_details = apply_filters('ms_invoice_description', $invoice->description, $invoice, null); $inv_date = apply_filters('ms_invoice_date', MS_Helper_Period::format_date($invoice->invoice_date), $invoice, null); $inv_due_date = apply_filters('ms_invoice_due_date', MS_Helper_Period::format_date($invoice->due_date), $invoice, null); if ($invoice->uses_trial) { $trial_date = apply_filters('ms_invoice_trial_date', MS_Helper_Period::get_period_desc($membership->trial_period, true), $trial_invoice, $invoice); $trial_date .= sprintf(' <small>(%s %s)</small>', __('ends on', MS_TEXT_DOMAIN), MS_Helper_Period::format_date($invoice->trial_ends)); } else { $trial_date = ''; } ob_start(); ?> <div class="entry-content ms-invoice" id="invoice"> <?php /** * We hardcode the CSS styles into this file, because the shortcode * is also used in Emails, which usually do not load remote CSS * files by default... */ ?> <style> #invoice table, th, td { margin: 0; font-size: 14px; } #invoice table { padding: 0; width: 520px; border: 1px solid #DDD; background-color: #FFF; box-shadow: 0 1px 8px #F0F0F0; } #invoice th, td { border: 0; padding: 8px; } #invoice th { font-weight: bold; text-align: left; text-transform: none; font-size: 13px; } #invoice tr.alt { background-color: #F9F9F9; } #invoice tr.sep th, #invoice tr.sep td { border-top: 1px solid #DDD; padding-top: 16px; } #invoice tr.space th, #invoice tr.space td { padding-bottom: 16px; } #invoice tr.ms-inv-sep th, #invoice tr.ms-inv-sep td { line-height: 1px; height: 1px; padding: 0; border-bottom: 1px solid #DDD; background-color: #F9F9F9; } #invoice .ms-inv-total .ms-inv-price { font-weight: bold; font-size: 18px; text-align: right; } #invoice h2 { text-align: right; padding: 10px 10px 0 0; } #invoice h2 a { color: #000; } <?php do_action('ms_invoice_css'); ?> </style> <div class="ms-invoice-details ms-status-<?php echo esc_attr($invoice->status); ?> "> <table class="ms-purchase-table"> <tr class="ms-inv-title"> <td colspan="2"><h2><?php echo $inv_title; ?> </h2></td> </tr> <?php if (!empty($inv_from)) { ?> <tr class="ms-inv-from"> <th><?php _e('Sender', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-text"><?php echo $inv_from; ?> </td> </tr> <?php } ?> <tr class="ms-inv-to"> <th><?php _e('Invoice to', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-text"><?php echo $inv_to; ?> </td> </tr> <tr class="ms-inv-invoice-date"> <th><?php _e('Invoice date', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-date"><?php echo $inv_date; ?> </td> </tr> <?php if (!empty($trial_date)) { ?> <tr class="ms-inv-trial-end-date"> <th><?php _e('Trial period', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-date"><?php echo $trial_date; ?> </td> </tr> <?php } ?> <tr class="ms-inv-status space"> <th><?php _e('Status', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-text"><?php echo $inv_status; ?> </td> </tr> <tr class="ms-inv-item-name alt sep"> <th><?php _e('Name', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-text"><?php echo $inv_item_name; ?> </td> </tr> <?php if (!empty($inv_details)) { ?> <tr class="ms-inv-description alt"> <th><?php _e('Description', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-text"><?php echo $inv_details; ?> </td> </tr> <?php } ?> <tr class="ms-inv-amount alt space"> <th><?php _e('Amount', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-price"><?php echo $inv_amount; ?> </td> </tr> <?php $sep = 'sep'; ?> <?php if (!empty($inv_discount)) { ?> <tr class="ms-inv-discount <?php echo esc_attr($sep); $sep = ''; ?> "> <th><?php _e('Coupon discount', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-price"><?php echo $inv_discount; ?> </td> </tr> <?php } ?> <?php if (!empty($inv_pro_rate)) { ?> <tr class="ms-inv-pro-rate <?php echo esc_attr($sep); $sep = ''; ?> "> <th><?php _e('Pro rate discount', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-price"><?php echo $inv_pro_rate; ?> </td> </tr> <?php } ?> <?php if (!empty($inv_taxes)) { ?> <tr class="ms-inv-tax <?php echo esc_attr($sep); $sep = ''; ?> "> <th><?php printf(__('Taxes %s', MS_TEXT_DOMAIN), '<small>(' . $invoice->tax_name . ')</small>'); ?> </th> <td class="ms-inv-price"><?php echo $inv_taxes; ?> </td> </tr> <?php } ?> <?php if (!$is_free) { ?> <tr class="ms-inv-due-date <?php echo esc_attr($sep); $sep = ''; ?> "> <th><?php _e('Payment due', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-date"><?php echo $inv_due_date; ?> </td> </tr> <?php } ?> <tr class="ms-inv-total <?php echo esc_attr($sep); $sep = ''; ?> "> <th><?php _e('Total', MS_TEXT_DOMAIN); ?> </th> <td class="ms-inv-price"><?php echo $inv_total; ?> </td> </tr> <?php $show_button = lib2()->is_true($this->data['pay_button']); if ($invoice->is_paid()) { // Invoice is already paid. We don't need a payment // button... $show_button = false; } if ($show_button) { ?> <tr class="ms-inv-sep sep"><td colspan="2"></td></tr> <?php do_action('ms_view_shortcode_invoice_purchase_button', $subscription, $invoice); } ?> </table> </div> </div> <?php $html = ob_get_clean(); $html = apply_filters('ms_compact_code', $html); return apply_filters('ms_shortcode_invoice', $html, $this->data); }
/** * 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); }
/** * Check for card expiration date. * * Save event for card expire soon. * * @since 1.0.0 * * @access protected * @param MS_Model_Relationship $subscription The membership relationship. */ public function check_card_expiration($subscription) { do_action('ms_gateway_check_card_expiration_before', $this); $member = MS_Factory::load('MS_Model_Member', $subscription->user_id); $card_exp = $member->get_gateway_profile($this->id, 'card_exp'); if (!empty($card_exp)) { $comm = MS_Model_Communication::get_communication(MS_Model_Communication::COMM_TYPE_CREDIT_CARD_EXPIRE); $days = MS_Helper_Period::get_period_in_days($comm->period['period_unit'], $comm->period['period_type']); $card_expire_days = MS_Helper_Period::subtract_dates($card_exp, MS_Helper_Period::current_date(), DAY_IN_SECONDS, true); if ($card_expire_days < 0 || $days == $card_expire_days) { MS_Model_Event::save_event(MS_Model_Event::TYPE_CREDIT_CARD_EXPIRE, $subscription); } } do_action('ms_gateway_check_card_expiration_after', $this, $subscription); }
public function column_post_modified($item, $column_name) { $html = MS_Helper_Period::format_date($item->post_modified); return $html; }
public function column_due_date($item, $column_name) { $due_now = false; $is_paid = $item->is_paid(); if (!$is_paid) { $diff = MS_Helper_Period::subtract_dates($item->due_date, MS_Helper_Period::current_date(), null, true); $due_now = $diff < 0; } $due_date = MS_Helper_Period::format_date($item->due_date); if ($due_now) { $html = sprintf('<span class="due-now" title="%2$s">%1$s</span>', $due_date, __('Payment is overdue', 'membership2')); } elseif ($item->pay_date) { $pay_date = MS_Helper_Period::format_date($item->pay_date, 'M j, Y'); $html = sprintf('<span class="is-paid" title="%2$s">%1$s</span>', $due_date, sprintf(__('Paid: %s', 'membership2'), $pay_date)); } else { $html = sprintf('<span>%1$s</span>', $due_date); } return $html; }
/** * Output column content * * @since 1.0.0 * @param object $item The item that is displayed. * @return string The HTML code to output. */ public function column_date($item, $column_name) { $html = MS_Helper_Period::format_date($item->date, 'Y-m-d H:i'); return $html; }
public function available_content_panel_data() { $relative = array(); $absolute = array(); $membership = $this->data['membership']; $rule_types = MS_Model_Rule::get_dripped_rule_types(); foreach ($rule_types as $rule_type) { $rule = $membership->get_rule($rule_type); $contents = (array) $rule->get_contents(); foreach ($contents as $content) { if ($rule->has_dripped_rules($content->id)) { $infos = $rule->dripped[$content->id]; $key = false; $content->date = $rule->get_dripped_description($content->id); $content->icon = 'visibility'; switch ($infos['type']) { case MS_Model_Rule::DRIPPED_TYPE_FROM_REGISTRATION: $content->icon = 'clock'; $key = MS_Helper_Period::get_period_in_days($infos['delay_unit'], $infos['delay_type']); $key = 100000 + $key * 1000; while (isset($relative[$key])) { $key += 1; } $relative[$key] = $content; break; case MS_Model_Rule::DRIPPED_TYPE_SPEC_DATE: $key = preg_replace('/[^0-9]/', '', $infos['date']); if (!$rule->has_access($content->id)) { $content->icon = 'lock'; } // Fall through // Fall through case MS_Model_Rule::DRIPPED_TYPE_INSTANTLY: default: if (empty($key)) { $key = 0; } $key = $key * 1000; while (isset($relative[$key])) { $key += 1; } $absolute[$key] = $content; break; } } } } ?> <div class="clear"></div> <div class="cf"> <div class="ms-half ms-available-soon space"> <div class="ms-bold"> <i class="dashicons dashicons-calendar ms-low"></i> <?php _e('Available on a specific date:', MS_TEXT_DOMAIN); ?> </div> <div class="inside"> <?php $this->content_box($absolute); ?> </div> </div> <div class="ms-half ms-available"> <div class="ms-bold"> <i class="dashicons dashicons-clock ms-low"></i> <?php _e('Relative to registration:', MS_TEXT_DOMAIN); ?> </div> <div class="inside"> <?php $this->content_box($relative); ?> </div> </div> </div> <div class="cf"> <div class="ms-half"> <div class="inside"> <div class="ms-protection-edit-wrapper"> <?php $edit_url = MS_Controller_Plugin::get_admin_url('protection', array('tab' => $rule->rule_type, 'membership_id' => $membership->id)); MS_Helper_Html::html_element(array('id' => 'edit_dripped', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('Edit Dripped Content', MS_TEXT_DOMAIN), 'url' => $edit_url, 'class' => 'wpmui-field-button button')); if (!$membership->is_free) { $payment_url = esc_url_raw(add_query_arg(array('step' => MS_Controller_Membership::STEP_PAYMENT, 'edit' => 1))); MS_Helper_Html::html_element(array('id' => 'setup_payment', 'type' => MS_Helper_Html::TYPE_HTML_LINK, 'value' => __('Payment Options', MS_TEXT_DOMAIN), 'url' => $payment_url, 'class' => 'wpmui-field-button button')); } ?> </div> </div> </div> </div> <?php }
/** * Refreshes the due-date of the invoice. * * @since 1.0.0 */ public function set_due_date() { // Never change due-date of paid invoices. if ($this->is_paid()) { return; } $subscription = $this->get_subscription(); $due_date = false; // Handle special cases in due date calculation. switch ($subscription->status) { case MS_Model_Relationship::STATUS_TRIAL: $due_date = $subscription->trial_expire_date; break; case MS_Model_Relationship::STATUS_ACTIVE: case MS_Model_Relationship::STATUS_CANCELED: $due_date = $subscription->expire_date; break; } // Default due date is today. if (empty($due_date)) { if ($subscription->is_trial_eligible()) { /* * This invoice includes a trial period. * Payment is due on last day of trial */ $due_date = $subscription->trial_expire_date; } else { // No trial period is used for this invoice. Due now. $due_date = MS_Helper_Period::current_date(); } } // Update the trial expiration date. $this->trial_ends = $subscription->trial_expire_date; $this->due_date = $due_date; }
/** * Creates or updates a single payment plan on Stripe. * * This function is called when the gateway is activated and after a * membership was saved to database. * * @since 1.0.0 */ public function update_stripe_data_membership($membership) { if (!$this->active) { return false; } $this->_api->set_gateway($this); $plan_data = array('id' => self::get_the_id($membership->id, 'plan'), 'amount' => 0); if (!$membership->is_free() && $membership->payment_type == MS_Model_Membership::PAYMENT_TYPE_RECURRING) { // Prepare the plan-data for Stripe. $trial_days = null; if ($membership->has_trial()) { $trial_days = MS_Helper_Period::get_period_in_days($membership->trial_period_unit, $membership->trial_period_type); } $interval = 'day'; $max_count = 365; switch ($membership->pay_cycle_period_type) { case MS_Helper_Period::PERIOD_TYPE_WEEKS: $interval = 'week'; $max_count = 52; break; case MS_Helper_Period::PERIOD_TYPE_MONTHS: $interval = 'month'; $max_count = 12; break; case MS_Helper_Period::PERIOD_TYPE_YEARS: $interval = 'year'; $max_count = 1; break; } $interval_count = min($max_count, $membership->pay_cycle_period_unit); $settings = MS_Plugin::instance()->settings; $plan_data['amount'] = absint($membership->price * 100); $plan_data['currency'] = $settings->currency; $plan_data['name'] = $membership->name; $plan_data['interval'] = $interval; $plan_data['interval_count'] = $interval_count; $plan_data['trial_period_days'] = $trial_days; // Check if the plan needs to be updated. $serialized_data = json_encode($plan_data); $temp_key = substr('ms-stripe-' . $plan_data['id'], 0, 45); $temp_data = MS_Factory::get_transient($temp_key); if ($temp_data != $serialized_data) { MS_Factory::set_transient($temp_key, $serialized_data, HOUR_IN_SECONDS); $this->_api->create_or_update_plan($plan_data); } } }
/** * Prepare the PayPal IPN fields * * Details here: * https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/ * * @since 1.0.0 * @return array */ private function prepare_fields() { $subscription = $this->data['ms_relationship']; $membership = $subscription->get_membership(); if (0 === $membership->price) { return; } $gateway = $this->data['gateway']; $invoice = $subscription->get_current_invoice(); $regular_invoice = null; $settings = MS_Factory::load('MS_Model_Settings'); $nonce = wp_create_nonce($gateway->id . '_' . $subscription->id); $cancel_url = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REGISTER); $return_url = esc_url_raw(add_query_arg(array('ms_relationship_id' => $subscription->id), MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REG_COMPLETE, false))); $fields = array('_wpnonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $nonce), 'charset' => array('id' => 'charset', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'utf-8'), 'business' => array('id' => 'business', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $gateway->merchant_id), 'cmd' => array('id' => 'cmd', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => '_xclick-subscriptions'), 'bn' => array('id' => 'bn', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'incsub_SP'), 'item_name' => array('id' => 'item_name', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership->name), 'item_number' => array('id' => 'item_number', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership->id), 'currency_code' => array('id' => 'currency_code', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => MS_Plugin::instance()->settings->currency), 'return' => array('id' => 'return', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $return_url), 'cancel_return' => array('id' => 'cancel_return', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $cancel_url), 'notify_url' => array('id' => 'notify_url', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $gateway->get_return_url()), 'country' => array('id' => 'country', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $gateway->paypal_site), 'no_note' => array('id' => 'no_note', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 1), 'no_shipping' => array('id' => 'no_shipping', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 1), 'invoice' => array('id' => 'invoice', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $invoice->id)); $fields['submit'] = array('id' => 'submit', 'type' => MS_Helper_Html::INPUT_TYPE_IMAGE, 'value' => 'https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif', 'alt' => __('PayPal - The safer, easier way to pay online', 'membership2')); // custom pay button defined in gateway settings $custom_label = $gateway->pay_button_url; if (!empty($custom_label)) { if (false !== strpos($custom_label, '://')) { $fields['submit']['value'] = $custom_label; } else { $fields['submit'] = array('id' => 'submit', 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT, 'value' => $custom_label); } } // Trial period if ($subscription->is_trial_eligible()) { $fields['a1'] = array('id' => 'a1', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $invoice->trial_price); $trial_type = MS_Helper_Period::get_period_value($membership->trial_period, 'period_type'); $trial_type = strtoupper($trial_type[0]); $trial_value = MS_Helper_Period::get_period_value($membership->trial_period, 'period_unit'); $trial_value = MS_Helper_Period::validate_range($trial_value, $trial_type); $fields['p1'] = array('id' => 'p1', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $trial_value); $fields['t1'] = array('id' => 't1', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $trial_type); } // Membership price $membership_price = $invoice->total; $membership_price = MS_Helper_Billing::format_price($membership_price); $fields['a3'] = array('id' => 'a3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership_price); $fields['amount'] = array('id' => 'amount', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership_price); $recurring = 0; switch ($membership->payment_type) { // == RECURRING PAYMENTS case MS_Model_Membership::PAYMENT_TYPE_RECURRING: $period_type = MS_Helper_Period::get_period_value($membership->pay_cycle_period, 'period_type'); $period_type = strtoupper($period_type[0]); $period_value = MS_Helper_Period::get_period_value($membership->pay_cycle_period, 'period_unit'); $period_value = MS_Helper_Period::validate_range($period_value, $period_type); $fields['p3'] = array('id' => 'p3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_value); $fields['t3'] = array('id' => 't3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_type); // This makes the payments recurring! $recurring = 1; break; // == FINITE END DATE // == FINITE END DATE case MS_Model_Membership::PAYMENT_TYPE_FINITE: $period_type = MS_Helper_Period::get_period_value($membership->period, 'period_type'); $period_type = strtoupper($period_type[0]); $period_value = MS_Helper_Period::get_period_value($membership->period, 'period_unit'); $period_value = MS_Helper_Period::validate_range($period_value, $period_type); $fields['p3'] = array('id' => 'p3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_value); $fields['t3'] = array('id' => 't3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_type); break; // == DATE RANGE // == DATE RANGE case MS_Model_Membership::PAYMENT_TYPE_DATE_RANGE: $period_value = MS_Helper_Period::subtract_dates($membership->period_date_end, $membership->period_date_start); $period_value = MS_Helper_Period::validate_range($period_value, 'D'); $fields['p3'] = array('id' => 'p3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_value); $fields['t3'] = array('id' => 't3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'D'); break; // == PERMANENT // == PERMANENT case MS_Model_Membership::PAYMENT_TYPE_PERMANENT: /* * Permanent membership: Set the subscription range to 5 years! * PayPal requires us to provide the subscription range and the * maximum possible value is 5 years. */ $period_value = MS_Helper_Period::validate_range(5, 'Y'); $fields['p3'] = array('id' => 'p3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $period_value); $fields['t3'] = array('id' => 't3', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'Y'); break; } if (1 == $recurring) { if (1 == $membership->pay_cycle_repetitions) { $recurring = 0; } elseif ($membership->pay_cycle_repetitions > 1) { /** * Recurring times. * The number of times that a recurring payment is made. */ $fields['srt'] = array('id' => 'srt', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership->pay_cycle_repetitions); } } /** * Recurring field. * 0 - one time payment * 1 - recurring payments */ $fields['src'] = array('id' => 'src', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $recurring); /** * Modify current subscription field. * value != 0 does not allow trial period. * 0 - allows subscribers only to sign up for new subscriptions * 1 - allows subscribers to sign up for new subscriptions and modify their current subscriptions * 2 - allows subscribers to modify only their current subscriptions */ $modify = !empty($move_from_id); $fields['modify'] = array('id' => 'modify', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $modify ? 2 : 0); if ($gateway->is_live_mode()) { $this->data['action_url'] = 'https://www.paypal.com/cgi-bin/webscr'; } else { $this->data['action_url'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; } return apply_filters('ms_gateway_paypalstandard_view_prepare_fields', $fields); }
/** * Displays the inline-edit form used to edit the dripped content details. * * @since 1.0.0 */ protected function inline_edit() { $rule = $this->model; $membership = $this->membership; $field_action = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'action', 'value' => MS_Controller_Rule::AJAX_ACTION_UPDATE_DRIPPED); $field_rule = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'rule_type', 'value' => $this->model->rule_type); $field_item = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'item_id'); $field_offset = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'offset'); $field_number = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'number'); $field_filter = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'membership_id', 'value' => isset($_REQUEST['membership_id']) ? $_REQUEST['membership_id'] : ''); $field_id = array('type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'name' => 'membership_ids'); $field_type = array('type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'name' => 'dripped_type', 'class' => 'dripped_type', 'field_options' => MS_Model_Rule::get_dripped_types()); $field_date = array('type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER, 'name' => 'date', 'placeholder' => __('Date', 'membership2') . '...'); $field_delay_unit = array('type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'name' => 'delay_unit', 'class' => 'ms-text-small', 'placeholder' => '0'); $field_delay_type = array('type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'name' => 'delay_type', 'field_options' => MS_Helper_Period::get_period_types('plural'), 'after' => __('after subscription', 'membership2')); ?> <div> <h4> <span class="lbl-name"></span> - <?php _e('Dripped Content Settings', 'membership2'); ?> </h4> </div> <fieldset> <div class="inline-edit-col"> <?php MS_Helper_Html::html_element($field_action); MS_Helper_Html::html_element($field_rule); MS_Helper_Html::html_element($field_item); MS_Helper_Html::html_element($field_offset); MS_Helper_Html::html_element($field_number); MS_Helper_Html::html_element($field_filter); ?> <div class="dynamic-form"></div> </div> </fieldset> <div class="dripped-form cf no-auto-init hidden"> <div class="drip-col col-1"> <span class="the-name ms-membership"></span> <?php MS_Helper_Html::html_element($field_id); ?> </div> <div class="drip-col col-2"> <?php MS_Helper_Html::html_element($field_type); ?> </div> <div class="drip-col col-3"> <div class="drip-option <?php echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_INSTANTLY); ?> "> <?php _e('Instantly', 'membership2'); ?> </div> <div class="drip-option <?php echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_SPEC_DATE); ?> "> <?php MS_Helper_Html::html_element($field_date); ?> </div> <div class="drip-option <?php echo esc_attr(MS_Model_Rule::DRIPPED_TYPE_FROM_REGISTRATION); ?> "> <?php MS_Helper_Html::html_element($field_delay_unit); MS_Helper_Html::html_element($field_delay_type); ?> </div> </div> </div> </div> <?php }
/** * Overrides parent's to_html() method. * * @since 1.0.0 * * @return string */ public function to_html() { $fields = $this->prepare_fields(); $sim = $this->data['subscription']; $mem = $sim->get_membership(); $pay_types = $mem->get_payment_types(); if (is_admin()) { $toggle_icon = 'dashicons-arrow-down'; $toggle_state = 'collapsed'; } else { $toggle_icon = 'dashicons-arrow-up'; $toggle_state = ''; } $details = lib2()->session->get('ms-access'); $denied_url = false; $deciding_membership = false; $deciding_rule = false; if (isset($details[1]) && !$details[1]['has_access']) { $denied_url = $details[1]['url']; $deciding_membership = $details[1]['deciding_membership']; $deciding_rule = $details[1]['deciding_rule']; } elseif (isset($details[0]) && $details[0]['has_access']) { $deciding_membership = $details[0]['deciding_membership']; $deciding_rule = $details[0]['deciding_rule']; } ob_start(); $this->output_scripts(); ?> <div class="ms-sim-info <?php echo esc_attr($toggle_state); ?> "> <div class="ms-sim-block"> <h4 class="toggle-wrap"> <?php _e('Simulation Overview', MS_TEXT_DOMAIN); ?> <span class="toggle"><i class="dashicons <?php echo esc_attr($toggle_icon); ?> "></i></span> </h4> <div class="ms-sim-body"> <form id="view-site-as" method="POST" class="inside"> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr> <th><?php _e('View as', MS_TEXT_DOMAIN); ?> </th> <td><?php MS_Helper_Html::html_element($fields['membership_id']); ?> </td> </tr> <?php if ($this->data['datepicker']) { ?> <tr> <th><?php _e('View on', MS_TEXT_DOMAIN); ?> </th> <td><?php MS_Helper_Html::html_element($fields['simulate_date']); ?> </td> </tr> <?php } ?> <tr> <th> </th> <td><button class="button"><?php _e('Update', MS_TEXT_DOMAIN); ?> </button></td> </tr> </table> <?php MS_Helper_Html::html_element($fields['action_field']); MS_Helper_Html::html_element($fields['nonce_field']); ?> </form> <h4 class="inside"> <?php _e('Simulated Membership', MS_TEXT_DOMAIN); ?> </h4> <table cellspacing="0" cellpadding="0" width="100%" border="0" class="inside"> <tr> <th><?php _e('Membership', MS_TEXT_DOMAIN); ?> </th> <td style="white-space: nowrap"><?php echo esc_html($mem->name); ?> </td> </tr> <tr> <th><?php _e('Type', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html($mem->get_type_description()); ?> </td> </tr> <tr> <th><?php _e('Start Date', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html($sim->start_date); ?> </td> </tr> <tr> <th><?php _e('Expire Date', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html($sim->expire_date); ?> </td> </tr> <?php if ($this->data['datepicker']) { ?> <tr> <th><?php _e('Simulated Date', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html(MS_Helper_Period::current_date()); ?> </td> </tr> <?php } ?> <tr> <th><?php _e('Status', MS_TEXT_DOMAIN); ?> </th> <td><?php if (MS_Model_Relationship::STATUS_ACTIVE == $sim->status) { $status_class = 'ms-sim-active'; } else { $status_class = 'ms-sim-inactive'; } printf('<span class="%1$s">%2$s</span>', $status_class, $sim->status); ?> </td> </tr> <tr> <th><?php _e('Payment model', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html($pay_types[$mem->payment_type]); ?> </td> </tr> <tr> <th><?php _e('Payment details', MS_TEXT_DOMAIN); ?> </th> <td><?php echo esc_html(strip_tags($sim->get_payment_description(null, true))); ?> </td> </tr> </table> </div> <div class="ms-sim-footer"> <div class="inside"> <?php $this->output_deciding_info($denied_url, $deciding_membership, $deciding_rule); ?> </div> <?php MS_Helper_Html::html_element($fields['exit_button']); ?> </div> </div> </div> <?php $html = ob_get_clean(); return apply_filters('ms_view_admin_bar_to_html', $html, $this); }
/** * 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); }
public function column_post_date($item, $column_name) { return MS_Helper_Period::format_date($item->post_date); }
/** * 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; }
public function column_post_date($item, $column_name) { return MS_Helper_Period::format_date($item->post_date, __('Y/m/d', MS_TEXT_DOMAIN)); }
public function column_due_date($item, $column_name) { $due_now = false; if (!$item->is_paid()) { $diff = MS_Helper_Period::subtract_dates($item->due_date, MS_Helper_Period::current_date(), null, true); $due_now = $diff < 0; } $date = MS_Helper_Period::format_date($item->due_date); if ($due_now) { $html = sprintf('<span class="due-now" title="%2$s">%1$s</span>', $date, __('Payment is overdue', MS_TEXT_DOMAIN)); } else { $html = sprintf('<span>%1$s</span>', $date); } return $html; }
public function to_html() { ob_start(); ?> <div class="ms-account-wrapper"> <?php if (MS_Model_Member::is_logged_in()) { ?> <h2> <?php _e('Invoice', MS_TEXT_DOMAIN); ?> </h2> <table> <thead> <tr> <th class="ms-col-invoice-no"><?php _e('Invoice #', MS_TEXT_DOMAIN); ?> </th> <th class="ms-col-invoice-status"><?php _e('Status', MS_TEXT_DOMAIN); ?> </th> <th class="ms-col-invoice-total"><?php printf('%s (%s)', __('Total', MS_TEXT_DOMAIN), MS_Plugin::instance()->settings->currency); ?> </th> <th class="ms-col-invoice-title"><?php _e('Membership', MS_TEXT_DOMAIN); ?> </th> <th class="ms-col-invoice-due"><?php _e('Due date', MS_TEXT_DOMAIN); ?> </th> </tr> </thead> <tbody> <?php foreach ($this->data['invoices'] as $invoice) { $inv_membership = MS_Factory::load('MS_Model_Membership', $invoice->membership_id); $inv_classes = array('ms-invoice-' . $invoice->id, 'ms-subscription-' . $invoice->ms_relationship_id, 'ms-invoice-' . $invoice->status, 'ms-gateway-' . $invoice->gateway_id, 'ms-membership-' . $invoice->membership_id, 'ms-type-' . $inv_membership->type, 'ms-payment-' . $inv_membership->payment_type); ?> <tr class="<?php echo esc_attr(implode(' ', $inv_classes)); ?> "> <td class="ms-col-invoice-no"><?php printf('<a href="%s">%s</a>', get_permalink($invoice->id), $invoice->get_invoice_number()); ?> </td> <td class="ms-col-invoice-status"><?php echo esc_html($invoice->status_text()); ?> </td> <td class="ms-col-invoice-total"><?php echo esc_html(MS_Helper_Billing::format_price($invoice->total)); ?> </td> <td class="ms-col-invoice-title"><?php echo esc_html($inv_membership->name); ?> </td> <td class="ms-col-invoice-due"><?php echo esc_html(MS_Helper_Period::format_date($invoice->due_date, __('F j', MS_TEXT_DOMAIN))); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <?php $redirect = esc_url_raw(add_query_arg(array())); $title = __('Your account', MS_TEXT_DOMAIN); echo do_shortcode("[ms-membership-login redirect='{$redirect}' title='{$title}']"); ?> <?php } ?> </div> <?php $html = ob_get_clean(); $html = apply_filters('ms_compact_code', $html); return $html; }
/** * Echo a member-list. This function can be overwritten by other views * to customize the list. * * @since 1.0.0 * * @param array $members List of members to display. */ protected function members_panel_data($members, $membership_id) { $item = 0; $max_items = 10; $class = ''; $status_types = MS_Model_Relationship::get_status_types(); ?> <table class="ms-list-table widefat"> <thead> <th><?php _e('Member', 'membership2'); ?> </th> <th><?php _e('Since', 'membership2'); ?> </th> <th><?php _e('Status', 'membership2'); ?> </th> </thead> <tbody> <?php foreach ($this->data['members'] as $member) { $item += 1; if ($item > $max_items) { break; } $class = $class == 'alternate' ? '' : 'alternate'; $subscription = $member->get_subscription($membership_id); ?> <tr class="<?php echo esc_attr($class); ?> "> <td><?php echo esc_html($member->username); ?> </td> <td><?php echo esc_html(MS_Helper_Period::format_date($subscription->start_date)); ?> </td> <td><?php echo esc_html($status_types[$subscription->status]); ?> </td> </tr> <?php } ?> </tbody> </table> <?php }
/** * Returns a string that describes the dripped rule. * * @since 1.0.0 * * @param string $item_id The content id to verify dripped access. * @return string Text like "Instantly" or "After 7 days" */ public function get_dripped_description($item_id) { $desc = ''; $drip_data = false; if (!is_array($this->dripped)) { $this->dripped = array(); } if (isset($this->dripped[$item_id])) { $drip_data = $this->dripped[$item_id]; } if (is_array($drip_data)) { lib3()->array->equip($drip_data, 'type', 'date', 'delay_unit', 'delay_type'); switch ($drip_data['type']) { case MS_Model_Rule::DRIPPED_TYPE_SPEC_DATE: $desc = sprintf(__('On <b>%1$s</b>', 'membership2'), MS_Helper_Period::format_date($drip_data['date'])); break; case MS_Model_Rule::DRIPPED_TYPE_FROM_REGISTRATION: $periods = MS_Helper_Period::get_period_types(); $period_key = $drip_data['delay_type']; if (0 == $drip_data['delay_unit']) { $desc = __('<b>Instantly</b>', 'membership2'); } elseif (1 == $drip_data['delay_unit']) { $desc = sprintf(__('After <b>%1$s %2$s</b>', 'membership2'), $periods['1' . $period_key], ''); } else { $desc = sprintf(__('After <b>%1$s %2$s</b>', 'membership2'), $drip_data['delay_unit'], $periods[$period_key]); } break; case MS_Model_Rule::DRIPPED_TYPE_INSTANTLY: default: $desc = __('<b>Instantly</b>', 'membership2'); break; } } return apply_filters('ms_rule_get_dripped_description', $desc, $item_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); } }
/** * Prepare the fields that are displayed in the form. * * @since 1.0.1.0 * @return array */ protected function get_fields() { $comm = $this->data['comm']; $membership = false; $membership_id = 0; if (isset($this->data['membership'])) { $membership = $this->data['membership']; if ($membership instanceof MS_Model_Membership) { $membership_id = $membership->id; } else { $membership = false; } } lib2()->array->equip($comm, 'type', 'enabled', 'period', 'subject', 'description', 'cc_enabled', 'cc_email'); $action = MS_Controller_Communication::AJAX_ACTION_UPDATE_COMM; $nonce = wp_create_nonce($action); $comm_titles = MS_Model_Communication::get_communication_type_titles($membership); $key_active = __('Send Email', MS_TEXT_DOMAIN); $key_inactive = __('No Email', MS_TEXT_DOMAIN); $key_skip = __('Use default template', MS_TEXT_DOMAIN); $titles = array($key_active => array(), $key_inactive => array(), $key_skip => array()); foreach ($comm_titles as $type => $title) { $tmp_comm = MS_Model_Communication::get_communication($type, $membership, true); if ($membership && !$tmp_comm->override) { $titles[$key_skip][$type] = $title; } elseif ($tmp_comm->enabled) { $titles[$key_active][$type] = $title; } else { $titles[$key_inactive][$type] = $title; } } $fields = array('comm_type' => array('id' => 'comm_type', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->type, 'field_options' => $titles), 'switch_comm_type' => array('id' => 'switch_comm_type', 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON, 'value' => __('Load Template', MS_TEXT_DOMAIN)), 'override' => array('id' => 'override', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'value' => $comm->override, 'before' => __('Use default template', MS_TEXT_DOMAIN), 'after' => __('Define custom template', MS_TEXT_DOMAIN), 'wrapper_class' => 'ms-block ms-tcenter', 'class' => 'override-slider', 'ajax_data' => array('type' => $comm->type, 'field' => 'override', 'action' => $action, '_wpnonce' => $nonce, 'membership_id' => $membership_id)), 'membership_id' => array('id' => 'membership_id', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $membership_id), 'type' => array('id' => 'type', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => $comm->type), 'enabled' => array('id' => 'enabled', 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER, 'value' => $comm->enabled, 'class' => 'state-slider', 'before' => ' <i class="wpmui-fa wpmui-fa-ban"></i>', 'after' => '<i class="wpmui-fa wpmui-fa-envelope"></i> ', 'ajax_data' => array('type' => $comm->type, 'field' => 'enabled', 'action' => $action, '_wpnonce' => $nonce, 'membership_id' => $membership_id)), 'period_unit' => array('id' => 'period_unit', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => __('Period after/before', MS_TEXT_DOMAIN), 'value' => $comm->period['period_unit']), 'period_type' => array('id' => 'period_type', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->period['period_type'], 'field_options' => MS_Helper_Period::get_period_types('plural')), 'subject' => array('id' => 'subject', 'type' => MS_Helper_Html::INPUT_TYPE_TEXT, 'title' => apply_filters('ms_translation_flag', __('Message Subject', MS_TEXT_DOMAIN), 'communication-subject'), 'value' => $comm->subject, 'class' => 'ms-comm-subject widefat'), 'email_body' => array('id' => 'email_body', 'type' => MS_Helper_Html::INPUT_TYPE_WP_EDITOR, 'title' => apply_filters('ms_translation_flag', '', 'communication-body'), 'value' => $comm->description, 'field_options' => array('media_buttons' => false, 'editor_class' => 'wpmui-ajax-update')), 'cc_enabled' => array('id' => 'cc_enabled', 'type' => MS_Helper_Html::INPUT_TYPE_CHECKBOX, 'title' => __('Send copy to Administrator', MS_TEXT_DOMAIN), 'value' => $comm->cc_enabled, 'class' => 'ms-inline-block'), 'cc_email' => array('id' => 'cc_email', 'type' => MS_Helper_Html::INPUT_TYPE_SELECT, 'value' => $comm->cc_email, 'field_options' => MS_Model_Member::get_admin_user_emails()), 'save_email' => array('id' => 'save_email', 'value' => __('Save Changes', MS_TEXT_DOMAIN), 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT), 'action' => array('id' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'save_comm'), 'nonce' => array('id' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce('save_comm')), 'load_action' => array('id' => 'load_action', 'name' => 'action', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => 'load_action'), 'load_nonce' => array('id' => '_wpnonce1', 'name' => '_wpnonce', 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN, 'value' => wp_create_nonce('load_action'))); if (!$membership instanceof MS_Model_Membership) { unset($fields['override']); unset($fields['membership_id']); } return apply_filters('ms_view_settings_prepare_email_fields', $fields); }
public function to_html() { ob_start(); ?> <div class="ms-account-wrapper"> <?php if (MS_Model_Member::is_logged_in()) { ?> <h2> <?php _e('Activity', MS_TEXT_DOMAIN); ?> </h2> <table> <thead> <tr> <th class="ms-col-activity-date"><?php _e('Date', MS_TEXT_DOMAIN); ?> </th> <th class="ms-col-activity-title"><?php _e('Activity', MS_TEXT_DOMAIN); ?> </th> </tr> </thead> <tbody> <?php foreach ($this->data['events'] as $event) { $ev_classes = array('ms-activity-topic-' . $event->topic, 'ms-activity-type-' . $event->type, 'ms-membership-' . $event->membership_id); ?> <tr class="<?php echo esc_attr(implode(' ', $ev_classes)); ?> "> <td class="ms-col-activity-date"><?php echo esc_html(MS_Helper_Period::format_date($event->post_modified, __('F j (H:i)', MS_TEXT_DOMAIN))); ?> </td> <td class="ms-col-activity-title"><?php echo esc_html($event->description); ?> </td> </tr> <?php } ?> </tbody> </table> <?php } else { $redirect = esc_url_raw(add_query_arg(array())); $title = __('Your account', MS_TEXT_DOMAIN); echo do_shortcode("[ms-membership-login redirect='{$redirect}' title='{$title}']"); } ?> </div> <?php $html = ob_get_clean(); $html = apply_filters('ms_compact_code', $html); return $html; }
/** * Validate period type. * * @since 1.0.0 * * @param string $period_type The period type to validate. * @param int $default The default value when not validated. Default to days. */ public function validate_period_type($period_type, $default = MS_Helper_Period::PERIOD_TYPE_DAYS) { $valid_types = MS_Helper_Period::get_period_types(); if (!isset($valid_types[$period_type])) { $period_type = $default; } return apply_filters('ms_model_validate_period_type', $period_type, $this); }
public static function get_period_desc($period, $include_quanity_one = false) { $period_unit = MS_Helper_Period::get_period_value($period, 'period_unit'); $period_type = MS_Helper_Period::get_period_value($period, 'period_type'); $types = self::get_period_types(); if (1 == $period_unit) { $desc = '%2$s'; if ($include_quanity_one) { $period_type = $types['1' . $period_type]; } else { $period_type = $types['1-' . $period_type]; } } else { $desc = '%1$s %2$s'; } $desc = sprintf($desc, $period_unit, $period_type); return apply_filters('ms_helper_period_get_period_desc', $desc); }