0
我使用wordpress REST API 2. 我爲我的插件註冊了以下路由。路由始終無效
register_rest_route('test-api', '/testRoom', array(
'methods' => 'GET',
'callback' => 'one'
));
的API:
class testRoomPlg
{
public function __construct()
{
add_action('rest_api_init', array($this, 'registerApiRoutes'));
}
public function registerApiRoutes()
{
// header("Access-Control-Allow-Origin: *");
register_rest_route('test-api', '/testRoom', array(
'methods' => 'GET',
'callback' => 'one'
));
}
public function one()
{
var_dump('here');exit;
}
}
#kick start the plugin here
add_action('plugins_loaded', 'loadAPI');
function loadAPI()
{
$setup = new testRoomPlg();
}
而且我訪問這樣的:
http://localhost/testRoom/index.php/wp-json/test-api/testRoom
我發現,而在本地主機,需要WP之前添加的index.php -json像這樣:
http://localhost/testRoom/index.php/wp-json/