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