[wp-trac] [WordPress Trac] #35574: Add REST API JSON schema information to WP_Widget
WordPress Trac
noreply at wordpress.org
Sun Apr 23 23:27:59 UTC 2017
#35574: Add REST API JSON schema information to WP_Widget
------------------------------------------+-----------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Widgets | Version: 2.8
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses: rest-api
------------------------------------------+-----------------------------
Comment (by westonruter):
Replying to [comment:30 wonderboymusic]:
> why is this so coupled to the potential transport mechanism?
Coupled to a potential transport mechanism meaning JSON? If the data is to
be able to be manipulated by JavaScript, which it should eventually, then
the widget instance data should be representable as JSON, so defining a
JSON Schema would enforce that. If a widget instance should store more
than what is `JsonSerializable`, then that would mean there would have to
be conversion between the internal PHP representation and the external
JSON representation, which I understand to be what you mean by having a
REST decorator. If we need that additional level of abstraction of an
internal-vs-external data representation, as I noted in the previous
comment, but in my experience it is seldom needed.
If there was a need for some richer type (e.g. `DateTime`), a custom
`type` could be used in the widget's schema, but the the REST controller
(decorator) could be handle the conversion of the JSON representation to
the PHP representation. Right?
> your first approach was sufficient in its idea - setting default props
for the widget instance.
Beyond having default props for a widget instance, it is useful to have a
full schema which can then be read by the `WP_Widget::update()` method to
automate the sanitization of instance changes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35574#comment:31>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list