예제 #1
0
 public function _sync()
 {
     // check
     if ($class_vars = get_object_vars($this)) {
         // has options
         if (is_array($this->options)) {
             // loop
             foreach ($this->options as $option_name => $option_value) {
                 // check
                 if (in_array($option_name, $class_vars)) {
                     // array, needs merge
                     if (is_array($this->{$option_name})) {
                         // callback, to extend merging scenario for some optionswhich needs to overwrite default option vars
                         if (method_exists($this, '_option_merge_callback')) {
                             // invoke, name, current value, new value
                             $this->_option_merge_callback($option_name, $this->{$option_name}, $option_value);
                         } else {
                             // default, merge current value and new value
                             $this->{$option_name} = mgm_array_merge_recursive_unique($this->{$option_name}, $option_value);
                         }
                     } elseif (is_object($this->{$option_name})) {
                         // object, convert to array and merge. @TODO, needs test
                         $this->{$option_name} = (object) array_merge((array) mgm_object2array($this->{$option_name}), (array) $option_value);
                     } else {
                         // string, current value reset with new value
                         // set
                         $this->{$option_name} = $option_value;
                     }
                 }
             }
             // return
             return $this->options;
         }
     }
     // return
     return false;
 }
 /**
 * Overridden function:	
   See the comment below:
 *
 * @param string $option_name
 * @param array $current_value current value for class var(can be default)
 * @param array $option_value: updated value
 */
 function _option_merge_callback($option_name, $current_value, $option_value)
 {
     // This is to make sure that the default membership_type array doesn;t contain the hardcoded option 'member'
     // incase user deletes it and option array doesn't have it.
     // issue#: 521
     if ($option_name == 'membership_types') {
         //This is to copy from options:
         $current_value = array();
     }
     // update class var
     $this->{$option_name} = mgm_array_merge_recursive_unique($current_value, $option_value);
 }
예제 #3
0
 /**
  * Overridden function:	
  * See the comment below:
  *
  * @param string option_name name of option/var
  * @param array current_value current value for class var(can be default)
  * @param array new_value updated value
  */
 function _option_merge_callback($option_name, $current_value, $new_value)
 {
     // This is to make sure that active_modules['payment'] doesn't contain the default options incase user deletes disables any one of them.
     // issue#: 526
     switch ($option_name) {
         // active modules
         case 'active_modules':
             // to copy options array as it is:
             if (isset($new_value['payment'])) {
                 $current_value['payment'] = array();
             }
             break;
         case 'setting':
             // check array keys
             if (isset($new_value['rest_output_formats']) && isset($new_value['rest_input_methods'])) {
                 // reset
                 $current_value['rest_output_formats'] = $current_value['rest_input_methods'] = array();
             }
             // purchase options links
             if (isset($new_value['guest_content_purchase_options_links'])) {
                 // reset
                 $current_value['guest_content_purchase_options_links'] = array();
             }
             break;
     }
     // update class var
     $this->{$option_name} = mgm_array_merge_recursive_unique($current_value, $new_value);
 }