PluginProbe
Gutenberg / 23.6.2
Gutenberg v23.6.2
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 / compat / wordpress-7.1 / rest-api.php

rest-api.php in Gutenberg 23.6.2, at lib/compat/wordpress-7.1/rest-api.php

100 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress 7.1 compatibility functions for the Gutenberg
4 * editor plugin changes related to REST API.
5 *
6 * @package gutenberg
7 */
8
9 /**
10 * Registers the View Config REST API routes.
11 */
12 function gutenberg_register_view_config_controller_endpoints() {
13 $view_config_controller = new Gutenberg_REST_View_Config_Controller_7_1();
14 $view_config_controller->register_routes();
15 }
16 add_action( 'rest_api_init', 'gutenberg_register_view_config_controller_endpoints', PHP_INT_MAX );
17
18 /**
19 * Add the `date` value to the `wp_template` schema.
20 *
21 * @since 7.1.0 Added 'date' property and response value.
22 */
23 function gutenberg_add_date_wp_template_schema() {
24 register_rest_field(
25 array( 'wp_template', 'wp_template_part' ),
26 'date',
27 array(
28 'schema' => array(
29 'description' => __( "The date the template was published, in the site's timezone.", 'gutenberg' ),
30 'type' => array( 'string', 'null' ),
31 'format' => 'date-time',
32 'context' => array( 'view', 'edit' ),
33 'readonly' => true,
34 ),
35 'get_callback' => function ( $item ) {
36 if ( ! empty( $item['wp_id'] ) ) {
37 $post = get_post( $item['wp_id'] );
38 if ( $post && isset( $post->post_date ) ) {
39 return mysql_to_rfc3339( $post->post_date );
40 }
41 }
42 return null;
43 },
44 )
45 );
46 }
47 add_filter( 'rest_api_init', 'gutenberg_add_date_wp_template_schema' );
48
49 /**
50 * Registers the Icon Collections Registry REST API routes.
51 */
52 function gutenberg_register_icon_collections_controller_endpoints() {
53 $icon_collections_controller = new WP_REST_Icon_Collections_Controller();
54 $icon_collections_controller->register_routes();
55 }
56 add_action( 'rest_api_init', 'gutenberg_register_icon_collections_controller_endpoints' );
57
58 /**
59 * Overrides the REST controller for the attachment post type to add support
60 * for filtering by multiple media types.
61 *
62 * Only applies if the experimental media processing feature is not enabled,
63 * as that feature includes this functionality and more.
64 *
65 * @param array $args Array of arguments for registering a post type.
66 * @param string $post_type Post type key.
67 * @return array Modified array of arguments.
68 */
69 function gutenberg_override_attachments_rest_controller( $args, $post_type ) {
70 if ( 'attachment' === $post_type && ! gutenberg_is_client_side_media_processing_enabled() ) {
71 $args['rest_controller_class'] = 'Gutenberg_REST_Attachments_Controller_7_1';
72 }
73 return $args;
74 }
75 add_filter( 'register_post_type_args', 'gutenberg_override_attachments_rest_controller', 10, 2 );
76
77 /**
78 * Overrides the default REST controller for autosaves to fix real-time
79 * collaboration on draft posts.
80 *
81 * When RTC is enabled, draft autosaves from all users update the post directly
82 * instead of creating per-user autosave revisions depending on post lock and
83 * assigned author.
84 *
85 * Only overrides when autosave_rest_controller_class is not explicitly set,
86 * i.e. when WP_REST_Autosaves_Controller would be used by default. Post types
87 * with their own specialized autosave controller (e.g. templates) are left alone.
88 *
89 * @param array $args Array of arguments for registering a post type.
90 * @return array Modified array of arguments.
91 */
92 function gutenberg_override_autosaves_rest_controller( $args ) {
93 if ( empty( $args['autosave_rest_controller_class'] ) ) {
94 $args['autosave_rest_controller_class'] = 'Gutenberg_REST_Autosaves_Controller';
95 }
96 return $args;
97 }
98
99 add_filter( 'register_post_type_args', 'gutenberg_override_autosaves_rest_controller', 10, 1 );
100