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.
25 lines
457 B
PHP
25 lines
457 B
PHP
<?php
|
|
namespace MailPoet\Router;
|
|
use \MailPoet\Models\Setting;
|
|
|
|
if(!defined('ABSPATH')) exit;
|
|
|
|
class Settings {
|
|
function __construct() {
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|