我有一个自定义帖子类型的元框,其中有一个链接。此链接指向wp json rest API中的端点。在我使用的rest API的端点上current_user_can 验证用户是否已登录。
这是端点,只是更改了名称:
register_rest_route( \'myapi\', \'/download_file/\', array(
\'methods\' => \'GET\',
\'callback\' => \'file\',
\'permission_callback\' => function () {
return current_user_can(\'administrator\');
}
) );
端点下载文件。关键是您必须登录才能下载文件。然而,当我点击链接时,我得到一个
403.
这是链接标记:
<a href="http://example.com/wp-json/myapi/download_file" target="_blank">
Download file
</a>
我是否需要向此链接添加其他内容?或者做一个post请求,证明我已经登录?
编辑:也许这就是问题所在:
On login, wordpress uses the wordpress_[hash] cookie to store your authentication details. Its use is limited to the admin console area, /wp-admin/
从…起here.