PluginProbe
Gutenberg / 18.9.0
Gutenberg v18.9.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 / rest-api.php

rest-api.php in Gutenberg 18.9.0, at lib/rest-api.php

79 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PHP and WordPress configuration compatibility functions for the Gutenberg
4 * editor plugin changes related to REST API.
5 *
6 * @package gutenberg
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die( 'Silence is golden.' );
11 }
12
13 /**
14 * Registers the Global Styles REST API routes.
15 */
16 function gutenberg_register_global_styles_endpoints() {
17 $global_styles_controller = new WP_REST_Global_Styles_Controller_Gutenberg();
18 $global_styles_controller->register_routes();
19 }
20 add_action( 'rest_api_init', 'gutenberg_register_global_styles_endpoints' );
21
22 if ( ! function_exists( 'gutenberg_register_edit_site_export_controller_endpoints' ) ) {
23 /**
24 * Registers the Edit Site Export REST API routes.
25 */
26 function gutenberg_register_edit_site_export_controller_endpoints() {
27 $edit_site_export_controller = new WP_REST_Edit_Site_Export_Controller_Gutenberg();
28 $edit_site_export_controller->register_routes();
29 }
30 }
31
32 add_action( 'rest_api_init', 'gutenberg_register_edit_site_export_controller_endpoints' );
33
34 if ( ! function_exists( 'gutenberg_register_wp_rest_post_types_controller_fields' ) ) {
35 /**
36 * Adds `template` and `template_lock` fields to WP_REST_Post_Types_Controller class.
37 */
38 function gutenberg_register_wp_rest_post_types_controller_fields() {
39 register_rest_field(
40 'type',
41 'template',
42 array(
43 'get_callback' => function ( $item ) {
44 $post_type = get_post_type_object( $item['slug'] );
45 if ( ! empty( $post_type ) ) {
46 return $post_type->template ?? array();
47 }
48 },
49 'schema' => array(
50 'type' => 'array',
51 'description' => __( 'The block template associated with the post type.', 'gutenberg' ),
52 'readonly' => true,
53 'context' => array( 'view', 'edit', 'embed' ),
54 ),
55 )
56 );
57 register_rest_field(
58 'type',
59 'template_lock',
60 array(
61 'get_callback' => function ( $item ) {
62 $post_type = get_post_type_object( $item['slug'] );
63 if ( ! empty( $post_type ) ) {
64 return ! empty( $post_type->template_lock ) ? $post_type->template_lock : false;
65 }
66 },
67 'schema' => array(
68 'type' => array( 'string', 'boolean' ),
69 'enum' => array( 'all', 'insert', 'contentOnly', false ),
70 'description' => __( 'The template_lock associated with the post type, or false if none.', 'gutenberg' ),
71 'readonly' => true,
72 'context' => array( 'view', 'edit', 'embed' ),
73 ),
74 )
75 );
76 }
77 }
78 add_action( 'rest_api_init', 'gutenberg_register_wp_rest_post_types_controller_fields' );
79