| 1 |
<?php |
| 2 |
/** |
| 3 |
* Controls User info |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Library\Controllers; |
| 7 |
|
| 8 |
use Extendify\Library\SiteSettings; |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die('No direct access.'); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* The controller for managing Extendify SiteSettings. |
| 16 |
*/ |
| 17 |
class SiteSettingsController |
| 18 |
{ |
| 19 |
|
| 20 |
/** |
| 21 |
* Return Current SiteSettings meta data |
| 22 |
* |
| 23 |
* @return array |
| 24 |
*/ |
| 25 |
public static function show() |
| 26 |
{ |
| 27 |
$siteSettings = json_decode(SiteSettings::data(), true); |
| 28 |
// Keep the user sitetype in sync across all users. |
| 29 |
$siteType = \get_option('extendify_siteType', false); |
| 30 |
if ($siteType) { |
| 31 |
$siteSettings['state']['siteType'] = $siteType; |
| 32 |
} |
| 33 |
|
| 34 |
return new \WP_REST_Response(wp_json_encode($siteSettings)); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Persist the data |
| 39 |
* |
| 40 |
* @param \WP_REST_Request $request - The request. |
| 41 |
* @return array |
| 42 |
*/ |
| 43 |
public static function store($request) |
| 44 |
{ |
| 45 |
$settingsData = json_decode($request->get_param('data'), true); |
| 46 |
\update_option(SiteSettings::key(), $settingsData, true); |
| 47 |
return new \WP_REST_Response(SiteSettings::data()); |
| 48 |
} |
| 49 |
/** |
| 50 |
* Persist the data |
| 51 |
* |
| 52 |
* @param \WP_REST_Request $request - The request. |
| 53 |
* @return \WP_REST_Response |
| 54 |
*/ |
| 55 |
public static function updateOption($request) |
| 56 |
{ |
| 57 |
$params = $request->get_json_params(); |
| 58 |
\update_option($params['option'], $params['value']); |
| 59 |
return new \WP_REST_Response(['success' => true], 200); |
| 60 |
} |
| 61 |
} |
| 62 |
|