Example #1
0
 /**
  * Saves a record to storage.
  *
  * @param \WordPress\Data\ModelInterface $model
  */
 public function save(ModelInterface $model)
 {
     $data = $model->getModelData();
     if ($model->ID) {
         $result = wp_update_post($data);
     } else {
         $result = wp_insert_post($data);
     }
     return $result;
 }
Example #2
0
 /**
  * Saves a record to storage.
  *
  * @param \WordPress\Data\ModelInterface $model
  */
 public function save(ModelInterface $model)
 {
     if (!$model->name || !$model->object_type) {
         throw new \RuntimeException("Taxonomy must have 'name' and 'object_type' fields");
     }
     $result = register_taxonomy($model->name, $model->object_type, $model->getModelData());
     if ($result && is_wp_error($result)) {
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * Saves a record to storage.
  *
  * @param \WordPress\Data\ModelInterface $model
  */
 public function save(ModelInterface $model)
 {
     if ($model->ID) {
         $result = wp_update_user($model->getModelData());
     } else {
         $result = wp_insert_user($model->getModelData());
         if (is_int($result)) {
             $model->ID = $result;
         }
     }
     if ($result && is_wp_error($result)) {
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Saves a record to storage.
  *
  * @param \WordPress\Data\ModelInterface $model
  */
 public function save(ModelInterface $model)
 {
     if (!$model->taxonomy) {
         throw new \RuntimeException("Term must have 'taxonomy' field.");
     }
     if ($model->term_id) {
         $result = wp_update_term($model->term_id, $model->taxonomy, $model->getModelData());
     } else {
         if (!$model->name) {
             throw new \RuntimeException("New terms must have 'name' field to insert.");
         }
         $result = wp_insert_term($model->name, $model->taxonomy, $model->getModelData());
         if (is_array($result)) {
             $model->hydrate($result);
         }
     }
     if ($result && is_wp_error($result)) {
         return false;
     }
     return true;
 }