|
19 | 19 | * |
20 | 20 | * Note: Do not use before the {@see 'rest_api_init'} hook. |
21 | 21 | * |
22 | | - * Example usage: |
23 | | - * ```php |
24 | | - * add_action( 'rest_api_init', function () { |
25 | | - * register_rest_route( 'my-plugin/v1', '/settings', array( |
26 | | - * 'methods' => 'GET', |
27 | | - * 'callback' => 'my_plugin_get_settings', |
28 | | - * 'permission_callback' => function () { |
29 | | - * // Only allow users who can manage options. |
30 | | - * return current_user_can( 'manage_options' ); |
31 | | - * }, |
32 | | - * ) ); |
33 | | - * } ); |
34 | | - * ``` |
35 | | - * |
36 | 22 | * @since 4.4.0 |
37 | 23 | * @since 5.1.0 Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook. |
38 | 24 | * @since 5.5.0 Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set. |
39 | 25 | * |
40 | 26 | * @param string $route_namespace The first URL segment after core prefix. Should be unique to your package/plugin. |
41 | | - * @param string $route The base URL for route to be added with support for regular expressions. |
42 | | - * Example: '/posts/(?P<id>[\d]+)'. |
43 | | - * @param array $args { |
44 | | - * Optional. An array of options for the endpoint. This can be a single associative |
45 | | - * array for one endpoint, or an array of associative arrays for multiple endpoints. |
46 | | - * Default empty array. |
47 | | - * |
48 | | - * @type string|array $methods Required. HTTP method(s) the route |
49 | | - * responds to. Can be a string or an array |
50 | | - * (e.g. 'GET', 'POST', ['GET', 'POST']). |
51 | | - * @type callable $callback Required. The callback function to handle |
52 | | - * the request. Accepts a `WP_REST_Request` |
53 | | - * and returns a `WP_REST_Response` or array. |
54 | | - * @type callable $permission_callback Required. A function to check if the |
55 | | - * request has permission. Must return |
56 | | - * `true` or `WP_Error`. |
57 | | - * @type array $args { |
58 | | - * Optional. An associative array of argument schema for validation and |
59 | | - * sanitization. |
60 | | - * Keys are argument names, values are arrays of argument options: |
61 | | - * |
62 | | - * @type bool $required Whether this parameter is required. |
63 | | - * Default false. |
64 | | - * @type string $type Data type: 'string', 'integer', 'boolean', |
65 | | - * 'array', etc. |
66 | | - * @type mixed $default Default value if the parameter is not |
67 | | - * provided. |
68 | | - * @type callable $validate_callback Callback to validate the parameter. |
69 | | - * @type callable $sanitize_callback Callback to sanitize the parameter. |
70 | | - * @type array $enum Allowed values (enumeration). |
71 | | - * @type array $items Schema for array items if type is 'array'. |
72 | | - * } |
73 | | - * } |
74 | | - * @param bool $override Optional. True to override existing route, false to merge (with newer overriding |
75 | | - * if duplicate keys exist). Default false. |
| 27 | + * @param string $route The base URL for route you are adding. |
| 28 | + * @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for |
| 29 | + * multiple methods. Default empty array. |
| 30 | + * @param bool $override Optional. If the route already exists, should we override it? True overrides, |
| 31 | + * false merges (with newer overriding if duplicate keys exist). Default false. |
76 | 32 | * @return bool True on success, false on error. |
77 | | - * |
78 | 33 | */ |
79 | 34 | function register_rest_route( $route_namespace, $route, $args = array(), $override = false ) { |
80 | 35 | if ( empty( $route_namespace ) ) { |
|
0 commit comments