简体   繁体   English

从Wordpress插件访问Wordpress Rest API

[英]Access wordpress rest api from wordpress plugin

The question may seems dumb but i need to access wordpress's default rest api from my custom wordpress plugin so that i can modify further for my custom api endpoints and post data to a third party api. 这个问题似乎很愚蠢,但是我需要从我的自定义wordpress插件访问wordpress的默认rest api,以便我可以进一步修改我的自定义api端点并将数据发布到第三方api。

I need to access and have all the data and functionalities of the existing rest api but i don't want to fetch data from database by querying again. 我需要访问并拥有现有rest api的所有数据和功能,但我不想通过再次查询从数据库中获取数据。 Instead i want to call the rest api directly from plugin. 相反,我想直接从插件调用其余的api。

Now the problem it doesn't seems right to calling rest api from a plugin. 现在的问题似乎是从插件调用rest api并不正确。 If i want to avoid querying again from database is this a valid approach (calling rest api) or there are other better ways to do that? 如果我想避免再次从数据库中查询,这是一种有效的方法(调用rest api)还是有其他更好的方法呢?

According to the Wordpress Rest API HandBook, To modify Responses, You can use register_rest_field and register_meta . 根据Wordpress Rest API手册,要修改响应,您可以使用register_rest_fieldregister_meta

More Details : Modifying Responses 更多详细信息: 修改响应


To Create an Endpoint you can use , register_rest_route() . 要创建一个端点,您可以使用register_rest_route()

More Details : Routes and Endpoints 更多详细信息: 路线和终点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM