create_initial_rest_routes

Registers default REST API routes.

Description

create_initial_rest_routes(); 

Usage

  1. if ( !function_exists( 'create_initial_rest_routes' ) ) { 
  2. require_once ABSPATH . WPINC . '/rest-api.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = create_initial_rest_routes(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/rest-api.php  
  1. function create_initial_rest_routes() { 
  2. foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { 
  3. $class = ! empty( $post_type->rest_controller_class ) ? $post_type->rest_controller_class : 'WP_REST_Posts_Controller'; 
  4.  
  5. if ( ! class_exists( $class ) ) { 
  6. continue; 
  7. $controller = new $class( $post_type->name ); 
  8. if ( ! is_subclass_of( $controller, 'WP_REST_Controller' ) ) { 
  9. continue; 
  10.  
  11. $controller->register_routes(); 
  12.  
  13. if ( post_type_supports( $post_type->name, 'revisions' ) ) { 
  14. $revisions_controller = new WP_REST_Revisions_Controller( $post_type->name ); 
  15. $revisions_controller->register_routes(); 
  16.  
  17. // Post types. 
  18. $controller = new WP_REST_Post_Types_Controller; 
  19. $controller->register_routes(); 
  20.  
  21. // Post statuses. 
  22. $controller = new WP_REST_Post_Statuses_Controller; 
  23. $controller->register_routes(); 
  24.  
  25. // Taxonomies. 
  26. $controller = new WP_REST_Taxonomies_Controller; 
  27. $controller->register_routes(); 
  28.  
  29. // Terms. 
  30. foreach ( get_taxonomies( array( 'show_in_rest' => true ), 'object' ) as $taxonomy ) { 
  31. $class = ! empty( $taxonomy->rest_controller_class ) ? $taxonomy->rest_controller_class : 'WP_REST_Terms_Controller'; 
  32.  
  33. if ( ! class_exists( $class ) ) { 
  34. continue; 
  35. $controller = new $class( $taxonomy->name ); 
  36. if ( ! is_subclass_of( $controller, 'WP_REST_Controller' ) ) { 
  37. continue; 
  38.  
  39. $controller->register_routes(); 
  40.  
  41. // Users. 
  42. $controller = new WP_REST_Users_Controller; 
  43. $controller->register_routes(); 
  44.  
  45. // Comments. 
  46. $controller = new WP_REST_Comments_Controller; 
  47. $controller->register_routes(); 
  48.  
  49. // Settings. 
  50. $controller = new WP_REST_Settings_Controller; 
  51. $controller->register_routes();