/** * Merge current rules to Membership2. * * Assure the membership rules get updated whenever Membership2 is changed. * * @since 1.0.0 * @internal */ public function prepare_obj() { parent::prepare_obj(); if (false !== strpos($this->_factory_id, '_is_valid_')) { // This object only checks if the item ID is valid. // No need to load any rules yet... return; } foreach ($this->rule_values as $key => $values) { // Skip rules without any values. if (empty($values)) { continue; } // Network-wide: Only instanciate rules for the *current* site! if (!MS_Rule::is_current_site($key)) { continue; } // Key could be "type" of "site:type" format. $rule_type = MS_Rule::rule_type($key); // At this point we have an empty rule-instance $rule = $this->get_rule($rule_type); // Now we populate that rule-instance with site-specific settings. $rule->populate($values); } // validate rules using Membership2 rules if (!$this->is_base() && $this->is_valid()) { $this->merge_protection_rules(); } }