[wp-trac] [WordPress Trac] #49339: Issue when comparing old and new meta of type integer on update_multi_meta_value
WordPress Trac
noreply at wordpress.org
Sat Feb 1 15:04:25 UTC 2020
#49339: Issue when comparing old and new meta of type integer on
update_multi_meta_value
--------------------------+-----------------------------
Reporter: renathoc | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
Hi there!
I found an issue when updating a meta through JS (REST API). I'm using a
plugin sidebar to update a post meta with the type `integer`.
When I update the meta value, the
`WP_REST_Meta_Fields::update_multi_meta_value` method tries to compare the
old and the new values to remove and add only the necessary.
But the `$current = get_metadata( $meta_type, $object_id, $meta_key, false
);` line always return an `array` of `string` and the `$values` is
correctly an `array` of `integer`. So any value doesn't match, and all old
post metas are deleted and all new post metas are added.
The line that tries to compare is: `$remove_keys = array_keys( $to_remove,
$value, true );`
**Example:**
- We have as a post metas: `[ 1, 2 ]` and try to update for `[ 2, 3 ]`
- It's removing the `1` and `2`. And after that it's adding the `2` and
`3`
- It should remove the `1` and add the `3`
**Workaround:**
As a workaround, I'm thinking to use temporarily `get_post_metadata` to
return the value correctly (as integer).
**The steps to reproduce:**
I created a clean repo with the scenario to make it easier to simulate:
https://github.com/renatho/meta-type-test-plugin/tree/master
- Clone the repo
- Run `npm i && npm run build`.
- Add the plugin to a WP env.
- Go to a post.
- Click on the smile on the top right.
- Change between the options clicking on the buttons and saving the post.
- Check the post comments to see the result.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49339>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list