最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - what is the best practice to add new field to an api route

programmeradmin6浏览0评论

I'm modifying the WP REST API for mobile app usage, and I went through at the first registering new fields route using the rest_api_init action or hook using the func register_rest_field, but I found there's a lot of fields I don't need it or wanted so I get rid of it by using the filter rest_prepare_post

What I found out is I can actually add new fields in my filter by modifying the data array and no needs for the rest_api_init or register_rest_field at all.

So what I am asking is what is the best approach for doing this? is it good to add and remove fields in one function instead of two? I'm now using both register_route_field for the new fields and unset all the unnecessary fields by rest_prepare_post

发布评论

评论列表(0)

  1. 暂无评论