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 like this:
http://localhost/testRoom/index.php/wp-json/