function set($input) { $valueObj = new Values(); foreach ($input as $slug => $value) { $where['slug'] = $slug; if (!is_array($value)) { $what['value'] = $value; } else { $what = $value; } if ($valueObj->get($where, ['id'])) { $output = $valueObj->update($where, $what); } else { $output = $valueObj->create(array_merge($where, $what)); } } return isset($output) && $output ? true : false; }
public function sgToggleFieldById() { $this->checkPermissions($_POST['_wpnonce'], 'sg-toggle-field-by-id'); $valuesObj = new Values(); $valuesObj->returnMessages = true; $what = []; foreach ($valuesObj->fields as $field => $type) { if (isset($_POST[$field])) { $what[$field] = $_POST[$field]; } } unset($what['id']); if (count($what)) { $output = $valuesObj->update(['id' => $_POST['id']], $what); $output['messages'] = $output['messages']['error']; } else { $output['result'] = 0; $output['messages'][] = __('Передано недостаточно данных'); } echo json_encode($output, JSON_UNESCAPED_UNICODE); die; }