// ========================================================================= // 27. SHORTCODE: Team Captains /captains/ // ========================================================================= add_shortcode('otg_rangers_captains_list', 'otg_rangers_captains_list_shortcode'); function otg_rangers_captains_list_shortcode() { global $wpdb; // Helper function to format dates nicely or leave seasons as-is $format_date_display = function($date_str) { if (empty($date_str)) { return 'Present'; } if (preg_match('/^\d{4}-\d{2}$/', $date_str)) { return $date_str; } $time = strtotime($date_str); return $time ? date('F j, Y', $time) : $date_str; }; // Helper function to convert table date strings (like Y-m-d or YYYY-MM) directly into comparable Y-m-d bounds $parse_date_bound = function($date_str, $is_end = false) { if (empty($date_str)) return null; if (preg_match('/^(\d{4})-(\d{2})$/', $date_str, $m)) { $y = intval($m[1]); $sub = intval($m[2]); $full_y = ($sub < 50) ? 2000 + $sub : 1900 + $sub; if (!$is_end) { return $y . '-09-01'; // Season start baseline } else { return $full_y . '-07-31'; // Season end baseline } } $time = strtotime($date_str); return $time ? date('Y-m-d', $time) : null; }; $captains = $wpdb->get_results("SELECT * FROM otg_rangers_captains ORDER BY id ASC"); $output = '
| No. | Captain / Period | Tenure Began | Tenure Ended | Record (W-L-T/OT) |
|---|---|---|---|---|
| No captain records found. | ||||
| ' . ($display_num !== '' ? esc_html($display_num) : '') . ' | '; $output .= '' . $player_link . ' | '; $output .= '' . $began_display . ' | '; $output .= '' . $ended_display . ' | '; $output .= '' . esc_html($record_str) . ' | '; $output .= '
| — | '; $output .= '' . esc_html($vacancy_label) . ' | '; $output .= '— | '; $output .= '' . esc_html($v_record_str) . ' | '; $output .= '|