PluginProbe
Gutenberg / 23.5.1
Gutenberg v23.5.1
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.5.1, at lib/compat/wordpress-7.1/rest-api.php

67 lines 2.2 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 * Overrides the REST controller for the attachment post type to add support
51 * for filtering by multiple media types.
52 *
53 * Only applies if the experimental media processing feature is not enabled,
54 * as that feature includes this functionality and more.
55 *
56 * @param array $args Array of arguments for registering a post type.
57 * @param string $post_type Post type key.
58 * @return array Modified array of arguments.
59 */
60 function gutenberg_override_attachments_rest_controller( $args, $post_type ) {
61 if ( 'attachment' === $post_type && ! gutenberg_is_client_side_media_processing_enabled() ) {
62 $args['rest_controller_class'] = 'Gutenberg_REST_Attachments_Controller_7_1';
63 }
64 return $args;
65 }
66 add_filter( 'register_post_type_args', 'gutenberg_override_attachments_rest_controller', 10, 2 );
67