[wp-trac] [WordPress Trac] #42810: Updating metadata via the REST API fails when sanitized values match existing values

WordPress Trac noreply at wordpress.org
Mon Sep 17 18:06:53 UTC 2018


#42810: Updating metadata via the REST API fails when sanitized values match
existing values
--------------------------------------+-----------------------
 Reporter:  bradyvercher              |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  5.0
Component:  REST API                  |     Version:  4.7
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  rest-api
--------------------------------------+-----------------------
Changes (by boonebgorges):

 * focuses:   => rest-api
 * milestone:  Awaiting Review => 5.0


Comment:

 I'd like to flag this as a Gutenberg blocker, because of the following
 situation:

 1. You have a post with more than one block that uses post meta attributes
 2. One or more of those blocks save their data as a JSON-encoded string,
 as recommended in the documentation
 https://wordpress.org/gutenberg/handbook/block-
 api/attributes/#considerations
 3. You save the post without modifying the data in one or more of the
 blocks

 Because the REST API uses *slashed* data to compare with the existing
 values, but `get_metadata()` returns *unslashed* data, most JSON-encoded
 strings will look "new" to the REST API
 https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/rest-
 api/fields/class-wp-rest-meta-fields.php?marks=299,301#L287 But
 `update_metadata()` correctly compares unslashed-to-unslashed values, so
 returns `false`. Not only does this cause an "Updating failed" notice in
 Gutenberg, but because of the way that the `update_value()` method returns
 early out of the `foreach()` loop, blocks further down the page are not
 processed. https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-
 includes/rest-api/fields/class-wp-rest-meta-
 fields.php?marks=131,163-165#L129

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/42810#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list