/** * Get protection Rule Model. * * Note for network-wide mode: * In DB the rules for each site are stored in different objects. * When loading a membership we will always load 1 instance of each * rule_type, and this is the instance that belongs to the current site! * Instances for other sites are not accessible. * -> This is why we do not use/need a site_id or similar in this function. * * @since 1.0.0 * @api * * @param string $rule_type The rule model type @see MS_Rule * @return MS_Rule The requested rule model. */ public function get_rule($rule_type) { if ('attachment' === $rule_type) { $rule_type = MS_Rule_Media::RULE_ID; } if (!isset($this->_rules[$rule_type]) || !is_object($this->_rules[$rule_type])) { // Create a new rule model object. $rule = MS_Rule::rule_factory($rule_type, $this->id, $this->subscription_id); $rule = apply_filters('ms_model_membership_get_rule', $rule, $rule_type, $this); $this->_rules[$rule_type] = $rule; if (!is_array($rule->rule_value)) { $rule->rule_value = array(); } } return $this->_rules[$rule_type]; }