create_initial_rest_routes() WordPress Function

The create_initial_rest_routes() function is used to create the initial REST routes for a WordPress site. This function is called during the WordPress initialization process.

create_initial_rest_routes() #

Registers default REST API routes.


Source

File: wp-includes/rest-api.php

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
function create_initial_rest_routes() {
    foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
        $controller = $post_type->get_rest_controller();
 
        if ( ! $controller ) {
            continue;
        }
 
        $controller->register_routes();
 
        if ( post_type_supports( $post_type->name, 'revisions' ) ) {
            $revisions_controller = new WP_REST_Revisions_Controller( $post_type->name );
            $revisions_controller->register_routes();
        }
 
        if ( 'attachment' !== $post_type->name ) {
            $autosaves_controller = new WP_REST_Autosaves_Controller( $post_type->name );
            $autosaves_controller->register_routes();
        }
    }
 
    // Post types.
    $controller = new WP_REST_Post_Types_Controller;
    $controller->register_routes();
 
    // Post statuses.
    $controller = new WP_REST_Post_Statuses_Controller;
    $controller->register_routes();
 
    // Taxonomies.
    $controller = new WP_REST_Taxonomies_Controller;
    $controller->register_routes();
 
    // Terms.
    foreach ( get_taxonomies( array( 'show_in_rest' => true ), 'object' ) as $taxonomy ) {
        $controller = $taxonomy->get_rest_controller();
 
        if ( ! $controller ) {
            continue;
        }
 
        $controller->register_routes();
    }
 
    // Users.
    $controller = new WP_REST_Users_Controller;
    $controller->register_routes();
 
    // Application Passwords
    $controller = new WP_REST_Application_Passwords_Controller();
    $controller->register_routes();
 
    // Comments.
    $controller = new WP_REST_Comments_Controller;
    $controller->register_routes();
 
    $search_handlers = array(
        new WP_REST_Post_Search_Handler(),
        new WP_REST_Term_Search_Handler(),
        new WP_REST_Post_Format_Search_Handler(),
    );
 
    /**
     * Filters the search handlers to use in the REST search controller.
     *
     * @since 5.0.0
     *
     * @param array $search_handlers List of search handlers to use in the controller. Each search
     *                               handler instance must extend the `WP_REST_Search_Handler` class.
     *                               Default is only a handler for posts.
     */
    $search_handlers = apply_filters( 'wp_rest_search_handlers', $search_handlers );
 
    $controller = new WP_REST_Search_Controller( $search_handlers );
    $controller->register_routes();
 
    // Block Renderer.
    $controller = new WP_REST_Block_Renderer_Controller();
    $controller->register_routes();
 
    // Block Types.
    $controller = new WP_REST_Block_Types_Controller();
    $controller->register_routes();
 
    // Global Styles.
    $controller = new WP_REST_Global_Styles_Controller;
    $controller->register_routes();
 
    // Settings.
    $controller = new WP_REST_Settings_Controller;
    $controller->register_routes();
 
    // Themes.
    $controller = new WP_REST_Themes_Controller;
    $controller->register_routes();
 
    // Plugins.
    $controller = new WP_REST_Plugins_Controller();
    $controller->register_routes();
 
    // Sidebars.
    $controller = new WP_REST_Sidebars_Controller();
    $controller->register_routes();
 
    // Widget Types.
    $controller = new WP_REST_Widget_Types_Controller();
    $controller->register_routes();
 
    // Widgets.
    $controller = new WP_REST_Widgets_Controller();
    $controller->register_routes();
 
    // Block Directory.
    $controller = new WP_REST_Block_Directory_Controller();
    $controller->register_routes();
 
    // Pattern Directory.
    $controller = new WP_REST_Pattern_Directory_Controller();
    $controller->register_routes();
 
    // Block Patterns.
    $controller = new WP_REST_Block_Patterns_Controller();
    $controller->register_routes();
 
    // Block Pattern Categories.
    $controller = new WP_REST_Block_Pattern_Categories_Controller();
    $controller->register_routes();
 
    // Site Health.
    $site_health = WP_Site_Health::get_instance();
    $controller  = new WP_REST_Site_Health_Controller( $site_health );
    $controller->register_routes();
 
    // URL Details.
    $controller = new WP_REST_URL_Details_Controller();
    $controller->register_routes();
 
    // Menu Locations.
    $controller = new WP_REST_Menu_Locations_Controller();
    $controller->register_routes();
 
    // Site Editor Export.
    $controller = new WP_REST_Edit_Site_Export_Controller();
    $controller->register_routes();
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More