// =========================================================================
// SHORTCODE: Recent Team Transactions (Abbreviated Front Page Feed)
// =========================================================================
/**
* Shortcode to Display a Clean, Abbreviated Recent Transactions Feed for Front Pages
* Usage: [otg_recent_transactions limit="10"]
*/
add_shortcode('otg_recent_transactions', 'otg_render_recent_transactions');
function otg_render_recent_transactions($atts) {
global $wpdb;
$transactions_table = 'otg_transactions';
// Parse attributes for row limit (default to 10 rows)
$atts = shortcode_atts(array(
'limit' => 10,
), $atts);
$limit = intval($atts['limit']);
// Fetch the most recent transactions without filters or pagination
$sql = "
SELECT
t.TransIndex,
t.ID AS Player_ID,
t.Partner AS Team_Name,
DATE_FORMAT(t.Date, '%M %e, %Y') AS Transaction_Date,
t.Name AS Player_Name,
t.Transaction AS Transaction_Type,
t.Included,
t.Notes
FROM {$transactions_table} AS t
ORDER BY t.Date DESC, t.TransIndex DESC
LIMIT %d
";
$results = $wpdb->get_results($wpdb->prepare($sql, $limit));
// Build HTML Output Container
$html = '
';
$html .= '
Recent Transactions
';
if (empty($results)) {
$html .= '
No recent transactions found.
';
$html .= '
';
return $html;
}
// Render Compact Data Table (No Headers, matching the provided screenshot style)
$html .= '
';
$html .= '';
foreach ($results as $row) {
$player_display = '-';
if (!empty($row->Player_Name)) {
if (!empty($row->Player_ID)) {
$profile_url = esc_url(home_url('/profile/?player_id=' . intval($row->Player_ID)));
$player_display = '' . esc_html($row->Player_Name) . '';
} else {
$player_display = esc_html($row->Player_Name);
}
}
$tx_type = trim($row->Transaction_Type ?: '');
$tx_color = '#0073aa'; // default fallback color
$tx_icon = '';
// Transaction Color & Icon Mapping based on requirements
switch ($tx_type) {
case 'Signed':
case 'Resigned':
$tx_color = '#ffd700'; // yellow
$tx_icon = '$';
break;
case 'Acquired':
$tx_color = '#2ecc71'; // green
$tx_icon = '+';
break;
case 'Traded':
$tx_color = '#e74c3c'; // red
$tx_icon = '−';
break;
case 'Reassigned':
$tx_color = '#1b4f72'; // darker blue
$tx_icon = '& کاهش;'; // fallback down arrow symbol or character
break;
case 'Called Up':
$tx_color = '#5dade2'; // lighter blue
$tx_icon = '▲';
break;
case 'Deceased':
case 'Passed Away':
$tx_color = '#ffffff'; // white
$tx_icon = '🌹';
break;
case 'Retired':
$tx_color = '#f39c12'; // orange
$tx_icon = '🪇';
break;
case 'Lost on waivers':
$tx_color = '#f1948a'; // light red
$tx_icon = '✖';
break;
case 'Waiver Claim':
$tx_color = '#abeb78'; // light green
$tx_icon = '✔';
break;
case 'Signed PTO':
$tx_color = '#ffd700'; // yellow
$tx_icon = '$';
break;
case 'Released from PTO':
$tx_color = '#f39c12'; // orange
$tx_icon = '✖';
break;
case 'Contract Terminated':
$tx_color = '#e74c3c'; // red
$tx_icon = '';
break;
default:
$tx_color = '#0073aa';
$tx_icon = '';
break;
}
// Override arrow icon explicitly for Reassigned using clean unicode down arrow
if ($tx_type === 'Reassigned') {
$tx_icon = '▼';
}
// 4th column displays the Notes field
$html .= '