'hv_schema_render']); } add_action('init','hv_schema_register_block'); add_action('wp_enqueue_scripts',function(){ wp_enqueue_script('hv-schema-frontend'); wp_enqueue_style('hv-schema-style');}); function hv_schema_render(){ return '
'; } // server-side ICS fetch add_action('rest_api_init', function(){ register_rest_route('hv/v1','/schema',[ 'methods'=>'GET', 'callback'=>'hv_schema_fetch' ]); }); function hv_schema_fetch(){ // Hämta settings $signatur = get_option('hv_schema_signatur', 's.COH'); $antal = get_option('hv_schema_antal', 7); // Bygg ICS-URL dynamiskt $url = 'https://schema.hv.se/setup/jsp/SchemaICAL.ics' . '?startDatum=idag' . '&intervallTyp=m' . '&intervallAntal=6' . '&sprak=SV' . '&sokMedAND=true' . '&forklaringar=true' . '&resurser=' . urlencode($signatur); $res = wp_remote_get($url); if(is_wp_error($res)) return []; // Skicka både ICS OCH antal return [ 'ics' => wp_remote_retrieve_body($res), 'antal' => intval($antal) ]; } function hv_schema_settings_page(){ ?>