Make WordPress Core


Ignore:
Timestamp:
10/31/2021 11:15:10 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support custom namespaces for custom post types.

While a custom post type can define a custom route by using the rest_base argument, a namespace of wp/v2 was assumed. This commit introduces support for a rest_namespace argument.

A new rest_get_route_for_post_type_items function has been introduced and the rest_get_route_for_post function updated to facilitate getting the correct route for custom post types.

While the WordPress Core Block Editor bootstrap code has been updated to use these API functions, for maximum compatibility sticking with the default wp/v2 namespace is recommended until the API functions see wider use.

Props spacedmonkey, swissspidy.
Fixes #53656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r51913 r51962  
    14191419 *                                               for the post type to be available in the block editor.
    14201420 *     @type string       $rest_base             To change the base URL of REST API route. Default is $post_type.
     1421 *     @type string       $rest_namespace        To change the namespace URL of REST API route. Default is wp/v2.
    14211422 *     @type string       $rest_controller_class REST API controller class name. Default is 'WP_REST_Posts_Controller'.
    14221423 *     @type int          $menu_position         The position in the menu order the post type should appear. To work,
Note: See TracChangeset for help on using the changeset viewer.