/** * Validate specific property before set. * * @since 1.0.0 * @param string $property The name of a property to associate. * @param mixed $value The value of a property. */ public function __set($property, $value) { if (property_exists($this, $property)) { switch ($property) { case 'rule_type': if (in_array($value, MS_Model_Rule::get_rule_types())) { $this->{$property} = $value; } break; case 'dripped': if (is_array($value)) { $this->{$property} = $value; } break; default: $this->{$property} = $value; break; } } do_action('ms_rule__set_after', $property, $value, $this); }
protected function available_content_panel_data() { $membership = $this->data['membership']; $rule_types = MS_Model_Rule::get_rule_types(); ?> <div class="ms-settings ms-group"> <div class="ms-group"> <?php foreach ($rule_types as $rule_type) { $rule = $membership->get_rule($rule_type); if (!$rule->is_active()) { continue; } if ($rule->has_rules()) { $this->content_box($rule); } } ?> </div> </div> <?php 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', 'membership2'), 'url' => $payment_url, 'class' => 'wpmui-field-button button')); } }
/** * Get protection rules sorted. * * First one has priority over the last one. * These rules are used to determine access. * * @since 1.0.0 * @internal */ private function get_rules_hierarchy() { $rule_types = MS_Model_Rule::get_rule_types(); $rules = array(); $subscription = MS_Factory::load('MS_Model_Relationship', $this->subscription_id); foreach ($rule_types as $rule_type) { $rule = $this->get_rule($rule_type); if ($rule->rule_type != $rule_type) { // This means that the $rule_type was not found... continue; } // Sometimes the $subscription->id can be 0, which is intentional: // This is the case when the membership was auto-assigned to guest // or default membership. $rule->_subscription_id = $subscription->id; $rule->membership_id = $this->id; $rules[$rule_type] = $rule; } return apply_filters('ms_model_membership_get_rules_hierarchy', $rules, $this); }
/** * Load all the rules that are used by the plugin. * * Related Action Hooks: * - ms_init_done * * @since 1.0.0 */ public function setup_rules() { // Make sure we stick to the correct workflow. if (!did_action('ms_init_done')) { throw new Exception('setup_rules() is called too early.', 1); return; } do_action('ms_initialize_rules', $this); $rule_types = MS_Model_Rule::get_rule_types(); foreach ($this->member->subscriptions as $subscription) { foreach ($rule_types as $rule_type) { $rule = $subscription->get_membership()->get_rule($rule_type); } } }