Merge pull request #340 from fwatteau/master

The Metrics data are updatables by rest api
This commit is contained in:
Brian Miyaji
2020-08-06 13:15:40 +10:00
committed by GitHub
2 changed files with 6 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;
} }