various improvements to make release 1 complete
This commit is contained in:
@@ -31,6 +31,7 @@ class Swi_Foot_Admin
|
||||
register_setting('swi_foot_settings', 'swi_foot_verein_id');
|
||||
register_setting('swi_foot_settings', 'swi_foot_season_id');
|
||||
register_setting('swi_foot_settings', 'swi_foot_match_cache_duration');
|
||||
register_setting('swi_foot_settings', 'swi_foot_api_language');
|
||||
|
||||
add_settings_section(
|
||||
'swi_foot_api_section',
|
||||
@@ -44,6 +45,7 @@ class Swi_Foot_Admin
|
||||
add_settings_field('swi_foot_api_password', __('API Password (Application Pass)', 'swi_foot_matchdata'), array($this, 'password_render'), 'swi_foot_settings', 'swi_foot_api_section');
|
||||
add_settings_field('swi_foot_verein_id', __('Verein ID (Club ID)', 'swi_foot_matchdata'), array($this, 'verein_id_render'), 'swi_foot_settings', 'swi_foot_api_section');
|
||||
add_settings_field('swi_foot_season_id', __('Season ID', 'swi_foot_matchdata'), array($this, 'season_id_render'), 'swi_foot_settings', 'swi_foot_api_section');
|
||||
add_settings_field('swi_foot_api_language', __('API Response Language', 'swi_foot_matchdata'), array($this, 'language_render'), 'swi_foot_settings', 'swi_foot_api_section');
|
||||
|
||||
add_settings_section(
|
||||
'swi_foot_cache_section',
|
||||
@@ -107,6 +109,17 @@ class Swi_Foot_Admin
|
||||
echo '<p class="description">' . __('How long to cache match data in seconds (10-300)', 'swi_foot_matchdata') . '</p>';
|
||||
}
|
||||
|
||||
public function language_render()
|
||||
{
|
||||
$language = get_option('swi_foot_api_language', '1');
|
||||
echo '<select name="swi_foot_api_language">';
|
||||
echo '<option value="1" ' . selected($language, '1', false) . '>' . __('German', 'swi_foot_matchdata') . '</option>';
|
||||
echo '<option value="2" ' . selected($language, '2', false) . '>' . __('French', 'swi_foot_matchdata') . '</option>';
|
||||
echo '<option value="3" ' . selected($language, '3', false) . '>' . __('Italian', 'swi_foot_matchdata') . '</option>';
|
||||
echo '</select>';
|
||||
echo '<p class="description">' . __('Select the language for API responses (German, French, or Italian)', 'swi_foot_matchdata') . '</p>';
|
||||
}
|
||||
|
||||
public function admin_scripts($hook)
|
||||
{
|
||||
if ($hook === 'settings_page_swiss-football-matchdata') {
|
||||
@@ -248,23 +261,21 @@ class Swi_Foot_Admin
|
||||
<div class="wrap">
|
||||
<h1><?php _e('Swiss Football Matchdata Settings', 'swi_foot_matchdata'); ?></h1>
|
||||
|
||||
<form action="options.php" method="post">
|
||||
<form action="options.php" method="post" id="swi-foot-settings-form">
|
||||
<?php
|
||||
settings_fields('swi_foot_settings');
|
||||
do_settings_sections('swi_foot_settings');
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
|
||||
<div class="swi-foot-admin-section">
|
||||
<h2><?php _e('Connection Test', 'swi_foot_matchdata'); ?></h2>
|
||||
<p>
|
||||
<button type="button" id="test-connection" class="button">
|
||||
<?php _e('Test API Connection', 'swi_foot_matchdata'); ?>
|
||||
<div class="swi-foot-form-actions">
|
||||
<button type="submit" name="swi_foot_action" value="save_and_test" class="button button-primary">
|
||||
<?php _e('Save and Test', 'swi_foot_matchdata'); ?>
|
||||
</button>
|
||||
<span id="connection-status"></span>
|
||||
</p>
|
||||
</div>
|
||||
<button type="submit" name="swi_foot_action" value="save_only" class="button">
|
||||
<?php _e('Save without Test', 'swi_foot_matchdata'); ?>
|
||||
</button>
|
||||
</div>
|
||||
<span id="connection-status"></span>
|
||||
</form>
|
||||
|
||||
<div class="swi-foot-admin-section">
|
||||
<h2><?php _e('Team Management', 'swi_foot_matchdata'); ?></h2>
|
||||
@@ -325,7 +336,11 @@ class Swi_Foot_Admin
|
||||
|
||||
if (is_wp_error($teams)) {
|
||||
echo '<p class="notice notice-error">' .
|
||||
sprintf(__('Error loading teams: %s', 'swi_foot_matchdata'), $teams->get_error_message()) .
|
||||
sprintf(
|
||||
/* translators: %s is the error message from the API */
|
||||
__('Error loading teams: %s', 'swi_foot_matchdata'),
|
||||
$teams->get_error_message()
|
||||
) .
|
||||
'</p>';
|
||||
return;
|
||||
}
|
||||
@@ -357,7 +372,12 @@ class Swi_Foot_Admin
|
||||
$cache_count = is_array($keys) ? count($keys) : 0;
|
||||
$cache_duration = get_option('swi_foot_match_cache_duration', 30);
|
||||
|
||||
echo '<p>' . sprintf(__('Currently caching %d match records with %d second cache duration.', 'swi_foot_matchdata'), $cache_count, $cache_duration) . '</p>';
|
||||
echo '<p>' . sprintf(
|
||||
/* translators: %1$d is the number of cached match records, %2$d is the cache duration in seconds */
|
||||
__('Currently caching %1$d match records with %2$d second cache duration.', 'swi_foot_matchdata'),
|
||||
$cache_count,
|
||||
$cache_duration
|
||||
) . '</p>';
|
||||
|
||||
if ($cache_count > 0) {
|
||||
$timestamps = array();
|
||||
@@ -460,7 +480,5 @@ class Swi_Foot_Admin
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -9,6 +9,7 @@ class Swi_Foot_API
|
||||
private $verein_id;
|
||||
private $season_id;
|
||||
private $cache_duration;
|
||||
private $language;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -18,6 +19,7 @@ class Swi_Foot_API
|
||||
$this->verein_id = get_option('swi_foot_verein_id');
|
||||
$this->season_id = get_option('swi_foot_season_id', date('Y'));
|
||||
$this->cache_duration = get_option('swi_foot_match_cache_duration', 30);
|
||||
$this->language = get_option('swi_foot_api_language', '1');
|
||||
|
||||
// AJAX actions were migrated to REST endpoints (see includes/class-swi-foot-rest.php)
|
||||
|
||||
@@ -176,6 +178,7 @@ class Swi_Foot_API
|
||||
$response = wp_remote_get($url, array(
|
||||
'headers' => array(
|
||||
'X-User-Token' => $token,
|
||||
'X-User-Language' => $this->language,
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'timeout' => 30
|
||||
@@ -204,7 +207,13 @@ class Swi_Foot_API
|
||||
if ($response_code !== 200) {
|
||||
$body_debug = wp_remote_retrieve_body($response);
|
||||
error_log('Swiss Football API: Request to ' . $url . ' returned ' . $response_code . ' - body: ' . substr($body_debug, 0, 1000));
|
||||
return new WP_Error('api_error', 'API request failed with code ' . $response_code);
|
||||
|
||||
// Handle 406 Not Acceptable - data not yet available
|
||||
if ($response_code === 406) {
|
||||
return new WP_Error('data_not_available', 'Data not yet available', array('status_code' => 406));
|
||||
}
|
||||
|
||||
return new WP_Error('api_error', 'API request failed with code ' . $response_code, array('status_code' => $response_code));
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
@@ -348,6 +357,11 @@ class Swi_Foot_API
|
||||
return $this->api_request('/api/match/' . $match_id . '/events');
|
||||
}
|
||||
|
||||
public function get_match_referees($match_id)
|
||||
{
|
||||
return $this->api_request('/api/match/' . $match_id . '/referees');
|
||||
}
|
||||
|
||||
public function get_team_picture($team_id)
|
||||
{
|
||||
// Special handling for team picture endpoint which returns 200 with data or 204 No Content
|
||||
@@ -364,6 +378,7 @@ class Swi_Foot_API
|
||||
$response = wp_remote_get($url, array(
|
||||
'headers' => array(
|
||||
'X-User-Token' => $token,
|
||||
'X-User-Language' => $this->language,
|
||||
'Content-Type' => 'application/json'
|
||||
),
|
||||
'timeout' => 30
|
||||
@@ -410,9 +425,9 @@ class Swi_Foot_API
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function get_commons_ids()
|
||||
public function get_common_ids($params = array())
|
||||
{
|
||||
return $this->api_request('/api/commons/ids');
|
||||
return $this->api_request('/api/common/ids', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,17 +456,54 @@ class Swi_Foot_API
|
||||
*/
|
||||
public function test_connection()
|
||||
{
|
||||
// Actually test the connection by making an API request
|
||||
$result = $this->api_request('/api/teams', array('vereinId' => $this->verein_id));
|
||||
|
||||
// Check if the request was successful (not an error)
|
||||
if (is_wp_error($result)) {
|
||||
error_log('Swiss Football API: Connection test failed - ' . $result->get_error_message());
|
||||
return false;
|
||||
// First, check if credentials are configured
|
||||
if (empty($this->username) || empty($this->password)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'API credentials not configured',
|
||||
'details' => 'Please configure API Username and Password in Settings → Swiss Football'
|
||||
);
|
||||
}
|
||||
|
||||
// Check if Verein ID is configured
|
||||
if (empty($this->verein_id)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Verein ID (Club ID) not configured',
|
||||
'details' => 'Please configure Verein ID in Settings → Swiss Football'
|
||||
);
|
||||
}
|
||||
|
||||
// Verify we got a response (array means success)
|
||||
return is_array($result);
|
||||
// Test connection using the /api/common/ids endpoint with required parameters
|
||||
$result = $this->get_common_ids(array(
|
||||
'ClubId' => $this->verein_id,
|
||||
'Language' => 1 // 1 = German
|
||||
));
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
$error_msg = $result->get_error_message();
|
||||
error_log('Swiss Football API: Connection test failed - ' . $error_msg);
|
||||
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'API connection failed',
|
||||
'details' => $error_msg
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_array($result)) {
|
||||
return array(
|
||||
'success' => false,
|
||||
'error' => 'Invalid API response',
|
||||
'details' => 'The API returned unexpected data format'
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'error' => null,
|
||||
'details' => 'Connection successful!'
|
||||
);
|
||||
}
|
||||
|
||||
public function get_current_match($team_id)
|
||||
|
||||
@@ -17,6 +17,23 @@ class Swi_Foot_Blocks
|
||||
|
||||
public function register_blocks()
|
||||
{
|
||||
// Register custom block category for Swiss Football blocks
|
||||
add_filter('block_categories_all', function($categories) {
|
||||
// Check if category already exists
|
||||
foreach ($categories as $cat) {
|
||||
if ($cat['slug'] === 'swi-football') {
|
||||
return $categories; // Already registered
|
||||
}
|
||||
}
|
||||
// Add custom category with translated label
|
||||
$categories[] = array(
|
||||
'slug' => 'swi-football',
|
||||
'title' => __('Swiss Football', 'swi_foot_matchdata'),
|
||||
'icon' => 'soccer'
|
||||
);
|
||||
return $categories;
|
||||
});
|
||||
|
||||
// Register blocks from metadata (block.json) and provide server-side render callbacks
|
||||
$base = dirname(__DIR__) . '/blocks';
|
||||
|
||||
@@ -90,14 +107,6 @@ class Swi_Foot_Blocks
|
||||
) );
|
||||
}
|
||||
|
||||
// Register additional blocks (editor-only save shortcodes)
|
||||
if ( file_exists( $base . '/team-data/block.json' ) ) {
|
||||
register_block_type_from_metadata( $base . '/team-data', array(
|
||||
'editor_script' => 'swi-foot-editor-blocks',
|
||||
'editor_style' => 'swi-foot-editor-styles'
|
||||
) );
|
||||
}
|
||||
|
||||
if ( file_exists( $base . '/match-roster/block.json' ) ) {
|
||||
register_block_type_from_metadata( $base . '/match-roster', array(
|
||||
'render_callback' => array( $this, 'render_match_roster_block' ),
|
||||
@@ -113,6 +122,22 @@ class Swi_Foot_Blocks
|
||||
'editor_style' => 'swi-foot-editor-styles'
|
||||
) );
|
||||
}
|
||||
|
||||
if ( file_exists( $base . '/match-bench/block.json' ) ) {
|
||||
register_block_type_from_metadata( $base . '/match-bench', array(
|
||||
'render_callback' => array( $this, 'render_match_bench_block' ),
|
||||
'editor_script' => 'swi-foot-editor-blocks',
|
||||
'editor_style' => 'swi-foot-editor-styles'
|
||||
) );
|
||||
}
|
||||
|
||||
if ( file_exists( $base . '/match-referees/block.json' ) ) {
|
||||
register_block_type_from_metadata( $base . '/match-referees', array(
|
||||
'render_callback' => array( $this, 'render_match_referees_block' ),
|
||||
'editor_script' => 'swi-foot-editor-blocks',
|
||||
'editor_style' => 'swi-foot-editor-styles'
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_scripts()
|
||||
@@ -223,7 +248,11 @@ class Swi_Foot_Blocks
|
||||
|
||||
if (is_wp_error($standings)) {
|
||||
return '<div class="swi-foot-error">' .
|
||||
sprintf(__('Error loading standings: %s', 'swi_foot_matchdata'), $standings->get_error_message()) .
|
||||
sprintf(
|
||||
/* translators: %s is the error message from the API */
|
||||
__('Error loading standings: %s', 'swi_foot_matchdata'),
|
||||
$standings->get_error_message()
|
||||
) .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
@@ -281,6 +310,7 @@ class Swi_Foot_Blocks
|
||||
// Team must come from context only
|
||||
$team_id = $ctx['team_id'] ?? null;
|
||||
$limit = isset($attributes['limit']) ? $attributes['limit'] : 5;
|
||||
$match_filter = isset($attributes['matchFilter']) ? $attributes['matchFilter'] : 'all';
|
||||
|
||||
if (empty($team_id)) {
|
||||
return '<div class="swi-foot-error">' . __('Schedule: No team provided in container context.', 'swi_foot_matchdata') . '</div>';
|
||||
@@ -291,18 +321,47 @@ class Swi_Foot_Blocks
|
||||
|
||||
if (is_wp_error($events)) {
|
||||
return '<div class="swi-foot-error">' .
|
||||
sprintf(__('Error loading schedule: %s', 'swi_foot_matchdata'), $events->get_error_message()) .
|
||||
sprintf(
|
||||
/* translators: %s is the error message from the API */
|
||||
__('Error loading schedule: %s', 'swi_foot_matchdata'),
|
||||
$events->get_error_message()
|
||||
) .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// Filter upcoming events and limit results
|
||||
// Filter upcoming events by match type (home/away/all) and limit results
|
||||
$upcoming_events = array();
|
||||
if (is_array($events)) {
|
||||
foreach ($events as $event) {
|
||||
// Check if match is in the future
|
||||
if (strtotime($event['matchDate']) >= time()) {
|
||||
$upcoming_events[] = $event;
|
||||
if (count($upcoming_events) >= $limit) {
|
||||
break;
|
||||
// Apply match filter (home/away/all)
|
||||
$match_should_be_included = true;
|
||||
|
||||
if ($match_filter !== 'all') {
|
||||
// Determine if this is a home or away match
|
||||
// teamAId is home team, teamBId is away team
|
||||
$is_home_match = isset($event['teamAId']) && $event['teamAId'] == $team_id;
|
||||
$is_away_match = isset($event['teamBId']) && $event['teamBId'] == $team_id;
|
||||
|
||||
// If team IDs aren't available, try to infer from team names
|
||||
if (!isset($event['teamAId']) || !isset($event['teamBId'])) {
|
||||
// This is a fallback - not ideal but works if IDs aren't present
|
||||
$is_home_match = true; // Default to home
|
||||
}
|
||||
|
||||
if ($match_filter === 'home' && !$is_home_match) {
|
||||
$match_should_be_included = false;
|
||||
} elseif ($match_filter === 'away' && !$is_away_match) {
|
||||
$match_should_be_included = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($match_should_be_included) {
|
||||
$upcoming_events[] = $event;
|
||||
if (count($upcoming_events) >= $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +459,8 @@ class Swi_Foot_Blocks
|
||||
// Match must come from context
|
||||
$match_id = $ctx['match_id'] ?? '';
|
||||
$side = $attributes['side'] ?? 'home';
|
||||
$with_bench = $attributes['withBench'] ? 'true' : 'false';
|
||||
$show_starting_squad = isset($attributes['showStartingSquad']) ? $attributes['showStartingSquad'] : true;
|
||||
$show_bench = isset($attributes['showBench']) ? $attributes['showBench'] : false;
|
||||
|
||||
if (empty($match_id)) {
|
||||
return '<div class="swi-foot-error">' . __('Match Roster: No match provided in container context.', 'swi_foot_matchdata') . '</div>';
|
||||
@@ -408,8 +468,11 @@ class Swi_Foot_Blocks
|
||||
|
||||
// Build shortcode using match from context and side attribute
|
||||
$shortcode = '[swi_foot_roster match_id="' . esc_attr($match_id) . '" side="' . esc_attr($side) . '"';
|
||||
if ($with_bench === 'true') {
|
||||
$shortcode .= ' with_bench="true"';
|
||||
if ($show_starting_squad) {
|
||||
$shortcode .= ' show_starting="true"';
|
||||
}
|
||||
if ($show_bench) {
|
||||
$shortcode .= ' show_bench="true"';
|
||||
}
|
||||
$shortcode .= ']';
|
||||
|
||||
@@ -446,6 +509,61 @@ class Swi_Foot_Blocks
|
||||
return do_shortcode($shortcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render match bench block
|
||||
* Gets match from container context, displays team staff/substitutes
|
||||
*/
|
||||
public function render_match_bench_block($attributes, $content = '', $block = null)
|
||||
{
|
||||
// Get context from parent block container
|
||||
$provided = is_object($block) && !empty($block->context['swi-foot/context']) ? $block->context['swi-foot/context'] : null;
|
||||
$ctx = array();
|
||||
if (is_array($provided)) $ctx = $provided;
|
||||
$post_defaults = function_exists('swi_foot_resolve_context') ? swi_foot_resolve_context(get_the_ID()) : array();
|
||||
$ctx = array_merge($post_defaults, $ctx);
|
||||
|
||||
// Match must come from context
|
||||
$match_id = $ctx['match_id'] ?? '';
|
||||
$side = $attributes['side'] ?? 'home';
|
||||
|
||||
if (empty($match_id)) {
|
||||
return '<div class="swi-foot-error">' . __('Match Bench: No match provided in container context.', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// Build shortcode using match from context and side attribute
|
||||
$shortcode = '[swi_foot_bench match_id="' . esc_attr($match_id) . '" side="' . esc_attr($side) . '"]';
|
||||
|
||||
// Process and return the shortcode
|
||||
return do_shortcode($shortcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render match referees block
|
||||
* Gets match from container context, displays match officials/referees
|
||||
*/
|
||||
public function render_match_referees_block($attributes, $content = '', $block = null)
|
||||
{
|
||||
// Get context from parent block container
|
||||
$provided = is_object($block) && !empty($block->context['swi-foot/context']) ? $block->context['swi-foot/context'] : null;
|
||||
$ctx = array();
|
||||
if (is_array($provided)) $ctx = $provided;
|
||||
$post_defaults = function_exists('swi_foot_resolve_context') ? swi_foot_resolve_context(get_the_ID()) : array();
|
||||
$ctx = array_merge($post_defaults, $ctx);
|
||||
|
||||
// Match must come from context
|
||||
$match_id = $ctx['match_id'] ?? '';
|
||||
|
||||
if (empty($match_id)) {
|
||||
return '<div class="swi-foot-error">' . __('Match Referees: No match provided in container context.', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// Build shortcode using match from context
|
||||
$shortcode = '[swi_foot_referees match_id="' . esc_attr($match_id) . '"]';
|
||||
|
||||
// Process and return the shortcode
|
||||
return do_shortcode($shortcode);
|
||||
}
|
||||
|
||||
private function render_team_selector($block_type)
|
||||
{
|
||||
$api = new Swi_Foot_API();
|
||||
|
||||
@@ -84,18 +84,10 @@ class Swi_Foot_REST {
|
||||
)
|
||||
));
|
||||
|
||||
// Also allow team_id as a path parameter: /wp-json/swi-foot/v1/matches/123
|
||||
register_rest_route('swi-foot/v1', '/matches/(?P<team_id>\d+)', array(
|
||||
register_rest_route('swi-foot/v1', '/block-status/(?P<match_id>\d+)/(?P<endpoint>[a-z_]+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_matches_for_team'),
|
||||
'permission_callback' => '__return_true',
|
||||
'args' => array(
|
||||
'team_id' => array(
|
||||
'validate_callback' => function($param, $request, $key) {
|
||||
return is_numeric($param);
|
||||
}
|
||||
)
|
||||
)
|
||||
'callback' => array($this, 'check_block_status'),
|
||||
'permission_callback' => '__return_true'
|
||||
));
|
||||
|
||||
// Single match details: /wp-json/swi-foot/v1/match/<match_id>
|
||||
@@ -129,9 +121,9 @@ class Swi_Foot_REST {
|
||||
)
|
||||
));
|
||||
|
||||
register_rest_route('swi-foot/v1', '/commons-ids', array(
|
||||
register_rest_route('swi-foot/v1', '/common-ids', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array($this, 'get_commons_ids'),
|
||||
'callback' => array($this, 'get_common_ids'),
|
||||
'permission_callback' => '__return_true'
|
||||
));
|
||||
|
||||
@@ -210,7 +202,7 @@ class Swi_Foot_REST {
|
||||
return rest_ensure_response($normalized);
|
||||
}
|
||||
|
||||
public function get_commons_ids($request) {
|
||||
public function get_common_ids($request) {
|
||||
$api = new Swi_Foot_API();
|
||||
$commons = $api->get_commons_ids();
|
||||
if (is_wp_error($commons)) {
|
||||
@@ -370,12 +362,77 @@ class Swi_Foot_REST {
|
||||
public function admin_test_connection($request) {
|
||||
$api = new Swi_Foot_API();
|
||||
if (method_exists($api, 'test_connection')) {
|
||||
$ok = $api->test_connection();
|
||||
$result = $api->test_connection();
|
||||
} else {
|
||||
$ok = false;
|
||||
$result = array(
|
||||
'success' => false,
|
||||
'error' => 'test_connection method not found',
|
||||
'details' => 'Plugin may be incorrectly installed'
|
||||
);
|
||||
}
|
||||
|
||||
// Return response with full error details
|
||||
if (is_array($result) && isset($result['success'])) {
|
||||
if ($result['success']) {
|
||||
return rest_ensure_response(array(
|
||||
'success' => true,
|
||||
'message' => isset($result['details']) ? $result['details'] : 'Connection successful!'
|
||||
));
|
||||
} else {
|
||||
return new WP_REST_Response(array(
|
||||
'success' => false,
|
||||
'error' => isset($result['error']) ? $result['error'] : 'Connection failed',
|
||||
'details' => isset($result['details']) ? $result['details'] : 'Unknown error'
|
||||
), 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for unexpected response format
|
||||
return new WP_REST_Response(array(
|
||||
'success' => false,
|
||||
'error' => 'Unexpected response from API test',
|
||||
'details' => 'Unable to determine connection status'
|
||||
), 400);
|
||||
}
|
||||
|
||||
public function check_block_status($request) {
|
||||
$match_id = $request->get_param('match_id');
|
||||
$endpoint = $request->get_param('endpoint');
|
||||
|
||||
if (empty($match_id) || empty($endpoint)) {
|
||||
return rest_ensure_response(array('status' => 'error', 'message' => 'Missing parameters'));
|
||||
}
|
||||
|
||||
$api = new Swi_Foot_API();
|
||||
|
||||
// Map endpoint names to API methods
|
||||
$method_map = array(
|
||||
'roster' => 'get_match_players',
|
||||
'bench' => 'get_match_bench',
|
||||
'referees' => 'get_match_referees',
|
||||
'events' => 'get_match_events'
|
||||
);
|
||||
|
||||
if (!isset($method_map[$endpoint])) {
|
||||
return rest_ensure_response(array('status' => 'error', 'message' => __('Unknown endpoint', 'swi_foot_matchdata')));
|
||||
}
|
||||
|
||||
$method = $method_map[$endpoint];
|
||||
$result = $api->$method($match_id);
|
||||
|
||||
// Determine status based on result
|
||||
if (is_wp_error($result)) {
|
||||
$code = $result->get_error_code();
|
||||
if ($code === 'data_not_available') {
|
||||
return rest_ensure_response(array('status' => 'warning', 'message' => __('Data not yet available', 'swi_foot_matchdata')));
|
||||
} else {
|
||||
return rest_ensure_response(array('status' => 'error', 'message' => __('No data available', 'swi_foot_matchdata')));
|
||||
}
|
||||
} elseif (empty($result)) {
|
||||
return rest_ensure_response(array('status' => 'error', 'message' => __('No data available', 'swi_foot_matchdata')));
|
||||
} else {
|
||||
return rest_ensure_response(array('status' => 'success', 'message' => __('Data available', 'swi_foot_matchdata')));
|
||||
}
|
||||
if ($ok) return rest_ensure_response(array('success' => true));
|
||||
return new WP_REST_Response(array('error' => 'Connection failed'), 400);
|
||||
}
|
||||
|
||||
public function admin_delete_finished_match($request) {
|
||||
|
||||
@@ -22,6 +22,8 @@ class Swi_Foot_Shortcodes
|
||||
add_shortcode('swi_foot_match_round', array($this, 'match_round_shortcode'));
|
||||
add_shortcode('swi_foot_standings', array($this, 'standings_shortcode'));
|
||||
add_shortcode('swi_foot_roster', array($this, 'roster_shortcode'));
|
||||
add_shortcode('swi_foot_bench', array($this, 'bench_shortcode'));
|
||||
add_shortcode('swi_foot_referees', array($this, 'referees_shortcode'));
|
||||
add_shortcode('swi_foot_events', array($this, 'events_shortcode'));
|
||||
add_shortcode('swi_foot_match_data', array($this, 'match_data_shortcode'));
|
||||
add_shortcode('swi_foot_match_home_team_logo', array($this, 'match_home_team_logo_shortcode'));
|
||||
@@ -44,6 +46,26 @@ class Swi_Foot_Shortcodes
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render error message, distinguishing between "data not available" (406) and other errors
|
||||
* @param WP_Error $error The error object
|
||||
* @return string HTML-formatted error message
|
||||
*/
|
||||
private function render_error_message($error)
|
||||
{
|
||||
if (!is_wp_error($error)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Check if this is a "data not yet available" error (HTTP 406)
|
||||
if ($error->get_error_code() === 'data_not_available') {
|
||||
return '<div class="swi-foot-data-warning">⏳ ' . __('Data not yet available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// For other errors, show grey "no data available" message
|
||||
return '<div class="swi-foot-data-unavailable">ℹ️ ' . __('No data available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle internal requests for team logo images
|
||||
* URL format: /?swi_foot_team_logo=team_id&position=home|away|event
|
||||
@@ -198,7 +220,7 @@ class Swi_Foot_Shortcodes
|
||||
$match_data = $this->get_match_data($atts);
|
||||
|
||||
if (!$match_data) {
|
||||
return '<span class="swi-foot-error">' . __('Match data not available', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Match data not available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
@@ -388,6 +410,139 @@ class Swi_Foot_Shortcodes
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render match bench (team staff) list
|
||||
* Usage: [swi_foot_bench match_id="12345"]
|
||||
* Lists staff members (name and role) for both home and away teams
|
||||
*/
|
||||
public function bench_shortcode($atts)
|
||||
{
|
||||
$atts = shortcode_atts(array(
|
||||
'match_id' => '',
|
||||
'side' => '' // 'home' or 'away', shows both if not specified
|
||||
), $atts);
|
||||
|
||||
$match_id = $atts['match_id'];
|
||||
if (empty($match_id)) {
|
||||
return '<div class="swi-foot-error">' . __('Match ID required', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
$bench = $this->api->get_match_bench($match_id);
|
||||
|
||||
if (is_wp_error($bench)) {
|
||||
return $this->render_error_message($bench);
|
||||
}
|
||||
|
||||
if (empty($bench)) {
|
||||
return '<div class="swi-foot-notice">' . __('No bench data available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// Normalize side parameter
|
||||
$side = strtolower(trim($atts['side']));
|
||||
$show_side_filter = !empty($side) && in_array($side, array('home', 'away'), true);
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="swi-foot-bench-container" data-match-id="<?php echo esc_attr($match_id); ?>">
|
||||
<?php
|
||||
// Group bench players by team
|
||||
$home_staff = array_filter($bench, function($person) {
|
||||
return isset($person['isHomeTeam']) && $person['isHomeTeam'] === true;
|
||||
});
|
||||
$away_staff = array_filter($bench, function($person) {
|
||||
return isset($person['isHomeTeam']) && $person['isHomeTeam'] === false;
|
||||
});
|
||||
|
||||
// If side is specified, filter to only that side
|
||||
if ($show_side_filter) {
|
||||
if ($side === 'home') {
|
||||
$away_staff = array();
|
||||
} else {
|
||||
$home_staff = array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if (!empty($home_staff)): ?>
|
||||
<div class="bench-team bench-home">
|
||||
<?php if (!$show_side_filter): ?>
|
||||
<h3><?php echo esc_html($home_staff[array_key_first($home_staff)]['teamName'] ?? __('Home Team', 'swi_foot_matchdata')); ?></h3>
|
||||
<?php endif; ?>
|
||||
<ul class="bench-list">
|
||||
<?php foreach ($home_staff as $person): ?>
|
||||
<li class="bench-person">
|
||||
<?php echo esc_html($person['personName'] ?? ''); ?>
|
||||
<?php if (!empty($person['roleCategoryName'])): ?>
|
||||
<span class="swi-foot-role">(<?php echo esc_html($person['roleCategoryName']); ?>)</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($away_staff)): ?>
|
||||
<div class="bench-team bench-away">
|
||||
<?php if (!$show_side_filter): ?>
|
||||
<h3><?php echo esc_html($away_staff[array_key_first($away_staff)]['teamName'] ?? __('Away Team', 'swi_foot_matchdata')); ?></h3>
|
||||
<?php endif; ?>
|
||||
<ul class="bench-list">
|
||||
<?php foreach ($away_staff as $person): ?>
|
||||
<li class="bench-person">
|
||||
<?php echo esc_html($person['personName'] ?? ''); ?>
|
||||
<?php if (!empty($person['roleCategoryName'])): ?>
|
||||
<span class="swi-foot-role">(<?php echo esc_html($person['roleCategoryName']); ?>)</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render referees list for a match
|
||||
* Usage: [swi_foot_referees match_id="12345"]
|
||||
* Lists referees with their role and name formatted as: "Role: Firstname Name" (name in bold)
|
||||
*/
|
||||
public function referees_shortcode($atts)
|
||||
{
|
||||
$atts = shortcode_atts(array(
|
||||
'match_id' => ''
|
||||
), $atts);
|
||||
|
||||
$match_id = $atts['match_id'];
|
||||
if (empty($match_id)) {
|
||||
return '<div class="swi-foot-error">✗ ' . __('Match ID required', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
$referees = $this->api->get_match_referees($match_id);
|
||||
|
||||
if (is_wp_error($referees)) {
|
||||
return $this->render_error_message($referees);
|
||||
}
|
||||
|
||||
if (empty($referees)) {
|
||||
return '<div class="swi-foot-data-unavailable">ℹ️ ' . __('No data available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="swi-foot-referees-container" data-match-id="<?php echo esc_attr($match_id); ?>">
|
||||
<ul class="referees-list">
|
||||
<?php foreach ($referees as $referee): ?>
|
||||
<li class="referee-item">
|
||||
<span class="referee-role"><?php echo esc_html($referee['refereeRoleName'] ?? ''); ?>:</span>
|
||||
<strong><?php echo esc_html(($referee['firstname'] ?? '') . ' ' . ($referee['name'] ?? '')); ?></strong>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic inline data point shortcode
|
||||
* Extracts a specific field from match data and displays it inline
|
||||
@@ -512,15 +667,16 @@ class Swi_Foot_Shortcodes
|
||||
return null;
|
||||
}
|
||||
|
||||
// Parse the matchDate string - handle multiple formats
|
||||
$timestamp = strtotime($match['matchDate']);
|
||||
if ($timestamp === false) {
|
||||
// Extract date part from ISO datetime string (e.g., "2026-03-27T19:30:00" -> "2026-03-27")
|
||||
// API provides date in Swiss time, use as-is without any timezone conversion
|
||||
$date_part = substr($match['matchDate'], 0, 10);
|
||||
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_part)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Use WordPress date format setting
|
||||
// Convert date string to WordPress format
|
||||
$date_format = get_option('date_format');
|
||||
return wp_date($date_format, $timestamp);
|
||||
return date_i18n($date_format, strtotime($date_part));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,15 +691,20 @@ class Swi_Foot_Shortcodes
|
||||
return null;
|
||||
}
|
||||
|
||||
// Parse the matchDate string - handle multiple formats
|
||||
$timestamp = strtotime($match['matchDate']);
|
||||
if ($timestamp === false) {
|
||||
// Extract time part from ISO datetime string (e.g., "2026-03-27T19:30:00" -> "19:30:00")
|
||||
// API provides time in Swiss time, use as-is without any timezone conversion
|
||||
if (strpos($match['matchDate'], 'T') === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$time_part = substr($match['matchDate'], 11, 8);
|
||||
if (!preg_match('/^\d{2}:\d{2}:\d{2}$/', $time_part)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Use WordPress time format setting
|
||||
// Format time string with WordPress time format setting
|
||||
$time_format = get_option('time_format');
|
||||
return wp_date($time_format, $timestamp);
|
||||
return date_i18n($time_format, strtotime('2000-01-01 ' . $time_part));
|
||||
}
|
||||
|
||||
private function get_match_data($atts)
|
||||
@@ -616,13 +777,13 @@ class Swi_Foot_Shortcodes
|
||||
), $atts);
|
||||
|
||||
if (empty($atts['team_id'])) {
|
||||
return '<span class="swi-foot-error">' . __('Team ID required', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Team ID required', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
$standings = $this->api->get_standings($atts['team_id']);
|
||||
|
||||
if (is_wp_error($standings) || empty($standings)) {
|
||||
return '<span class="swi-foot-error">' . __('Standings data not available', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Standings data not available', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
@@ -667,16 +828,18 @@ class Swi_Foot_Shortcodes
|
||||
public function roster_shortcode($atts)
|
||||
{
|
||||
$atts = shortcode_atts(array(
|
||||
'match_id' => '',
|
||||
'team_id' => '',
|
||||
'show_current' => 'false',
|
||||
'side' => '',
|
||||
'with_bench' => 'false'
|
||||
'match_id' => '',
|
||||
'team_id' => '',
|
||||
'show_current' => 'false',
|
||||
'side' => '',
|
||||
'show_starting' => 'true',
|
||||
'show_bench' => 'false',
|
||||
'with_bench' => 'false' // Legacy support
|
||||
), $atts);
|
||||
|
||||
$side = strtolower(trim($atts['side']));
|
||||
if (!in_array($side, array('home', 'away'), true)) {
|
||||
return '<span class="swi-foot-error">' . __('Parameter "side" must be "home" or "away"', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Parameter "side" must be "home" or "away"', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
$match_id = $atts['match_id'];
|
||||
@@ -688,27 +851,27 @@ class Swi_Foot_Shortcodes
|
||||
}
|
||||
|
||||
if (empty($match_id)) {
|
||||
return '<span class="swi-foot-error">' . __('Match ID required', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Match ID required', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// Parse show_starting and show_bench attributes (handle legacy with_bench)
|
||||
$show_starting = strtolower($atts['show_starting']) === 'true';
|
||||
$show_bench = strtolower($atts['show_bench']) === 'true';
|
||||
|
||||
// Legacy support: if with_bench is true and show_starting is default, show both
|
||||
if (strtolower($atts['with_bench']) === 'true' && !$show_bench) {
|
||||
$show_bench = true;
|
||||
}
|
||||
|
||||
// First check if we have saved final data
|
||||
$saved = $this->api->get_finished_match_data($match_id);
|
||||
if ($saved) {
|
||||
$players = $saved['roster']['players'] ?? array();
|
||||
$bench_players = $saved['roster']['bench'] ?? array();
|
||||
$players = $saved['roster']['players'] ?? array();
|
||||
} else {
|
||||
// Live fetch
|
||||
$players = $this->api->get_match_players($match_id);
|
||||
if (is_wp_error($players)) {
|
||||
return '<span class="swi-foot-error">' . __('Roster data not available', 'swi_foot_matchdata') . ': ' . esc_html($players->get_error_message()) . '</span>';
|
||||
}
|
||||
$bench_players = array();
|
||||
|
||||
if (strtolower($atts['with_bench']) === 'true') {
|
||||
$bench = $this->api->get_match_bench($match_id);
|
||||
if (!is_wp_error($bench)) {
|
||||
$bench_players = $bench;
|
||||
}
|
||||
return $this->render_error_message($players);
|
||||
}
|
||||
|
||||
// Check match ended & possibly save events + roster together
|
||||
@@ -722,68 +885,100 @@ class Swi_Foot_Shortcodes
|
||||
if (is_array($players)) {
|
||||
$this->api->save_finished_match_data(
|
||||
$match_id,
|
||||
array('players' => $players, 'bench' => $bench_players),
|
||||
array('players' => $players),
|
||||
$events
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter roster for side
|
||||
$filtered_players = array_filter($players, function ($p) use ($side) {
|
||||
// Filter players by team side
|
||||
$team_players = array_filter($players, function ($p) use ($side) {
|
||||
return $side === 'home' ? !empty($p['isHomeTeam']) : empty($p['isHomeTeam']);
|
||||
});
|
||||
$filtered_bench = array_filter($bench_players, function ($p) use ($side) {
|
||||
return $side === 'home' ? !empty($p['isHomeTeam']) : empty($p['isHomeTeam']);
|
||||
|
||||
// Split players into starting (assignmentRoleId = 0 or 1 for captain) and bench (assignmentRoleId > 1)
|
||||
$starting_players = array_filter($team_players, function ($p) {
|
||||
return isset($p['assignmentRoleId']) && ((int)$p['assignmentRoleId'] === 0 || (int)$p['assignmentRoleId'] === 1);
|
||||
});
|
||||
$bench_players = array_filter($team_players, function ($p) {
|
||||
return !isset($p['assignmentRoleId']) || ((int)$p['assignmentRoleId'] > 1);
|
||||
});
|
||||
|
||||
// If neither option is checked, return empty div
|
||||
if (!$show_starting && !$show_bench) {
|
||||
return '<div class="swi-foot-error">' . __('No roster display options selected', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="swi-foot-roster" data-match-id="<?php echo esc_attr($match_id); ?>">
|
||||
<h3><?php echo esc_html(ucfirst($side) . ' ' . __('Team Roster', 'swi_foot_matchdata')); ?></h3>
|
||||
<?php if (!empty($filtered_players)): ?>
|
||||
<ul class="roster-list">
|
||||
<?php foreach ($filtered_players as $pl): ?>
|
||||
<li>
|
||||
<?php
|
||||
$jersey = $pl['jerseyNumber'] ?? '';
|
||||
$firstname = $pl['firstname'] ?? '';
|
||||
$name = $pl['name'] ?? '';
|
||||
$secondName = $pl['secondName'] ?? '';
|
||||
$positionName = $pl['positionName'] ?? $pl['position'] ?? '';
|
||||
$displayName = trim($firstname . ' ' . $name . ' ' . $secondName);
|
||||
echo esc_html($jersey . ' – ' . $displayName);
|
||||
if (!empty($positionName)) {
|
||||
echo ' (' . esc_html($positionName) . ')';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
<p><?php _e('No roster data available.', 'swi_foot_matchdata'); ?></p>
|
||||
|
||||
<?php if ($show_starting && !empty($starting_players)): ?>
|
||||
<div class="swi-foot-roster-starting">
|
||||
<h4><?php _e('Starting Squad', 'swi_foot_matchdata'); ?></h4>
|
||||
<ul class="roster-list">
|
||||
<?php foreach ($starting_players as $pl): ?>
|
||||
<li class="roster-player<?php echo isset($pl['assignmentRoleId']) && (int)$pl['assignmentRoleId'] === 1 ? ' roster-player-captain' : ''; ?>">
|
||||
<?php
|
||||
$jersey = $pl['jerseyNumber'] ?? '';
|
||||
$firstname = $pl['firstname'] ?? '';
|
||||
$name = $pl['name'] ?? '';
|
||||
$secondName = $pl['secondName'] ?? '';
|
||||
$positionName = $pl['positionName'] ?? $pl['position'] ?? '';
|
||||
$isCaptain = isset($pl['assignmentRoleId']) && (int)$pl['assignmentRoleId'] === 1;
|
||||
$displayName = trim($firstname . ' ' . $name . ' ' . $secondName);
|
||||
|
||||
// Captain badge
|
||||
if ($isCaptain) {
|
||||
echo '<span class="swi-foot-captain-badge" title="' . esc_attr(__('Captain', 'swi_foot_matchdata')) . '">C</span> ';
|
||||
}
|
||||
|
||||
echo esc_html($jersey . ' – ' . $displayName);
|
||||
|
||||
if (!empty($positionName)) {
|
||||
echo ' <span class="swi-foot-position">(' . esc_html($positionName) . ')</span>';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($filtered_bench)): ?>
|
||||
<h4><?php _e('Bench', 'swi_foot_matchdata'); ?></h4>
|
||||
<ul class="roster-bench-list">
|
||||
<?php foreach ($filtered_bench as $pl): ?>
|
||||
<li>
|
||||
<?php
|
||||
$jersey = $pl['jerseyNumber'] ?? '';
|
||||
$firstname = $pl['firstname'] ?? '';
|
||||
$name = $pl['name'] ?? '';
|
||||
$secondName = $pl['secondName'] ?? '';
|
||||
$positionName = $pl['positionName'] ?? $pl['position'] ?? '';
|
||||
$displayName = trim($firstname . ' ' . $name . ' ' . $secondName);
|
||||
echo esc_html($jersey . ' – ' . $displayName);
|
||||
if (!empty($positionName)) {
|
||||
echo ' (' . esc_html($positionName) . ')';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if ($show_starting && !empty($starting_players) && $show_bench && !empty($bench_players)): ?>
|
||||
<hr class="swi-foot-roster-divider" />
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($show_bench && !empty($bench_players)): ?>
|
||||
<div class="swi-foot-roster-bench">
|
||||
<h4><?php _e('Bench', 'swi_foot_matchdata'); ?></h4>
|
||||
<ul class="roster-bench-list">
|
||||
<?php foreach ($bench_players as $pl): ?>
|
||||
<li class="roster-player">
|
||||
<?php
|
||||
$jersey = $pl['jerseyNumber'] ?? '';
|
||||
$firstname = $pl['firstname'] ?? '';
|
||||
$name = $pl['name'] ?? '';
|
||||
$secondName = $pl['secondName'] ?? '';
|
||||
$positionName = $pl['positionName'] ?? $pl['position'] ?? '';
|
||||
$displayName = trim($firstname . ' ' . $name . ' ' . $secondName);
|
||||
echo esc_html($jersey . ' – ' . $displayName);
|
||||
if (!empty($positionName)) {
|
||||
echo ' <span class="swi-foot-position">(' . esc_html($positionName) . ')</span>';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$show_starting && !empty($bench_players) && !$show_bench): ?>
|
||||
<p><?php _e('No roster data to display.', 'swi_foot_matchdata'); ?></p>
|
||||
<?php elseif ($show_starting && empty($starting_players) && empty($bench_players)): ?>
|
||||
<p><?php _e('No roster data available.', 'swi_foot_matchdata'); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
@@ -814,7 +1009,7 @@ class Swi_Foot_Shortcodes
|
||||
}
|
||||
|
||||
if (empty($match_id)) {
|
||||
return '<span class="swi-foot-error">' . __('Match ID required', 'swi_foot_matchdata') . '</span>';
|
||||
return '<div class="swi-foot-error">' . __('Match ID required', 'swi_foot_matchdata') . '</div>';
|
||||
}
|
||||
|
||||
// Try saved first
|
||||
@@ -824,7 +1019,7 @@ class Swi_Foot_Shortcodes
|
||||
} else {
|
||||
$events = $this->api->get_match_events($match_id);
|
||||
if (is_wp_error($events)) {
|
||||
return '<span class="swi-foot-error">' . __('Events data not available', 'swi_foot_matchdata') . '</span>';
|
||||
return $this->render_error_message($events);
|
||||
}
|
||||
|
||||
// Check if match ended and store both data sets
|
||||
|
||||
Reference in New Issue
Block a user