| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin\api; |
| 4 |
|
| 5 |
use Leadin\api\Base_Api_Controller; |
| 6 |
use Leadin\data\Portal_Options; |
| 7 |
|
| 8 |
/** |
| 9 |
* Hublet Api. Used to fetch portal's hublet and update in case of region migration |
| 10 |
*/ |
| 11 |
class Hublet_Api_Controller extends Base_Api_Controller { |
| 12 |
|
| 13 |
/** |
| 14 |
* Class constructor, register route. |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
self::register_leadin_admin_route( |
| 18 |
'/hublet', |
| 19 |
\WP_REST_Server::EDITABLE, |
| 20 |
array( $this, 'update_hublet' ) |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Get's correct hublet and updates it in Options |
| 26 |
* |
| 27 |
* @param array $request Request body. |
| 28 |
*/ |
| 29 |
public function update_hublet( $request ) { |
| 30 |
$data = json_decode( $request->get_body(), true ); |
| 31 |
$hublet = $data['hublet']; |
| 32 |
|
| 33 |
if ( ! $hublet ) { |
| 34 |
return new \WP_REST_Response( 'Hublet is required', 400 ); |
| 35 |
} |
| 36 |
Portal_Options::set_hublet( $hublet ); |
| 37 |
return new \WP_REST_Response( $hublet, 200 ); |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
|