Settings router.
Here's a simple settings router. the createOrUpdate method lives in the model, and by default all models will return true on save or false if save went wrong.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
use \MailPoet\Models\Setting;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@@ -7,12 +8,17 @@ class Settings {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function get($params) {
|
||||
$data = array(
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Mailer',
|
||||
'email' => 'john@mailpoet.com'
|
||||
);
|
||||
wp_send_json($params);
|
||||
function get() {
|
||||
$settings = Setting::find_array();
|
||||
wp_send_json($settings);
|
||||
}
|
||||
|
||||
function set($args) {
|
||||
$save = function($setting) {
|
||||
Setting::createOrUpdate($setting);
|
||||
};
|
||||
$results = array_map($save, $args);
|
||||
|
||||
wp_send_json(in_array(false, $results));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user