小编ed2*_*ed2的帖子

在哪里注册到 WordPress 插件端点的 REST 路由

注册功能必须去哪里?( register_rest_route())

  • 它必须在 theme/child function.php 中吗?
  • 或者可以在插件基础 php 文件中吗?(例如\wp-content\plugins\example\example.php)

有任何文件可以澄清这一点吗?

官方文档中没有提到: https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/

同样,端点函数必须存储在哪里?注册函数只是命名它,而不指定它的路径。

例如,你可以这样做:

  • 注册函数调用 ( register_rest_route) 位于主插件文件中(例如 \wp-content\plugins\example\example.php)
  • 端点函数位于其他一些插件文件中(例如 \wp-content\plugins\example\sub-path-stuff\example-controller.php)

如果是这样,怎么办?

以下链接似乎尝试执行此操作,但未指定这些属性(例如 \wp-content\plugins\example\example.php)

php wordpress routes wordpress-rest-api wordpress-plugin-creation

6
推荐指数
1
解决办法
2万
查看次数