Default value of block attributes stored as meta not respected. #4494
Labels
Core REST API Task
Task for Core REST API efforts
[Feature] Extensibility
The ability to extend blocks or the editing experience
REST API Interaction
Related to REST API
[Type] Bug
An existing feature does not function as intended
[Type] WP Core Ticket
Requires an upstream change from WordPress. Core Trac ticket should be linked.
Milestone
Issue Overview
My goal is to have a block attribute stored in meta, that has a default value, for new posts that is not false. Currently the initial value of an attribute, stored as post meta, is always false.
Steps to Reproduce (for bugs)
register_meta
to register field in Rest API.Notice that I tried to set the default value using
schema.default
because that's how the REST API expects it. See: https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php#L71WordPress explicitly disallows, via the
register_meta_args
using an index ofschema
ordefault
in that function. :(3. Create a new post.
4. Add block to post.
5. Notice default value is false, not true.
6. Sad face emojis.
Expected Behavior
I expect the block attribute's default to be true, or whatever is set in the block.
Current Behavior
The default value is always false. The reason it is false, is that
get_metadata()
always returns false, before the filter on the return value runs if it's called.Possible Solution
_wp_register_meta_args_whitelist()
prevents doing so.Todos
The text was updated successfully, but these errors were encountered: