REST API ‘results’ bug due WP update 5.5
-
Hi folks,
I found a bug in the REST API due to the wordpress update 5.5
While calling an event to update the results, nothing will happen. Here is the call to event endpoint:
https://localhost/wp-json/sportspress/v2/events/<ID> { "results":{ "<TEAM_A_ID>":{ "first":"10", "second":"0", "total":"", "outcome":"" }, "<TEAM_B_ID":{ "first":"6", "second":"0", "total":"", "outcome":"" } } }
I already investigated on this and here are my insights:
I found out the location where the problem is happening, but I don’t have an idea how to fix it.
The WP update changed the wp-includes/rest-api.php at line 1859 within the method rest_sanitize_value_from_schema:if ( 'array' === $args['type'] ) { $value = rest_sanitize_array( $value ); ...
rest_sanitize_array will give us a normalized array, which has no more information about the team ids.
In wordpress 5.4 you will find the previous coda at line 1433:
if ( 'array' === $args['type'] ) { if ( empty( $args['items'] ) ) { return (array) $value; } ...
The different behaviour causes that within sportspress class-sp-rest-api.php the method update_post_meta_arrays can’t do the merge correctly. Because the $value parameter has no more team id information
public static function update_post_meta_arrays( $value, $object, $field_name )
In WP 5.4 the $value array looked like:
$value: <TEAM_A_ID>:array(4) first: "10" second: "" total: "" outcome: "" <TEAM_B_ID>:array(4) first: "6" second: "" total: "" outcome: ""
In WP 5.5 the $value looks like:
$value: 0:array(4) first: "10" second: "" total: "" outcome: "" 1:array(4) first: "6" second: "" total: "" outcome: ""
Any idea how to fix this?
Thanks in advance
Chris
- The topic ‘REST API ‘results’ bug due WP update 5.5’ is closed to new replies.