wp-api-meta-endpoints icon indicating copy to clipboard operation
wp-api-meta-endpoints copied to clipboard

Implement new-style meta with register_meta

Open rmccue opened this issue 9 years ago • 5 comments

This is a first pass at new-style meta support for the REST API.

With the new register_meta support in 4.6, we can now support meta fully, as it's actually a registered thing instead of being a vague mess.

This PR includes a brand new README as well, which documents how to use this. tl;dr set show_in_rest => true in your register_meta call, then use the meta field on the regular endpoints.

Important note: this is not ready for merge yet, and still requires security checks and further validation.

rmccue avatar Sep 19 '16 22:09 rmccue

Current coverage is 100% (diff: 100%)

No coverage report found for master at 70cdd51.

Powered by Codecov. Last update 70cdd51...d2c4126

codecov-io avatar Sep 28 '16 22:09 codecov-io

Coverage is now at 100%, ready for review I think!

rmccue avatar Sep 29 '16 20:09 rmccue

I've been playing and noticed some things:

  • I can update a metakey to be anything (array, object, etc) if its registered type is not string, number or bool
  • a metavalue doesn't update or delete correctly, it would be nice to get a error (it does mostly)
  • if I try to update a metakey which was registered single=true with an array it saves it as a serialized array then throws an array to string conversion notice on GET

I haven't been thorough, not sure if that's the type of thing you're looking for.

tharsheblows avatar Oct 05 '16 20:10 tharsheblows

@tharsheblows Thanks for the feedback! We're discussing these in slack and the update function definitely needs to be tightened up, that array casting issue is definitely a bug and making the update stricter should address the first item too

kadamwhite avatar Oct 06 '16 14:10 kadamwhite

There are also a slight issue when deleting multiple identical meta_values for a given meta_key in update_multi_meta_value. So eg if you have postmeta_multiple_number: [ 11, 13, 13, 13, 13 ],

you'll get an error when you delete / update it because it tries to do all of the 13s one at a time and they all get done at once by delete_metadata I think. I had an issue when updating to multiple identical meta_values but I can't reproduce it.

tharsheblows avatar Oct 06 '16 15:10 tharsheblows