PluginProbe
Gutenberg / 23.4.0
Gutenberg v23.4.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experimental / guidelines / index.php

index.php in Gutenberg 23.4.0, at lib/experimental/guidelines/index.php

62 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Guidelines experimental feature.
4 *
5 * @package gutenberg
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 require_once __DIR__ . '/guidelines.php';
13 require_once __DIR__ . '/class-gutenberg-guidelines-post-type.php';
14 require_once __DIR__ . '/class-gutenberg-guidelines-rest-controller.php';
15 require_once __DIR__ . '/class-gutenberg-content-guidelines-revisions-controller.php';
16 require_once __DIR__ . '/class-gutenberg-content-guidelines-rest-controller.php';
17
18 /*
19 * Register the guideline post type.
20 * The standard /wp/v2/guidelines collection uses the default posts controller.
21 */
22 add_action( 'init', array( 'Gutenberg_Guidelines_Post_Type', 'register' ) );
23
24 /*
25 * Ensure the post type is registered before any other `rest_api_init` callback
26 * runs. `init` normally fires before `rest_api_init`, but anything that calls
27 * `rest_get_server()` early (e.g. from `plugins_loaded`) fires `rest_api_init`
28 * before `init` priority 10. The callbacks below — both `register_post_meta`
29 * and the controller instantiations — dereference the post type object and
30 * 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_Guidelines_Post_Type::POST_TYPE ) ) {
36 Gutenberg_Guidelines_Post_Type::register();
37 }
38 },
39 1
40 );
41
42 // Register post meta once the REST API loads and the block registry is available.
43 add_action( 'rest_api_init', array( 'Gutenberg_Guidelines_Post_Type', 'register_post_meta' ) );
44
45 /*
46 * Register content singleton routes beside the standard CPT routes.
47 * The singleton rule is scoped to /wp/v2/content-guidelines for UI handling.
48 * The standard /wp/v2/guidelines route keeps default post handling for every
49 * `wp_guideline` post. If `content` becomes a data level singleton, add
50 * enforcement to the default CPT route too.
51 */
52 add_action(
53 'rest_api_init',
54 static function () {
55 $content_controller = new Gutenberg_Content_Guidelines_REST_Controller();
56 $content_controller->register_routes();
57
58 $content_revisions_controller = new Gutenberg_Content_Guidelines_Revisions_Controller();
59 $content_revisions_controller->register_routes();
60 }
61 );
62