wpseek.com
A WordPress-centric search engine for devs and theme authors



create_initial_rest_routes › WordPress Function

Since4.7.0
Deprecatedn/a
create_initial_rest_routes ( No parameters )
Defined at:
Codex:

Registers default REST API routes.



Source

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;
		}

		if ( ! $post_type->late_route_registration ) {
			$controller->register_routes();
		}

		$revisions_controller = $post_type->get_revisions_rest_controller();
		if ( $revisions_controller ) {
			$revisions_controller->register_routes();
		}

		$autosaves_controller = $post_type->get_autosave_rest_controller();
		if ( $autosaves_controller ) {
			$autosaves_controller->register_routes();
		}

		if ( $post_type->late_route_registration ) {
			$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 revisions.
	$controller = new WP_REST_Global_Styles_Revisions_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();

	// Navigation Fallback.
	$controller = new WP_REST_Navigation_Fallback_Controller();
	$controller->register_routes();

	// Font Collections.
	$font_collections_controller = new WP_REST_Font_Collections_Controller();
	$font_collections_controller->register_routes();
}