admin管理员组文章数量:1023773
He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
Share
Improve this question
asked Apr 12, 2019 at 14:34
TTTTTT
3291 gold badge4 silver badges17 bronze badges
4
|
1 Answer
Reset to default 3Check if your code looks like this because in the question you pass each method as separate function arguments (I have overlooked it earlier)
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
array('methods' => 'GET',
'callback' => 'GET_form',
),
array('methods' => 'POST',
'callback' => 'post_form'
)
)
);
});
As you can read in documentation:
Parameters #
$args - (array) (Optional)
Either an array of options for the endpoint, or an array of arrays for multiple methods.
Default value: array()
He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
Share
Improve this question
asked Apr 12, 2019 at 14:34
TTTTTT
3291 gold badge4 silver badges17 bronze badges
4
-
Yes, it's correct syntax. As you can read in codex:
$args
- Either an array of options for the endpoint, or an array of arrays for multiple methods. – nmr Commented Apr 12, 2019 at 14:45 - @nmr keep comments for clarifying questions, and post answers as answers, afterall I can't upvote your comment and TTT can't mark it as the answer – Tom J Nowell ♦ Commented Apr 12, 2019 at 14:50
- @TomJNowell OK, it seemed to mee too insignificant to write as an answer. – nmr Commented Apr 12, 2019 at 14:52
- Sometimes the answer is simple short and wellformed, don't let that discourage you from posting it! – Tom J Nowell ♦ Commented Apr 12, 2019 at 14:53
1 Answer
Reset to default 3Check if your code looks like this because in the question you pass each method as separate function arguments (I have overlooked it earlier)
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
array('methods' => 'GET',
'callback' => 'GET_form',
),
array('methods' => 'POST',
'callback' => 'post_form'
)
)
);
});
As you can read in documentation:
Parameters #
$args - (array) (Optional)
Either an array of options for the endpoint, or an array of arrays for multiple methods.
Default value: array()
本文标签: rest apiCan I define multiple callback methods depending on the call method
版权声明:本文标题:rest api - Can I define multiple callback methods depending on the call method? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745596082a2158178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$args
- Either an array of options for the endpoint, or an array of arrays for multiple methods. – nmr Commented Apr 12, 2019 at 14:45