apply_filters( 'sports_bench_game_events', $html, $events, $away_team, $home_team, $sport )

Type

Filters

Section

Game Recap

Outputs the HTML for the game events table for a game

Parameters

  • $html, string, the current HTML for the game events table
  • $events, array, the list of game events for the selected game
  • $away_team, Sports_Bench_Team object, the team object for the away team
  • $home_team, Sports_Bench_Team object, the team object for the home team
  • $sport, string, the sport that's being used on the site

Returns

  • string, the HTML for the game events table

Since: 1.5

Source: baseball-game-info.php, line 123; football-game-info.php, line 53; hockey-game-info.php, line 55; rugby-game-info.php, line 54; soccer-game-info.php, line 52

Example

/**
 * Returns the html for the game events table for a game recap
 *
 * @param string $html
 *
 * @param array $events
 *
 * @param Sports_Bench_Team $away_team
 *
 * @param Sports_Bench_Team $home_team
 *
 * @param string $sport
 *
 * @return string, html for the game events table
 *
 * @since 1.5
 */
function sports_bench_do_game_events( $html, $events, $away_team, $home_team, $sport ) {
	if ( 'baseball' == $sport ) {
		$html = '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		$html .= '';
		foreach ( $events as $event ) {
			if ( $event->game_info_top_bottom == 'Top' ) {
				$logo = $away_team->get_team_photo( 'team-logo' );
				$team = $away_team;
			} else {
				$logo = $home_team->get_team_photo( 'team-logo' );
				$team = $home_team;
			}
			$table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team );
			$html .= '';
			$html .= '';
			$html .= '';
			$html .= '';
			$html .= '';
			$html .= '';
		}
		$html .= '';
		$html .= '
' . $away_team->get_team_photo( 'team-logo' ) . '
' . $away_team->team_abbreviation . '
' . $home_team->get_team_photo( 'team-logo' ) . '
' . $home_team->team_abbreviation . '
' . $logo . '
' . $event->game_info_top_bottom . ' ' . $event->game_info_inning . '
' . $event->game_info_away_score . '' . $event->game_info_home_score . '' . $event->game_info_score_play . '
'; } elseif ( 'football' == $sport ) { $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $quarter = 0; foreach ( $events as $event ) { $team = new Sports_Bench_Team( (int)$event->game_info_scoring_team_id ); if ( $event->game_info_quarter != $quarter ) { if ( $event->game_info_quarter == 1 ) { $html .= ''; $quarter = 1; } elseif ( $event->game_info_quarter == 2 ) { $html .= ''; $quarter = 2; } elseif ( $event->game_info_quarter == 3 ) { $html .= ''; $quarter = 3; } elseif ( $event->game_info_quarter == 4 ) { $html .= ''; $quarter = 4; } else { $html .= ''; $quarter = 'OT'; } } $table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= ''; $html .= '
' . __( 'First Quarter', 'sports-bench' ) . '
' . __( 'Second Quarter', 'sports-bench' ) . '
' . __( 'Third Quarter', 'sports-bench' ) . '
' . __( 'Fourth Quarter', 'sports-bench' ) . '
' . __( 'Overtime', 'sports-bench' ) . '
' . $event->game_info_time . '' . $event->game_info_play . '' . $event->game_info_away_score . '' . $event->game_info_home_score . '
'; } elseif ( 'hockey' == $sport ) { $goals = []; $penalties = []; foreach ( $events as $event ) { if ( $event->game_info_event == 'Goal' ) { array_push( $goals, $event ); } else { array_push( $penalties, $event ); } } $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $home_score = 0; $away_score = 0; $period = 0; if ( $goals ) { $html .= ''; foreach ( $goals as $goal ) { $player = new Sports_Bench_Player( (int) $goal->player_id ); $player_name = $player->player_first_name . ' ' . $player->player_last_name; $assist = ''; if ( $goal->game_info_assist_one_id ) { $assist_one = new Sports_Bench_Player( (int) $goal->game_info_assist_one_id ); $assist_one_player = $assist_one->player_first_name . ' ' . $assist_one->player_last_name; $assist = __( 'Assists: ', 'sports-bench' ) . $assist_one_player; } if ( $goal->game_info_assist_two_id ) { $assist_two = new Sports_Bench_Player( (int) $goal->game_info_assist_two_id ); $assist_two_player = $assist_two->player_first_name . ' ' . $assist_two->player_last_name; $assist .= ', ' . $assist_two_player; } $team = new Sports_Bench_Team( (int) $goal->team_id ); if ( $team->team_id == $away_team->team_id ) { $away_score += 1; } else { $home_score += 1; } if ( $goal->game_info_period != $period ) { if ( $goal->game_info_period == 1 ) { $html .= ''; $period = 1; } elseif ( $goal->game_info_period == 2 ) { $html .= ''; $period = 2; } elseif ( $goal->game_info_period == 3 ) { $html .= ''; $period = 3; } else { $html .= ''; $period = 4; } } $table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } } $period = 0; if ( $penalties ) { $html .= ''; foreach ( $penalties as $penalty ) { $player = new Sports_Bench_Player( (int) $penalty->player_id ); $player_name = $player->player_first_name . ' ' . $player->player_last_name; $team = new Sports_Bench_Team( (int) $penalty->team_id ); if ( $penalty->game_info_period != $period ) { if ( $penalty->game_info_period == 1 ) { $html .= ''; $period = 1; } elseif ( $penalty->game_info_period == 2 ) { $html .= ''; $period = 2; } elseif ( $penalty->game_info_period == 3 ) { $html .= ''; $period = 3; } else { $html .= ''; $period = 4; } } $table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } } $html .= ''; $html .= '
' . __( 'Goals', 'sports-bench' ) . '
' . __( 'First Period', 'sports-bench' ) . '
' . __( 'Second Period', 'sports-bench' ) . '
' . __( 'Third Period', 'sports-bench' ) . '
' . __( 'Overtime', 'sports-bench' ) . '
' . $goal->game_info_time . '' . __( 'Goal scored by ', 'sports-bench' ) . $player_name . '. ' . $assist . '' . $away_score . '' . $home_score . '
' . __( 'Penalties', 'sports-bench' ) . '
' . __( 'First Period', 'sports-bench' ) . '
' . __( 'Second Period', 'sports-bench' ) . '
' . __( 'Third Period', 'sports-bench' ) . '
' . __( 'Overtime', 'sports-bench' ) . '
' . $penalty->game_info_time . '' . $player_name . ' ' . $penalty->game_info_penalty . '
'; } elseif ( 'rugby' == $sport ) { $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ( $events as $event ) { $player = new Sports_Bench_Player( (int)$event->player_id ); $team = new Sports_Bench_Team( (int)$event->team_id ); $table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team ); $html .= ''; if ( $event->team_id == $away_team->team_id ) { $logo = $away_team->get_team_photo( 'team-logo' ); } else { $logo = $home_team->get_team_photo( 'team-logo' ); } $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . $away_team->get_team_photo( 'team-logo' ) . '
' . $away_team->team_abbreviation . '
' . $home_team->get_team_photo( 'team-logo' ) . '
' . $home_team->team_abbreviation . '
' . $logo . '
' . $event->game_info_time . '\'
' . $event->game_info_away_score . '' . $event->game_info_home_score . '' . $event->game_info_event . ' — ' . $player->player_first_name . ' ' . $player->player_last_name . '
'; } elseif ( 'soccer' == $sport ) { $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ( $events as $event ) { $team = new Sports_Bench_Team( (int)$event->team_id ); $player = new Sports_Bench_Player( (int)$event->player_id ); if ( $event->game_info_assists != NULL ) { $assist = ' (' . $event->game_info_assists . ')'; } else { $assist = ''; } $table_row_styles = apply_filters( 'sports_bench_game_event_row', '', $team ); $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . __( 'Match Events', 'sports-bench' ) . '
' . $team->get_team_photo( 'team-logo' ) . '' . $event->game_info_time . "' — " . $event->game_info_event . ': ' . $player->player_first_name . ' ' . $player->player_last_name . $assist . '
'; } return $html; } add_filter( 'sports_bench_game_events', 'sports_bench_do_game_events', 10, 5 );