function otg_render_opening_night_page($atts) {
global $wpdb;
// 1. Get the current active season from otg_rangers_season_settings
$active_season = $wpdb->get_var("
SELECT season
FROM otg_rangers_season_settings
WHERE active_season = 'y'
LIMIT 1
");
// Fallback if no active_season row is flagged
if (empty($active_season)) {
$active_season = $wpdb->get_var("
SELECT season
FROM otg_rangers_season_settings
ORDER BY season DESC
LIMIT 1
");
}
// 2. Look up the earliest regular season game (game_type = 2) for that active season
$opening_game = $wpdb->get_row($wpdb->prepare("
SELECT *
FROM otg_rangers_games
WHERE season = %s
AND game_type = 2
AND (home_team_abbr = 'NYR' OR away_team_abbr = 'NYR')
ORDER BY game_date ASC, game_id ASC
LIMIT 1
", $active_season));
// Fallback if active season schedule is not yet in otg_rangers_games
if (!$opening_game) {
$opening_game = $wpdb->get_row("
SELECT *
FROM otg_rangers_games
WHERE game_type = 2
AND (home_team_abbr = 'NYR' OR away_team_abbr = 'NYR')
ORDER BY game_date DESC, game_id ASC
LIMIT 1
");
}
// 3. Determine Opponent Abbreviation and Logos
$game_id = $opening_game ? intval($opening_game->game_id) : 0;
$opp_abbr = '';
if ($opening_game) {
$opp_abbr = ($opening_game->home_team_abbr === 'NYR') ? $opening_game->away_team_abbr : $opening_game->home_team_abbr;
}
$nyr_logo = function_exists('otg_get_team_logo') ? otg_get_team_logo('NYR', $active_season) : '';
$opp_logo = ($opp_abbr && function_exists('otg_get_team_logo')) ? otg_get_team_logo($opp_abbr, $active_season) : '';
// =========================================================================
// RENDER LAYOUT
// =========================================================================
$html = '
';
$html .= '';
// Header Block
$html .= '
';
$html .= '
New York Rangers — Opening Night Preview (' . esc_html($active_season) . ')
';
if ($opp_abbr) {
$html .= '
Season Opener Matchup: NYR vs ' . esc_html($opp_abbr) . '
';
}
$html .= '
';
// Main Layout Flex Split
$html .= '
';
$html .= '
';
// 1. All-Time Opening Night Games vs. Current Opponent
if ($opp_abbr) {
$html .= otg_render_opening_nights_vs_opponent($opp_abbr, $opp_logo);
}
// 2. Skater Stats (Last 10 Opening Nights)
$html .= otg_render_opening_night_skater_stats($nyr_logo);
// 3. Goaltender Stats (Last 10 Opening Nights)
$html .= otg_render_opening_night_goalie_stats($nyr_logo);
// 4. All-Time Top 25 Opening Night Skaters
$html .= otg_render_top_25_opening_night_skaters();
// 5. All-Time Top 10 Opening Night Goaltenders
$html .= otg_render_top_10_opening_night_goalies();
// 6. Current Ranger Injuries Summary Table
if (function_exists('otg_render_preview_injuries_section')) {
$html .= otg_render_preview_injuries_section();
}
$html .= '
'; // Close left column
// Right Sidebar
$html .= '