wordpress - 隐藏 WordPress Rest API 端点定义

标签 wordpress rest api hook wordpress-rest-api

我想在 WordPress rest api 中隐藏端点的定义...在 https://www.wpwhitesecurity.com/wp-json 的情况下我想返回一个 404 或一个空数组,而不是站点的端点列表。

一些想法?

谢谢!

最佳答案

从版本 4.4.0 开始存在 Hook rest_index,文档在 https://developer.wordpress.org/reference/hooks/rest_index/ 中描述:

This contains the data describing the API. This includes information about supported authentication schemes, supported namespaces, routes available on the API, and a small amount of data about the site.

下一个代码可以完美地满足我的需要:

function my_site_rest_index( $response ){
    return array();
}
add_filter('rest_index', 'my_site_rest_index');

关于wordpress - 隐藏 WordPress Rest API 端点定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47568286/

相关文章:

javascript - 计算价格并显示在 WooCommerce 产品单页的价格下(简单价格,可变价格)

php - 优化 Wordpress 图片上传,在 Dedicated 上速度慢且一次只能上传 1 张

php - 在 woocommerce 结账时添加自定义税值

python - 如何实现Python REST认证

javascript - 从 addCard trello API 创建 trello 卡后如何捕获它的链接?

javascript - 如何在 Google Maps API 中指示语言?

php - 按 WP_Query 中的自定义字段(数字)排序

javascript - 仅使用 JavaScript 调用 Marketo API

javascript - 如何使用 Restangular 将我的任务添加回我的列表

javascript - 使用 multer 转发上传图像请求(javascript,express)