コード例 #1
0
 /**
  * Class constructor.
  *
  * @since  1.0.0
  * @param int $membership_id The membership that owns this rule object.
  */
 public function __construct($membership_id)
 {
     parent::__construct();
     $this->membership_id = apply_filters('ms_rule_constructor_membership_id', $membership_id, $this);
     $membership = MS_Factory::load('MS_Model_membership', $membership_id);
     $this->is_base_rule = $membership->is_base();
     $this->initialize();
 }
コード例 #2
0
 /**
  * Validates the object right after it was loaded/initialized.
  *
  * We ensure that the custom_data field is an array.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     parent::prepare_obj();
     if (!is_array($this->custom_data)) {
         $this->custom_data = array();
     }
 }
コード例 #3
0
ファイル: logs_model.php プロジェクト: 827992983/ec
 /**
  * 构造函数
  */
 function __construct()
 {
     parent::__construct();
 }
コード例 #4
0
ファイル: class-ms-factory.php プロジェクト: klgrimley/mzf
 /**
  * Populate fields of the model
  *
  * @since  1.0.0
  *
  * @param  MS_Model $model
  * @param  array $settings
  * @param  bool $postmeta
  */
 public static function populate_model(&$model, $settings, $postmeta = false)
 {
     $fields = $model->get_object_vars();
     $class = get_class($model);
     $vars = get_class_vars($class);
     $saved_data = array();
     $ignore = isset($vars['ignore_fields']) ? $vars['ignore_fields'] : array();
     $ignore[] = 'instance';
     // Don't deserialize the double-serialized model!
     $ignore[] = 'actions';
     $ignore[] = 'filters';
     $ignore[] = 'ignore_fields';
     foreach ($fields as $field => $val) {
         if ('_' === $field[0] || in_array($field, $ignore)) {
             continue;
         }
         $value = null;
         if (false === $postmeta) {
             if (isset($settings[$field])) {
                 $value = $settings[$field];
             } elseif (isset($settings['_' . $field])) {
                 $value = $settings['_' . $field];
             }
         } elseif (true === $postmeta) {
             if (isset($settings[$field][0])) {
                 $value = $settings[$field][0];
             } elseif (isset($settings['_' . $field][0])) {
                 $value = $settings['_' . $field][0];
             }
         } elseif (is_string($postmeta)) {
             if (isset($settings[$postmeta . $field][0])) {
                 $value = $settings[$postmeta . $field][0];
             } elseif (isset($settings['_' . $postmeta . $field][0])) {
                 $value = $settings['_' . $postmeta . $field][0];
             }
         }
         if ($value) {
             $value = maybe_unserialize($value);
         }
         $saved_data[$field] = $value;
         if (null !== $value) {
             $model->set_field($field, $value);
         }
     }
     $model->_saved_data = $saved_data;
     /**
      * Filter the serialized data collection before it is returned.
      *
      * Typically it is written to database right after this function call,
      * so this hook allows us to modify data before it's written to the DB.
      *
      * @var object $model The completely populated object.
      * @var string $class Class name of the object.
      * @var array $settings The source data (serialized array).
      * @var bool|string $postmeta The post-meta flag defines how the
      *      $settings array is formatted.
      */
     $model = apply_filters('ms_factory_populate', $model, $class, $settings, $postmeta);
     $model = apply_filters('ms_factory_populate-' . strtolower($class), $model, $settings, $postmeta);
 }