/** * 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; }