' . __('Configure your Swiss Football API credentials here.', 'swi_foot_matchdata') . '

'; } public function cache_section_callback() { echo '

' . __('Configure caching settings for match data.', 'swi_foot_matchdata') . '

'; } public function base_url_render() { $base_url = get_option('swi_foot_api_base_url', 'https://stg-club-api-services.football.ch'); echo ''; echo '

' . __('The base URL for the Swiss Football API', 'swi_foot_matchdata') . '

'; } public function username_render() { $username = get_option('swi_foot_api_username'); echo ''; echo '

' . __('Your API application key', 'swi_foot_matchdata') . '

'; } public function password_render() { $password = get_option('swi_foot_api_password'); echo ''; echo '

' . __('Your API application password', 'swi_foot_matchdata') . '

'; } public function verein_id_render() { $verein_id = get_option('swi_foot_verein_id'); echo ''; echo '

' . __('Enter your club\'s Verein ID (Club ID)', 'swi_foot_matchdata') . '

'; } public function season_id_render() { $season_id = get_option('swi_foot_season_id', date('Y')); echo ''; echo '

' . __('Current season ID (usually the year)', 'swi_foot_matchdata') . '

'; } public function cache_duration_render() { $duration = get_option('swi_foot_match_cache_duration', 30); echo ''; echo '

' . __('How long to cache match data in seconds (10-300)', 'swi_foot_matchdata') . '

'; } public function admin_scripts($hook) { if ($hook === 'settings_page_swiss-football-matchdata') { wp_enqueue_script('swi-foot-admin', SWI_FOOT_PLUGIN_URL . 'assets/admin.js', array('jquery'), SWI_FOOT_PLUGIN_VERSION, true); wp_localize_script('swi-foot-admin', 'swi_foot_ajax', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('swi_foot_nonce'), 'rest_url' => esc_url_raw(rest_url('swi-foot/v1')), 'rest_nonce' => wp_create_nonce('wp_rest') )); wp_enqueue_style('swi-foot-admin', SWI_FOOT_PLUGIN_URL . 'assets/admin.css', array(), SWI_FOOT_PLUGIN_VERSION); } // Add shortcode help to post/page editors global $pagenow; if (in_array($pagenow, array('post.php', 'post-new.php', 'edit.php'))) { // Enqueue the registered editor bundle so WordPress picks the built asset when available. // The script handle `swi-foot-editor-blocks` is registered in `register_blocks()`. wp_enqueue_script('swi-foot-editor-blocks'); // Add admin footer debug output to help diagnose missing script tags. add_action('admin_footer', array($this, 'print_editor_script_debug')); // Post context editor panel: allow editor to set per-post season/team/match wp_enqueue_script('swi-foot-post-context', SWI_FOOT_PLUGIN_URL . 'assets/post-context.js', array('wp-plugins','wp-edit-post','wp-element','wp-data','wp-components'), SWI_FOOT_PLUGIN_VERSION, true); wp_localize_script('swi-foot-post-context', 'swi_foot_post_context', array( 'rest_url' => esc_url_raw(rest_url('swi-foot/v1')), 'rest_nonce' => wp_create_nonce('wp_rest'), 'default_season' => get_option('swi_foot_season_id', date('Y')) )); wp_enqueue_style('swi-foot-admin', SWI_FOOT_PLUGIN_URL . 'assets/admin.css', array(), SWI_FOOT_PLUGIN_VERSION); } } public function print_editor_script_debug() { // Only show on post editor pages $pagenow = isset($GLOBALS['pagenow']) ? $GLOBALS['pagenow'] : ''; if (!in_array($pagenow, array('post.php', 'post-new.php', 'edit.php'))) return; // Check registration/enqueue status and attempt to find the resolved src $registered = false; $enqueued = false; $src = ''; global $wp_scripts; if (isset($wp_scripts) && is_object($wp_scripts)) { $registered = wp_script_is('swi-foot-editor-blocks', 'registered'); $enqueued = wp_script_is('swi-foot-editor-blocks', 'enqueued'); $handle = $wp_scripts->query('swi-foot-editor-blocks', 'registered'); if ($handle && isset($wp_scripts->registered['swi-foot-editor-blocks']->src)) { $src = $wp_scripts->registered['swi-foot-editor-blocks']->src; } } $msg = array( 'registered' => $registered ? 'yes' : 'no', 'enqueued' => $enqueued ? 'yes' : 'no', 'src' => $src ); echo ""; } public function add_match_meta_boxes() { add_meta_box( 'swi-foot-shortcodes', __('Swiss Football Shortcodes', 'swi_foot_matchdata'), array($this, 'shortcodes_meta_box'), array('post', 'page'), 'side', 'default' ); } public function shortcodes_meta_box($post) { ?>

[swi_foot_match match_id="12345"] [swi_foot_match team_id="67" show_next="true"]
[swi_foot_match_home_team match_id="12345"] [swi_foot_match_away_team match_id="12345"] [swi_foot_match_date match_id="12345" format="d.m.Y"] [swi_foot_match_time match_id="12345" format="H:i"] [swi_foot_match_venue match_id="12345"] [swi_foot_match_score match_id="12345" separator=":"] [swi_foot_match_status match_id="12345"] [swi_foot_match_league match_id="12345"] [swi_foot_match_round match_id="12345"]

display_teams(); ?>

display_cache_info(); ?>

display_finished_matches(); ?>


[swi_foot_match match_id="12345"]


[swi_foot_match team_id="67" show_next="true"]


[swi_foot_match_home_team match_id="12345"] [swi_foot_match_away_team match_id="12345"] [swi_foot_match_date match_id="12345"]

get_teams(); if (is_wp_error($teams)) { echo '

' . sprintf(__('Error loading teams: %s', 'swi_foot_matchdata'), $teams->get_error_message()) . '

'; return; } if (empty($teams)) { echo '

' . __('No teams found. Please check your API configuration.', 'swi_foot_matchdata') . '

'; return; } echo '

' . __('Available Teams:', 'swi_foot_matchdata') . '

'; echo '
'; foreach ($teams as $team) { echo '
'; echo '' . esc_html($team['teamName'] ?? 'Unknown Team') . '
'; echo 'ID: ' . esc_html($team['teamId'] ?? 'N/A') . '
'; if (!empty($team['teamLeagueName'])) { echo '' . esc_html($team['teamLeagueName']) . ''; } echo '
'; } echo '
'; } private function display_cache_info() { $keys = get_transient('swi_foot_match_keys'); $cache_count = is_array($keys) ? count($keys) : 0; $cache_duration = get_option('swi_foot_match_cache_duration', 30); echo '

' . sprintf(__('Currently caching %d match records with %d second cache duration.', 'swi_foot_matchdata'), $cache_count, $cache_duration) . '

'; if ($cache_count > 0) { $timestamps = array(); foreach ($keys as $k) { $payload = get_transient('swi_foot_match_' . $k); if (is_array($payload) && isset($payload['cached_at'])) { $timestamps[] = (int) $payload['cached_at']; } } if (!empty($timestamps)) { $oldest_timestamp = min($timestamps); $newest_timestamp = max($timestamps); echo '

' . __('Cache Range:', 'swi_foot_matchdata') . '
'; echo __('Oldest:', 'swi_foot_matchdata') . ' ' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $oldest_timestamp) . '
'; echo __('Newest:', 'swi_foot_matchdata') . ' ' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $newest_timestamp) . '

'; } } } private function display_finished_matches() { $finished = get_option('swi_foot_finished_matches', array()); if (empty($finished)) { echo '

' . __('No finished match data stored.', 'swi_foot_matchdata') . '

'; return; } echo ''; echo ''; foreach ($finished as $mid => $item) { $players = count($item['roster']['players'] ?? array()); $bench = count($item['roster']['bench'] ?? array()); $events = count($item['events'] ?? array()); $saved = !empty($item['saved_at']) ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $item['saved_at']) : '-'; echo ''; } echo '
' . __('Match ID', 'swi_foot_matchdata') . ' ' . __('Saved At', 'swi_foot_matchdata') . ' ' . __('Players', 'swi_foot_matchdata') . ' ' . __('Bench', 'swi_foot_matchdata') . ' ' . __('Events', 'swi_foot_matchdata') . '
' . esc_html($mid) . ' ' . esc_html($saved) . ' ' . esc_html($players) . ' ' . esc_html($bench) . ' ' . esc_html($events) . '
'; echo '

'; // Include inline JS for actions ?>