Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ThemeInstallerController | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
register_routes | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
initialize | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | namespace NewfoldLabs\WP\Module\Onboarding\RestApi\Themes; |
3 | |
4 | use NewfoldLabs\WP\Module\Onboarding\Permissions; |
5 | use NewfoldLabs\WP\Module\Onboarding\Services\ThemeService; |
6 | |
7 | /** |
8 | * Controller defining API's for theme install related functionalities. |
9 | */ |
10 | class ThemeInstallerController extends \WP_REST_Controller { |
11 | /** |
12 | * The namespace of this controller's route. |
13 | * |
14 | * @var string |
15 | */ |
16 | protected $namespace = 'newfold-onboarding/v1'; |
17 | |
18 | /** |
19 | * The base of this controller's route. |
20 | * |
21 | * @var string |
22 | */ |
23 | protected $rest_base = '/themes'; |
24 | |
25 | /** |
26 | * Register the controller routes. |
27 | */ |
28 | public function register_routes() { |
29 | \register_rest_route( |
30 | $this->namespace, |
31 | $this->rest_base . '/initialize', |
32 | array( |
33 | array( |
34 | 'methods' => \WP_REST_Server::CREATABLE, |
35 | 'callback' => array( $this, 'initialize' ), |
36 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
37 | ), |
38 | ) |
39 | ); |
40 | } |
41 | |
42 | /** |
43 | * Queue in the initial list of themes to be installed. |
44 | * |
45 | * @return \WP_REST_Response |
46 | */ |
47 | public static function initialize() { |
48 | if ( ThemeService::initialize() ) { |
49 | return new \WP_REST_Response( |
50 | array(), |
51 | 202 |
52 | ); |
53 | } |
54 | |
55 | return new \WP_REST_Response( |
56 | array(), |
57 | 500 |
58 | ); |
59 | } |
60 | } |