function display_player_stats_on_match_shortcode($atts) { // Shortcode attributes with default values $atts = shortcode_atts(['match_id' => ''], $atts, 'player_stats_on_venue'); // Validate match ID if (empty($atts['match_id'])) { return '
Error: Match ID is required.
'; } $match_id = sanitize_text_field($atts['match_id']); $match_info_url = API_CALL_BASE_URL . "v4/matches/$match_id/advance?token=" . GENERATE_DRAFT_TOKEN; // Fetch match info $match_response = wp_remote_get($match_info_url); if (is_wp_error($match_response)) { // Debug API request error return 'Error: Unable to fetch match info. Debug: ' . $match_response->get_error_message() . '
'; } $match_response_code = wp_remote_retrieve_response_code($match_response); if ($match_response_code !== 200) { // Debug non-200 response return 'Error: Unable to fetch match info. API returned an error code: ' . $match_response_code . '
'; } $match_data = json_decode(wp_remote_retrieve_body($match_response), true); // Debug: Show the full match data array live on the page $debug_output = '' . print_r($match_data, true) . ''; // Extract venue and team data $venue_name = $match_data['response']['items']['info']['venue']['name'] ?? 'Unknown Venue'; $team1_name = $match_data['response']['items']['info']['teama']['name'] ?? 'Team 1'; $team2_name = $match_data['response']['items']['info']['teamb']['name'] ?? 'Team 2'; // Extract player stats $batting_stats_team1 = $match_data['response']['items']['player_batting_stats_on_venue']['team1'] ?? []; $bowling_stats_team1 = $match_data['response']['items']['player_bowling_stats_on_venue']['team1'] ?? []; $batting_stats_team2 = $match_data['response']['items']['player_batting_stats_on_venue']['team2'] ?? []; $bowling_stats_team2 = $match_data['response']['items']['player_bowling_stats_on_venue']['team2'] ?? []; // Debug: Show extracted data live on the page $debug_output .= '
' . print_r($batting_stats_team1, true) . ''; $debug_output .= '
' . print_r($bowling_stats_team1, true) . ''; $debug_output .= '
' . print_r($batting_stats_team2, true) . ''; $debug_output .= '
' . print_r($bowling_stats_team2, true) . ''; // Build the HTML output $html = "
No batting stats available.
'; } $html = "Player | Innings | Runs | 50s | 100s | Average | Strike Rate |
---|---|---|---|---|---|---|
{$player['batsman_title']} | {$player['innings']} | {$player['runs']} | {$player['run50']} | {$player['run100']} | {$player['average']} | {$player['strike']} |
No bowling stats available.
'; } $html = "Player | Innings | Balls | Runs | Wickets | Economy | Average | Strike Rate |
---|---|---|---|---|---|---|---|
{$player['bowler_title']} | {$player['innings']} | {$player['balls']} | {$player['runs']} | {$player['wickets']} | {$player['econ']} | {$player['average']} | {$player['strike']} |