Merge pull request #340 from fwatteau/master
The Metrics data are updatables by rest api
This commit is contained in:
@@ -430,7 +430,6 @@ class SP_REST_API {
|
|||||||
'update_callback' => 'SP_REST_API::update_post_meta_array',
|
'update_callback' => 'SP_REST_API::update_post_meta_array',
|
||||||
'schema' => array(
|
'schema' => array(
|
||||||
'description' => __( 'Metrics', 'sportspress' ),
|
'description' => __( 'Metrics', 'sportspress' ),
|
||||||
'type' => 'array',
|
|
||||||
'context' => array( 'view', 'edit' ),
|
'context' => array( 'view', 'edit' ),
|
||||||
'arg_options' => array(
|
'arg_options' => array(
|
||||||
'sanitize_callback' => 'rest_sanitize_request_arg',
|
'sanitize_callback' => 'rest_sanitize_request_arg',
|
||||||
@@ -564,6 +563,11 @@ class SP_REST_API {
|
|||||||
* @return bool|int
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public static function update_post_meta_array( $value, $object, $field_name ) {
|
public static function update_post_meta_array( $value, $object, $field_name ) {
|
||||||
|
// Convert PHP object to array
|
||||||
|
if ( is_object( $value ) ) {
|
||||||
|
$value = (array) $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! is_array( $value ) ) return false;
|
if ( ! is_array( $value ) ) return false;
|
||||||
|
|
||||||
$type = $object->post_type;
|
$type = $object->post_type;
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$metric = sp_array_value( $metrics, $key, null );
|
$metric = sp_array_value( $metrics, $key, null );
|
||||||
if ( $metric == null )
|
if ( $metric == null )
|
||||||
continue;
|
continue;
|
||||||
$data[ $value ] = sp_array_value( $metrics, $key, ' ' );
|
$data[ $key ] = sp_array_value( $metrics, $key, ' ' );
|
||||||
endforeach;
|
endforeach;
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user