• Resolved sagund07

    (@sagund07)


    Hey,

    I have a another problem with the sportspress API in combination with offense/defense configuration.

    I am developing a frontend Result and Stat Submission Plugin which can be used by teams to enter the stats directly into sportspress via a frontend page. It worked until a certain point.

    I tried to find the reason why it stopped working and after some resarch I found out that changing the Performance type in the sportspress Event settings from “Combined” to “Offense -> Defense” caused the malfunction.

    In detail:

    I tried to enter some stats via the sportspress backend and entered the same stats in my plugin to compare the API output when calling “wp-json/sportspress/v2/events/id”. Surprisingly both outputs were identical. BUT when entering the stats through my plugin the stats wouldn’t show up in the event. Instead I get: “No data available in table”.

    I looked up the submitted stats in the database and found out, that the API don’t set the “sp_offense” and “sp_defense” players.

    Database after sportspress submission: https://i.imgur.com/VyiHB27.jpg
    Database after plugin submission: https://i.imgur.com/6NlqyT5.jpg

    I know, that there is a difference in the “players” field of the json output when using “Combined” or “Offense -> Defense”. When using “Combined” then “players”:[0,…,0,…] but when using “Offense -> Defense” then “players”:[0,…,0,…,0,…,0,…].

    Am I missing some json parameter to make this work or did you forget to implement setting the sp_offense and sp_defense values?

    • This topic was modified 8 years, 5 months ago by sagund07.
    • This topic was modified 8 years, 5 months ago by sagund07.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sagund07

    (@sagund07)

    Okay I fixed it myself. Maybe you can take my fix for next updates.

    File: includes/api/class-sp-rest-api.php

    Added code in line 153

    register_rest_field( 'sp_event',
    	'offense',
    	array(
    		'get_callback'    => 'SP_REST_API::get_post_meta_recursive',
    		'update_callback' => 'SP_REST_API::update_post_meta_recursive',
    		'schema'          => array(
    			'description'     => __( 'Offense', 'sportspress' ),
    			'type'            => 'array',
    			'context'         => array( 'view', 'edit' ),
    			'arg_options'     => array(
    				'sanitize_callback' => 'rest_sanitize_request_arg',
    			),
    		),
    	)
    );
    		
    register_rest_field( 'sp_event',
    	'defense',
    	array(
    		'get_callback'    => 'SP_REST_API::get_post_meta_recursive',
    		'update_callback' => 'SP_REST_API::update_post_meta_recursive',
    		'schema'          => array(
    			'description'     => __( 'Defense', 'sportspress' ),
    			'type'            => 'array',
    			'context'         => array( 'view', 'edit' ),
    			'arg_options'     => array(
    				'sanitize_callback' => 'rest_sanitize_request_arg',
    			),
    		),
    	)
    );

    and in line 759

    'offense' => 'sp_offense',
    'defense' => 'sp_defense',
    • This reply was modified 8 years, 5 months ago by sagund07.
    • This reply was modified 8 years, 5 months ago by sagund07.
    Plugin Author Brian

    (@brianmiyaji)

    @sagund07 You’re awesome! Yep, the offense/defense hasn’t been added to the API yet, will include this in the next update ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Offense/Defense API’ is closed to new replies.