@@ -263,15 +263,6 @@ function rest_api_default_filters() {
263263 * @since 4.7.0
264264 */
265265function create_initial_rest_routes () {
266- global $ wp_post_types ;
267-
268- // Register the registered templates endpoint. For that we need to copy the
269- // wp_template post type so that it's available as an entity in core-data.
270- $ wp_post_types ['wp_registered_template ' ] = clone $ wp_post_types ['wp_template ' ];
271- $ wp_post_types ['wp_registered_template ' ]->name = 'wp_registered_template ' ;
272- $ wp_post_types ['wp_registered_template ' ]->rest_base = 'wp_registered_template ' ;
273- $ wp_post_types ['wp_registered_template ' ]->rest_controller_class = 'WP_REST_Registered_Templates_Controller ' ;
274-
275266 foreach ( get_post_types ( array ( 'show_in_rest ' => true ), 'objects ' ) as $ post_type ) {
276267 $ controller = $ post_type ->get_rest_controller ();
277268
@@ -298,11 +289,14 @@ function create_initial_rest_routes() {
298289 }
299290 }
300291
292+ global $ wp_post_types ;
293+
301294 // Register the old templates endpoints. The WP_REST_Templates_Controller
302295 // and sub-controllers used linked to the wp_template post type, but are no
303296 // longer. They still require a post type object when contructing the class.
304297 // To maintain backward and changes to these controller classes, we make use
305298 // that the wp_template post type has the right information it needs.
299+ $ current_wp_template_rest_base = $ wp_post_types ['wp_template ' ]->rest_base ;
306300 $ wp_post_types ['wp_template ' ]->rest_base = 'templates ' ;
307301 // Store the classes so they can be restored.
308302 $ original_rest_controller_class = $ wp_post_types ['wp_template ' ]->rest_controller_class ;
@@ -328,7 +322,7 @@ function create_initial_rest_routes() {
328322 $ wp_post_types ['wp_template ' ]->autosave_rest_controller_class = $ original_autosave_rest_controller_class ;
329323 $ wp_post_types ['wp_template ' ]->revisions_rest_controller_class = $ original_revisions_rest_controller_class ;
330324 // Restore the original base.
331- $ wp_post_types ['wp_template ' ]->rest_base = ' wp_template ' ;
325+ $ wp_post_types ['wp_template ' ]->rest_base = $ current_wp_template_rest_base ;
332326
333327 // Register the old routes.
334328 $ autosaves_controller ->register_routes ();
@@ -356,6 +350,10 @@ function create_initial_rest_routes() {
356350 )
357351 );
358352
353+ // Registered templates.
354+ $ controller = new WP_REST_Registered_Templates_Controller ();
355+ $ controller ->register_routes ();
356+
359357 // Post types.
360358 $ controller = new WP_REST_Post_Types_Controller ();
361359 $ controller ->register_routes ();
0 commit comments