ThemeBoy / SportsPress

An open source league statistics plugin for WordPress created by ThemeBoy.
Other
147 stars 98 forks source link

REST API - Metrics are not updatables #339

Closed fwatteau closed 4 years ago

fwatteau commented 5 years ago

Hi,

When i GET a player data by rest api (/wp-json/sportspress/v2/players/123), i'have the response : ` ... "metrics":{ "points": "500" },

`

But, when i PUT a player data with the same data in body, i've got an 400 error with message Paramètre(s) non valide(s) : metrics.

The problem are the conversion between PHP object and JSON.

Franck,

ryandavis84 commented 4 years ago

Is there any chance that this will be fixed soon?

ryandavis84 commented 4 years ago

So if you update class-sp-rest-api.php the metrics rest field, so that the update_callback is recursive, then you this will work with your changes.

register_rest_field( 'sp_player', 'metrics', array( 'get_callback' => 'SP_REST_API::get_post_data', 'update_callback' => 'SP_REST_API::update_post_meta_recursive', 'schema' => array( 'description' => __( 'Metrics', 'sportspress' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'sanitize_callback' => 'rest_sanitize_request_arg', ), ), ) );

fwatteau commented 4 years ago

I don't know, i abandoned this plugin for custom dev.

So if you update class-sp-rest-api.php the metrics rest field, so that the update_callback is recursive, then you this will work with your changes.

register_rest_field( 'sp_player', 'metrics', array( 'get_callback' => 'SP_REST_API::get_post_data', 'update_callback' => 'SP_REST_API::update_post_meta_recursive', 'schema' => array( 'description' => __( 'Metrics', 'sportspress' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'sanitize_callback' => 'rest_sanitize_request_arg', ), ), ) );