Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RestApi | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_routes | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| register_settings | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\Migration\RestApi; |
| 3 | |
| 4 | /** |
| 5 | * Instantiate controllers and register routes. |
| 6 | */ |
| 7 | final class RestApi { |
| 8 | |
| 9 | /** |
| 10 | * Option settings |
| 11 | * |
| 12 | * @var array |
| 13 | */ |
| 14 | protected $options = array( |
| 15 | 'nfd_migrate_site' => 'boolean', |
| 16 | ); |
| 17 | |
| 18 | /** |
| 19 | * List of custom REST API controllers |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $controllers = array( |
| 24 | 'NewfoldLabs\\WP\\Module\\Migration\\RestApi\\MigrateController', |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Setup the custom REST API |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Register the custom REST API routes |
| 36 | */ |
| 37 | public function register_routes() { |
| 38 | foreach ( $this->controllers as $controller ) { |
| 39 | /** |
| 40 | * Get an instance of the WP_REST_Controller. |
| 41 | * |
| 42 | * @var $instance WP_REST_Controller |
| 43 | */ |
| 44 | $instance = new $controller(); |
| 45 | $instance->register_routes(); |
| 46 | } |
| 47 | self::register_settings(); |
| 48 | } |
| 49 | /** |
| 50 | * Register settings. |
| 51 | */ |
| 52 | public function register_settings() { |
| 53 | foreach ( $this->options as $option => $type ) { |
| 54 | \register_setting( |
| 55 | 'general', |
| 56 | $option, |
| 57 | array( |
| 58 | 'show_in_rest' => true, |
| 59 | 'type' => $type, |
| 60 | 'description' => __( 'NFD migration Options', 'wp-module-migration' ), |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | } |
| 65 | } |