193
193
$revisions_controller = new WP_REST_Revisions_Controller( $post_type->name );
194
194
$revisions_controller->register_routes();
197
if ( 'attachment' !== $post_type->name ) {
198
$autosaves_controller = new WP_REST_Autosaves_Controller( $post_type->name );
199
$autosaves_controller->register_routes();
230
236
$controller = new WP_REST_Comments_Controller;
231
237
$controller->register_routes();
240
* Filters the search handlers to use in the REST search controller.
244
* @param array $search_handlers List of search handlers to use in the controller. Each search
245
* handler instance must extend the `WP_REST_Search_Handler` class.
246
* Default is only a handler for posts.
248
$search_handlers = apply_filters( 'wp_rest_search_handlers', array( new WP_REST_Post_Search_Handler() ) );
250
$controller = new WP_REST_Search_Controller( $search_handlers );
251
$controller->register_routes();
254
$controller = new WP_REST_Block_Renderer_Controller;
255
$controller->register_routes();
234
258
$controller = new WP_REST_Settings_Controller;
235
259
$controller->register_routes();
262
$controller = new WP_REST_Themes_Controller;
263
$controller->register_routes();
316
347
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
319
$url .= '/' . ltrim( $path, '/' );
321
352
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
322
353
// nginx only allows HTTP/1.0 methods when redirecting from / to /index.php
1327
* Append result of internal request to REST API for purpose of preloading data to be attached to a page.
1328
* Expected to be called in the context of `array_reduce`.
1332
* @param array $memo Reduce accumulator.
1333
* @param string $path REST API path to preload.
1334
* @return array Modified reduce accumulator.
1336
function rest_preload_api_request( $memo, $path ) {
1337
// array_reduce() doesn't support passing an array in PHP 5.2, so we need to make sure we start with one.
1338
if ( ! is_array( $memo ) ) {
1342
if ( empty( $path ) ) {
1347
if ( is_array( $path ) && 2 === count( $path ) ) {
1348
$method = end( $path );
1349
$path = reset( $path );
1351
if ( ! in_array( $method, array( 'GET', 'OPTIONS' ), true ) ) {
1356
$path_parts = parse_url( $path );
1357
if ( false === $path_parts ) {
1361
$request = new WP_REST_Request( $method, $path_parts['path'] );
1362
if ( ! empty( $path_parts['query'] ) ) {
1363
parse_str( $path_parts['query'], $query_params );
1364
$request->set_query_params( $query_params );
1367
$response = rest_do_request( $request );
1368
if ( 200 === $response->status ) {
1369
$server = rest_get_server();
1370
$data = (array) $response->get_data();
1371
$links = $server->get_compact_response_links( $response );
1372
if ( ! empty( $links ) ) {
1373
$data['_links'] = $links;
1376
if ( 'OPTIONS' === $method ) {
1377
$response = rest_send_allow_header( $response, $server, $request );
1379
$memo[ $method ][ $path ] = array(
1381
'headers' => $response->headers,
1384
$memo[ $path ] = array(
1386
'headers' => $response->headers,