| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPConsole\Core\Console; |
| 4 |
|
| 5 |
class Console { |
| 6 |
|
| 7 |
/** |
| 8 |
* Class constructor |
| 9 |
* |
| 10 |
* @since 1.0.0 |
| 11 |
* |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
public function __construct() { |
| 15 |
add_filter( 'wp_console_rest_controllers', [ $this, 'add_rest_controller' ] ); |
| 16 |
add_filter( 'wp_console_user_settings_schema', [ $this, 'add_user_settings_schema' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Add REST controller |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* |
| 24 |
* @param object $controllers |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public function add_rest_controller( $controllers ) { |
| 29 |
$controllers->console = new RestController(); |
| 30 |
return $controllers; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Add user settings schema |
| 35 |
* |
| 36 |
* @since 2.0.0 |
| 37 |
* |
| 38 |
* @param array $settings |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function add_user_settings_schema( $schema ) { |
| 43 |
$defaults = [ |
| 44 |
'window_split' => 'vertical', |
| 45 |
'snippets' => [ |
| 46 |
[ |
| 47 |
'id' => wp_generate_uuid4(), |
| 48 |
'title' => __( 'Custom Snippets', 'wp-console' ), |
| 49 |
'snippets' => '{}', |
| 50 |
], |
| 51 |
], |
| 52 |
]; |
| 53 |
|
| 54 |
$schema['console'] = [ |
| 55 |
'description' => __( 'User settings for Console panel', 'wp-console' ), |
| 56 |
'type' => 'object', |
| 57 |
'context' => [ 'view', 'edit' ], |
| 58 |
'default' => $defaults, |
| 59 |
'properties' => [ |
| 60 |
'window_split' => [ |
| 61 |
'description' => __( 'Console panel window split type', 'wp-console' ), |
| 62 |
'type' => 'string', |
| 63 |
'enum' => [ 'horizontal', 'vertical' ], |
| 64 |
'default' => $defaults['window_split'], |
| 65 |
'context' => [ 'view', 'edit' ], |
| 66 |
], |
| 67 |
'snippets' => [ |
| 68 |
'description' => __( 'User defined custom snippets', 'wp-console' ), |
| 69 |
'type' => 'array', |
| 70 |
'default' => $defaults['snippets'], |
| 71 |
'context' => [ 'view', 'edit' ], |
| 72 |
'items' => [ |
| 73 |
'type' => 'object', |
| 74 |
'properties' => [ |
| 75 |
'id' => [ |
| 76 |
'description' => __( 'Snippet group id', 'wp-console' ), |
| 77 |
'type' => 'string', |
| 78 |
'required' => true, |
| 79 |
], |
| 80 |
'title' => [ |
| 81 |
'description' => __( 'Snippet group title', 'wp-console' ), |
| 82 |
'type' => 'string', |
| 83 |
'required' => true, |
| 84 |
], |
| 85 |
'snippets' => [ |
| 86 |
'description' => __( 'VSCode compatible snippets in JSON format', 'wp-console' ), |
| 87 |
'type' => 'string', |
| 88 |
'required' => true, |
| 89 |
], |
| 90 |
] |
| 91 |
], |
| 92 |
], |
| 93 |
], |
| 94 |
]; |
| 95 |
|
| 96 |
return $schema; |
| 97 |
} |
| 98 |
} |
| 99 |
|