| 1 |
<?php |
| 2 |
|
| 3 |
namespace WeDevs\ERP\API; |
| 4 |
|
| 5 |
use WP_REST_Response; |
| 6 |
use WP_REST_Server; |
| 7 |
|
| 8 |
class UtilityController extends REST_Controller { |
| 9 |
|
| 10 |
/** |
| 11 |
* Endpoint namespace. |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
protected $namespace = 'erp/v1'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Route base. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
protected $rest_base = 'utility'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Register the routes for the objects of the controller. |
| 26 |
*/ |
| 27 |
public function register_routes() { |
| 28 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/get-active-plugins', [ |
| 29 |
[ |
| 30 |
'methods' => WP_REST_Server::READABLE, |
| 31 |
'callback' => [ $this, 'get_active_plugins' ], |
| 32 |
'args' => $this->get_collection_params(), |
| 33 |
'permission_callback' => function ( $request ) { |
| 34 |
return current_user_can( 'erp_view_list' ); |
| 35 |
}, |
| 36 |
], |
| 37 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 38 |
] ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Get the list of active plugins |
| 43 |
* |
| 44 |
* @since 1.3.0 |
| 45 |
* |
| 46 |
* @param $request |
| 47 |
* |
| 48 |
* @return mixed|WP_REST_Response |
| 49 |
*/ |
| 50 |
public function get_active_plugins( $request ) { |
| 51 |
$active_plugins = get_option( 'active_plugins' ); |
| 52 |
$response = rest_ensure_response( $active_plugins ); |
| 53 |
|
| 54 |
return $response; |
| 55 |
} |
| 56 |
} |
| 57 |
|