PluginProbe
Gutenberg / 23.3.0
Gutenberg v23.3.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 / compat / wordpress-6.9 / rest-api.php

rest-api.php in Gutenberg 23.3.0, at lib/compat/wordpress-6.9/rest-api.php

51 lines 1.7 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 /**
10 * Adds export theme link relation to the block theme responses.
11 *
12 * @param WP_REST_Response $response The response object.
13 * @param WP_Theme $theme Theme object used to create response.
14 * @return WP_REST_Response Modified response object.
15 */
16 function gutenberg_rest_theme_export_link_rel( $response, $theme ) {
17 if ( ! empty( $response->get_links() ) && $theme->is_block_theme() ) {
18 $response->add_link(
19 'https://api.w.org/export-theme',
20 rest_url( 'wp-block-editor/v1/export' ),
21 array(
22 'targetHints' => array(
23 'allow' => current_user_can( 'export' ) ? array( 'GET' ) : array(),
24 ),
25 )
26 );
27 }
28
29 return $response;
30 }
31 add_filter( 'rest_prepare_theme', 'gutenberg_rest_theme_export_link_rel', 10, 2 );
32
33 /**
34 * Overrides the REST controller for the attachment post type to add support
35 * for filtering by multiple media types.
36 *
37 * Only applies if the experimental media processing feature is not enabled,
38 * as that feature includes this functionality and more.
39 *
40 * @param array $args Array of arguments for registering a post type.
41 * @param string $post_type Post type key.
42 * @return array Modified array of arguments.
43 */
44 function gutenberg_override_attachments_rest_controller( $args, $post_type ) {
45 if ( 'attachment' === $post_type && ! gutenberg_is_client_side_media_processing_enabled() ) {
46 $args['rest_controller_class'] = 'Gutenberg_REST_Attachments_Controller_6_9';
47 }
48 return $args;
49 }
50 add_filter( 'register_post_type_args', 'gutenberg_override_attachments_rest_controller', 10, 2 );
51