sanitizeJsonData($this->request->post('data')); // persist $model on DB try { $command = new SaveSettingsCommand($data); $command->execute(); $httpStatus = 200; $return = [ 'success' => true ]; } catch (\Exception $exception) { do_action("acpt/error", $exception); $httpStatus = 500; $return = [ 'success' => false, 'error' => $exception->getMessage() ]; } wp_send_json($return, $httpStatus); } }