コード例 #1
0
 /**
  * Create a new record in the database.
  *
  * @param  array  $attributes  The attributes used to create the record.
  * @return calling class|false Returns an instance of the class, the record which was created, or false if the database create method failed.
  */
 public static function create(array $attributes)
 {
     global $wpdb;
     $current_time = self::current_mysql_time();
     $new_attributes = array();
     $new_attributes['created_at'] = $current_time;
     $new_attributes['updated_at'] = $current_time;
     $new_attributes['first_name'] = self::verify_input('first_name', $attributes);
     $new_attributes['last_name'] = self::verify_input('last_name', $attributes);
     $new_attributes['email'] = self::verify_input('email', $attributes, true);
     $new_attributes['referred_by_id'] = self::verify_input('referred_by_id', $attributes);
     $model_name = self::called_model_name();
     $model = new Referrer($new_attributes);
     if ($model->is_valid()) {
         $result = $wpdb->insert(self::table_name(), array('first_name' => $new_attributes['first_name'], 'last_name' => $new_attributes['last_name'], 'email' => $new_attributes['email'], 'type' => $model_name, 'referred_by_id' => $new_attributes['referred_by_id'], 'created_at' => $new_attributes['created_at'], 'updated_at' => $new_attributes['updated_at']), array('%s', '%s', '%s', '%s', '%s', '%s'));
         return $result !== false ? self::find_by_email($new_attributes['email']) : $result;
     } else {
         return $model;
     }
 }