sc0ttkclark / wordpress-fields-api

The 2024 Fields API proposal for WordPress Core
https://make.wordpress.org/core/tag/fields-api/
361 stars 42 forks source link

Support client-side rendering: allow multiple renderers? #92

Closed citelao closed 1 year ago

citelao commented 7 years ago

Wordpress seems to be moving towards client-side rendering and a more JS-driven experience, and we should build the Fields API in a way that supports such an upgrade.

We currently lack a good solution.

The problem

The Fields API is not designed to handle the rigors of cross-language rendering (or even having multiple render methods at all):

Possible solution

One solution is to build a pluggable render system:

That way we could render the "New Post" form by, e.g., outputting a JSON blob of the form data and enqueuing a script that rendered the form in React.

Caveats

This system, however, lacks a sensible modularity. There are two ways to implement a custom render system, and both have flaws for plugin authors:

Further thoughts

Perhaps the clearest next step would be adding validation to field/form registration, since that lets field type creators verify field options without forcing them to duplicate code for different languages or render methods.

But the rest is unclear. It may only become necessary when developers begin writing their own custom field types---once that begins, we certainly won't be able to change our render method without breaking their fields.

Next steps