admin管理员组文章数量:1317740
I need to just handle outer request to my WordPress by: http://localhost/vku.dev/wp-json/notifications. No need to add additional parts to whole URL. So, my code is:
function testREST(WP_REST_Request $request) {
error_log('Route "notifications" works');
return 'Route "notifications" works';
//return new WP_REST_Response(true, 200);
}
add_action('rest_api_init', function () {
/*
// Inline function also not working
register_rest_route('notifications', '', [
'methods' => 'GET',
'callback' => function (WP_REST_Request $request) {
error_log('Route "notifications" works');
return 'Route "notifications" works';
//return new WP_REST_Response(true, 200);
},
]);
*/
register_rest_route('notifications', '', [
'methods' => 'GET',
'callback' => 'testREST',
]);
});
Code looks simplest, but not working - http://localhost/vku.dev/wp-json/notifications provide me with the dump of some object, body of event handler not reachable. What's wrong?
I need to just handle outer request to my WordPress by: http://localhost/vku.dev/wp-json/notifications. No need to add additional parts to whole URL. So, my code is:
function testREST(WP_REST_Request $request) {
error_log('Route "notifications" works');
return 'Route "notifications" works';
//return new WP_REST_Response(true, 200);
}
add_action('rest_api_init', function () {
/*
// Inline function also not working
register_rest_route('notifications', '', [
'methods' => 'GET',
'callback' => function (WP_REST_Request $request) {
error_log('Route "notifications" works');
return 'Route "notifications" works';
//return new WP_REST_Response(true, 200);
},
]);
*/
register_rest_route('notifications', '', [
'methods' => 'GET',
'callback' => 'testREST',
]);
});
Code looks simplest, but not working - http://localhost/vku.dev/wp-json/notifications provide me with the dump of some object, body of event handler not reachable. What's wrong?
Share Improve this question asked Nov 2, 2020 at 10:33 Valery BulashValery Bulash 1112 bronze badges 2 |1 Answer
Reset to default 1Exact namespace prefix and non-empty endpoint name helped me:
add_action('rest_api_init', function () {
register_rest_route('vku/notifications', 'test', [
'methods' => 'GET',
'callback' => function (WP_REST_Request $request) {
error_log('Route "notifications" works');
return new WP_REST_Response(true, 200);
},
]);
});
本文标签: phpSimple Wordpress endpoint route doesn39t work
版权声明:本文标题:php - Simple Wordpress endpoint route doesn't work 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742019738a2414433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
register_rest_route('vku/notifications', test'', [...
works well. Thanks a lot – Valery Bulash Commented Nov 2, 2020 at 13:41