admin管理员组

文章数量:1326638

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

本文标签: phpwhat is the best practice to add new field to an api route