| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP Controller |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Onboarding\Controllers; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
die('No direct access.'); |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* The controller for interacting with WordPress. |
| 14 |
*/ |
| 15 |
class WPController |
| 16 |
{ |
| 17 |
|
| 18 |
/** |
| 19 |
* Parse theme.json file. |
| 20 |
* |
| 21 |
* @param \WP_REST_Request $request - The request. |
| 22 |
* @return \WP_REST_Response |
| 23 |
*/ |
| 24 |
public static function parseThemeJson($request) |
| 25 |
{ |
| 26 |
if (!$request->get_param('themeJson')) { |
| 27 |
return new \WP_Error('invalid_theme_json', __('Invalid Theme.json file', 'extendify')); |
| 28 |
} |
| 29 |
|
| 30 |
$themeJson = new \WP_Theme_JSON(json_decode($request->get_param('themeJson'), true), ''); |
| 31 |
return new \WP_REST_Response([ |
| 32 |
'success' => true, |
| 33 |
'styles' => $themeJson->get_stylesheet(), |
| 34 |
]); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Persist the data |
| 39 |
* |
| 40 |
* @param \WP_REST_Request $request - The request. |
| 41 |
* @return \WP_REST_Response |
| 42 |
*/ |
| 43 |
public static function updateOption($request) |
| 44 |
{ |
| 45 |
$params = $request->get_json_params(); |
| 46 |
\update_option($params['option'], $params['value']); |
| 47 |
return new \WP_REST_Response(['success' => true]); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get a setting from the options table |
| 52 |
* |
| 53 |
* @param \WP_REST_Request $request - The request. |
| 54 |
* @return \WP_REST_Response |
| 55 |
*/ |
| 56 |
public static function getOption($request) |
| 57 |
{ |
| 58 |
$value = \get_option($request->get_param('option'), null); |
| 59 |
return new \WP_REST_Response([ |
| 60 |
'success' => true, |
| 61 |
'data' => $value, |
| 62 |
]); |
| 63 |
} |
| 64 |
} |
| 65 |
|