| 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 |
|