true]); }); register_activation_hook(__FILE__, function() { $role = get_role('administrator'); if ($role) { $role->add_cap('sportspress_can_control_score'); } }); register_deactivation_hook(__FILE__, function() { $role = get_role('administrator'); if ($role) { $role->remove_cap('sportspress_can_control_score'); } }); // Add meta box for scoreboard timeline add_action('add_meta_boxes', function() { add_meta_box('scoreboard_timeline', 'Scoreboard Timeline', 'render_scoreboard_meta_box', 'sp_event'); }); function render_scoreboard_meta_box($post) { $json = get_post_meta($post->ID, '_scoreboard_timeline', true); $json = $json ? esc_textarea($json) : '{}'; echo ''; } // Save scoreboard meta add_action('save_post_sp_event', function($post_id) { if (isset($_POST['scoreboard_timeline_json'])) { update_post_meta($post_id, '_scoreboard_timeline', wp_unslash($_POST['scoreboard_timeline_json'])); } }); add_action('wp_enqueue_scripts', function() { if (is_singular('sp_event')) { wp_enqueue_script('scoreboard-js', plugins_url('/js/scoreboard.js', __FILE__), ['jquery'], null, true); wp_enqueue_script('scoreboard-controls-js', plugins_url('/js/scoreboard-controls.js', __FILE__), ['jquery'], null, true); wp_localize_script('scoreboard-js', 'scoreboardData', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'eventId' => get_the_ID(), 'canEdit' => current_user_can('sportspress_can_control_score'), 'timeline' => get_post_meta(get_the_ID(), '_scoreboard_timeline', true) ?: '{}', 'templatesUrl' => plugins_url('/html/', __FILE__) ]); } }); // AJAX endpoint for saving scoreboard add_action('wp_ajax_update_scoreboard', function() { if (!current_user_can('sportspress_can_control_score')) { wp_send_json_error('Unauthorized'); } $event_id = intval($_POST['event_id']); $timeline = wp_unslash($_POST['timeline']); update_post_meta($event_id, '_scoreboard_timeline', $timeline); wp_send_json_success(); }); add_shortcode('live_score', function($atts) { ob_start(); ?>