moved logic from Subscribers router to model

This commit is contained in:
Jonathan Labreuille
2015-09-10 11:50:26 +02:00
parent 97db902529
commit 575e748d84
2 changed files with 24 additions and 15 deletions

View File

@ -34,22 +34,10 @@ class Subscribers {
}
function save($data = array()) {
$id = (isset($data['id']) ? (int)$data['id'] : 0);
$result = Subscriber::createOrUpdate($data);
if($id > 0) {
// update
$model = Subscriber::findOne($id);
$model->hydrate($data);
$saved = $model->save();
} else {
// new
$model = Subscriber::create();
$model->hydrate($data);
$saved = $model->save();
}
if($saved === false) {
wp_send_json($model->getValidationErrors());
if($result !== true) {
wp_send_json($result);
} else {
wp_send_json(true);
}