WP Rest API寄存器端点

时间:2016-10-08 09:45:31

标签: wordpress rest api oauth-2.0

我尝试使用WP Rest API注册自定义端点,我实现了这样的功能:

add_action('rest_api_init', 'myplugin_register_routes');

/**
* Register the /wp-json/myplugin/v1/foo route
*/
function myplugin_register_routes() {
register_rest_route( 'myplugin/v1', 'foo', array(
    'methods'  => WP_REST_Server::READABLE,
    'callback' => 'myplugin_serve_route',
) );
}


/**
* Generate results for the /wp-json/myplugin/v1/foo route.
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_REST_Response|WP_Error The response for the request.
*/
function myplugin_serve_route( WP_REST_Request $request ) {
// Do something with the $request

// Return either a WP_REST_Response or WP_Error object
return $response;
}

但我收到这样的错误:

[{" code":" json_no_route"," message":"没有路由提供URL和模式之间的映射\ u00e0请求&# 34;}]

如何为我的oauth配置和WP REST API创建安全端点?

0 个答案:

没有答案