| 1 |
<?php |
| 2 |
|
| 3 |
class MeowCommon_Classes_Rest_License |
| 4 |
{ |
| 5 |
private $licenser = null; |
| 6 |
private $namespace = null; |
| 7 |
|
| 8 |
public function __construct( &$licenser ) { |
| 9 |
$this->licenser = $licenser; |
| 10 |
$this->namespace = "meow-licenser/{$licenser->prefix}/v1"; |
| 11 |
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
| 12 |
} |
| 13 |
|
| 14 |
function rest_api_init() { |
| 15 |
register_rest_route( $this->namespace, '/get_license/', [ |
| 16 |
'methods' => 'POST', |
| 17 |
'permission_callback' => function () { |
| 18 |
return current_user_can( 'administrator' ); |
| 19 |
}, |
| 20 |
'callback' => [ $this, 'get_license' ] |
| 21 |
]); |
| 22 |
register_rest_route( $this->namespace, '/set_license/', [ |
| 23 |
'methods' => 'POST', |
| 24 |
'permission_callback' => function () { |
| 25 |
return current_user_can( 'administrator' ); |
| 26 |
}, |
| 27 |
'callback' => [ $this, 'set_license' ] |
| 28 |
]); |
| 29 |
} |
| 30 |
|
| 31 |
function get_license() { |
| 32 |
return new WP_REST_Response( [ 'success' => true, 'data' => $this->licenser->license ], 200 ); |
| 33 |
} |
| 34 |
|
| 35 |
function set_license( $request ) { |
| 36 |
$params = $request->get_json_params(); |
| 37 |
$serialKey = $params['serialKey']; |
| 38 |
$this->licenser->validate_pro( $serialKey ); |
| 39 |
return new WP_REST_Response( [ 'success' => true, 'data' => $this->licenser->license ], 200 ); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
?> |