| 1 |
<?php |
| 2 |
/** |
| 3 |
* Knowledge experimental feature. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
require_once __DIR__ . '/knowledge.php'; |
| 13 |
require_once __DIR__ . '/class-gutenberg-knowledge-post-type.php'; |
| 14 |
require_once __DIR__ . '/class-gutenberg-knowledge-rest-controller.php'; |
| 15 |
require_once __DIR__ . '/class-gutenberg-guideline-scopes-rest-controller.php'; |
| 16 |
|
| 17 |
/* |
| 18 |
* Register the knowledge post type. |
| 19 |
* The standard /wp/v2/knowledge collection is served by the custom |
| 20 |
* Gutenberg_Knowledge_REST_Controller (set via the post type's |
| 21 |
* `rest_controller_class`). |
| 22 |
*/ |
| 23 |
add_action( 'init', array( 'Gutenberg_Knowledge_Post_Type', 'register' ) ); |
| 24 |
|
| 25 |
/* |
| 26 |
* Ensure the post type is registered before any other `rest_api_init` callback |
| 27 |
* runs. `init` normally fires before `rest_api_init`, but anything that calls |
| 28 |
* `rest_get_server()` early (e.g. from `plugins_loaded`) fires `rest_api_init` |
| 29 |
* before `init` priority 10. The callback below dereferences the post type |
| 30 |
* object and would fatal (or trip `_doing_it_wrong`) without this guard. |
| 31 |
*/ |
| 32 |
add_action( |
| 33 |
'rest_api_init', |
| 34 |
static function () { |
| 35 |
if ( ! post_type_exists( Gutenberg_Knowledge_Post_Type::POST_TYPE ) ) { |
| 36 |
Gutenberg_Knowledge_Post_Type::register(); |
| 37 |
} |
| 38 |
}, |
| 39 |
1 |
| 40 |
); |
| 41 |
|
| 42 |
/* |
| 43 |
* Register the read-only guideline scopes registry route beside the standard |
| 44 |
* CPT routes. Guideline data itself is read and written through the standard |
| 45 |
* /wp/v2/knowledge collection; scope rows are identified by the `guideline-` |
| 46 |
* slug prefix and the `guideline` knowledge type (see the reservation guard in |
| 47 |
* knowledge.php). |
| 48 |
*/ |
| 49 |
add_action( |
| 50 |
'rest_api_init', |
| 51 |
static function () { |
| 52 |
$scopes_controller = new Gutenberg_Guideline_Scopes_REST_Controller(); |
| 53 |
$scopes_controller->register_routes(); |
| 54 |
} |
| 55 |
); |
| 56 |
|