10up / wp-scaffold

10up WordPress project scaffold.
MIT License
184 stars 46 forks source link

Add a standardised way to register post meta and REST fields #227

Open darylldoyle opened 3 months ago

darylldoyle commented 3 months ago

Is your enhancement related to a problem? Please describe.

Coming out of #218 @nicholasio asked the following:

Could we add a more structured way for registering custom fields? I'd love to use register_rest_field and/register_meta registering custom fields in this way where you also declare the "schema" makes things easier for headless projects. I'm thinking mostly from a REST API standpoint and not really thinking about us creating a wrapper around rendering the custom fields in the editor.

The end goal here is to make sure we're consistent in how we are exposing custom fields through the REST API. There are lots of ways to do it and it doesn't always get added to the REST API schema.

See this for example: https://github.com/10up/headstartwp/blob/develop/wp/headless-wp/includes/classes/Preview/PreviewLink.php#L36

This is a great opportunity to look at providing a better way to register post meta within the scaffold.

Whatever we provide must be easy-to-use, whilst being flexible for those who need to utilize all options.

This issue is here to discuss approaches before any implementation happens.