forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest-api.php
174 lines (153 loc) · 4.73 KB
/
rest-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* PHP and WordPress configuration compatibility functions for the Gutenberg
* editor plugin changes related to REST API.
*
* @package gutenberg
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Silence is golden.' );
}
/**
* Registers the REST API routes needed by the Gutenberg editor.
*
* @since 2.8.0
* @deprecated 5.0.0
*/
function gutenberg_register_rest_routes() {
_deprecated_function( __FUNCTION__, '5.0.0' );
}
/**
* Handle a failing oEmbed proxy request to try embedding as a shortcode.
*
* @see https://core.trac.wordpress.org/ticket/45447
*
* @since 2.3.0
*
* @param WP_HTTP_Response|WP_Error $response The REST Request response.
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
* @param WP_REST_Request $request Request used to generate the response.
* @return WP_HTTP_Response|object|WP_Error The REST Request response.
*/
function gutenberg_filter_oembed_result( $response, $handler, $request ) {
if ( ! is_wp_error( $response ) || 'oembed_invalid_url' !== $response->get_error_code() ||
'/oembed/1.0/proxy' !== $request->get_route() ) {
return $response;
}
// Try using a classic embed instead.
global $wp_embed;
$html = $wp_embed->shortcode( array(), $_GET['url'] );
if ( ! $html ) {
return $response;
}
global $wp_scripts;
// Check if any scripts were enqueued by the shortcode, and include them in
// the response.
$enqueued_scripts = array();
foreach ( $wp_scripts->queue as $script ) {
$enqueued_scripts[] = $wp_scripts->registered[ $script ]->src;
}
return array(
'provider_name' => __( 'Embed Handler', 'gutenberg' ),
'html' => $html,
'scripts' => $enqueued_scripts,
);
}
add_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result', 10, 3 );
/**
* Add additional 'visibility' rest api field to taxonomies.
*
* Used so private taxonomies are not displayed in the UI.
*
* @see https://core.trac.wordpress.org/ticket/42707
* @deprecated 5.0.0
*/
function gutenberg_add_taxonomy_visibility_field() {
_deprecated_function( __FUNCTION__, '5.0.0' );
}
/**
* Gets taxonomy visibility property data.
*
* @see https://core.trac.wordpress.org/ticket/42707
* @deprecated 5.0.0
*
* @param array $object Taxonomy data from REST API.
* @return array Array of taxonomy visibility data.
*/
function gutenberg_get_taxonomy_visibility_data( $object ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return isset( $object['visibility'] ) ? $object['visibility'] : array();
}
/**
* Add a permalink template to posts in the post REST API response.
*
* @see https://core.trac.wordpress.org/ticket/45017
* @deprecated 5.0.0
*
* @param WP_REST_Response $response WP REST API response of a post.
* @return WP_REST_Response Response containing the permalink_template.
*/
function gutenberg_add_permalink_template_to_posts( $response ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return $response;
}
/**
* Add the block format version to post content in the post REST API response.
*
* @see https://core.trac.wordpress.org/ticket/43887
* @deprecated 5.0.0
*
* @param WP_REST_Response $response WP REST API response of a post.
* @return WP_REST_Response Response containing the block_format.
*/
function gutenberg_add_block_format_to_post_content( $response ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return $response;
}
/**
* Include target schema attributes to links, based on whether the user can.
*
* @see https://core.trac.wordpress.org/ticket/45014
* @deprecated 5.0.0
*
* @param WP_REST_Response $response WP REST API response of a post.
* @return WP_REST_Response Response containing the new links.
*/
function gutenberg_add_target_schema_to_links( $response ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return $response;
}
/**
* Whenever a post type is registered, ensure we're hooked into it's WP REST API response.
*
* @deprecated 5.0.0
*
* @param string $post_type The newly registered post type.
* @return string That same post type.
*/
function gutenberg_register_post_prepare_functions( $post_type ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return $post_type;
}
/**
* Silence PHP Warnings and Errors in JSON requests
*
* @see https://core.trac.wordpress.org/ticket/44534
* @deprecated 5.0.0
*/
function gutenberg_silence_rest_errors() {
_deprecated_function( __FUNCTION__, '5.0.0' );
}
/**
* Include additional labels for registered post types
*
* @see https://core.trac.wordpress.org/ticket/45101
* @deprecated 5.0.0
*
* @param array $args Arguments supplied to register_post_type().
* @return array Arguments supplied to register_post_type()
*/
function gutenberg_filter_post_type_labels( $args ) {
_deprecated_function( __FUNCTION__, '5.0.0' );
return $args;
}