create_initial_rest_routes()
最后更新于:2021-11-25 22:30:01
create_initial_rest_routes()Registers default REST API routes.
源文件
文件: gc-includes/rest-api.php
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 GC_REST_Revisions_Controller( $post_type->name );
$revisions_controller->register_routes();
}
if ( 'attachment' !== $post_type->name ) {
$autosaves_controller = new GC_REST_Autosaves_Controller( $post_type->name );
$autosaves_controller->register_routes();
}
}
// Post types.
$controller = new GC_REST_Post_Types_Controller;
$controller->register_routes();
// Post statuses.
$controller = new GC_REST_Post_Statuses_Controller;
$controller->register_routes();
// Taxonomies.
$controller = new GC_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 GC_REST_Users_Controller;
$controller->register_routes();
// Application Passwords
$controller = new GC_REST_Application_Passwords_Controller();
$controller->register_routes();
// Comments.
$controller = new GC_REST_Comments_Controller;
$controller->register_routes();
$search_handlers = array(
new GC_REST_Post_Search_Handler(),
new GC_REST_Term_Search_Handler(),
new GC_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 `GC_REST_Search_Handler` class.
* Default is only a handler for posts.
*/
$search_handlers = apply_filters( 'gc_rest_search_handlers', $search_handlers );
$controller = new GC_REST_Search_Controller( $search_handlers );
$controller->register_routes();
// Block Renderer.
$controller = new GC_REST_Block_Renderer_Controller;
$controller->register_routes();
// Block Types.
$controller = new GC_REST_Block_Types_Controller();
$controller->register_routes();
// Settings.
$controller = new GC_REST_Settings_Controller;
$controller->register_routes();
// Themes.
$controller = new GC_REST_Themes_Controller;
$controller->register_routes();
// Plugins.
$controller = new GC_REST_Plugins_Controller();
$controller->register_routes();
// Sidebars.
$controller = new GC_REST_Sidebars_Controller();
$controller->register_routes();
// Widget Types.
$controller = new GC_REST_Widget_Types_Controller();
$controller->register_routes();
// Widgets.
$controller = new GC_REST_Widgets_Controller();
$controller->register_routes();
// Block Directory.
$controller = new GC_REST_Block_Directory_Controller();
$controller->register_routes();
// Pattern Directory.
$controller = new GC_REST_Pattern_Directory_Controller();
$controller->register_routes();
// Site Health.
$site_health = GC_Site_Health::get_instance();
$controller = new GC_REST_Site_Health_Controller( $site_health );
$controller->register_routes();
}