'. Block widget crons need the profile_url since it's difficult to connect the cron to the block it came from at cron execution. // //NOTE ON KEY STABILITY: single-event cron args form part of the event key (md5(serialize($args))). If a block's profile_url ever changes between schedule and fire, the old event becomes orphaned - it will still fire once against the old URL, then evaporate on its own. Not worth the complexity to fix IMHO. //fetches fresh steam data and writes the transient for the given instance id //on failure, extends the existing transient's TTL so an outage doesn't lose last-known-good data //returns true on success, or the error message string on failure //this function is used by classic widget, block widget, and REST refreshes function AdvancedSteamWidget_refresh_instance($id, $profile_url) { //normalize here so every refresh path (widget cron, block cron, REST) gets a canonical URL - fetch() prepends https:// blindly and would break on raw input like "https://..." $profile_url = AdvancedSteamWidget_normalize_profile_input($profile_url); try { $data = AdvancedSteamWidget_fetch($profile_url); AdvancedSteamWidget_set_cache($id, $data); return true; } catch (Exception $err) { //outage protection: re-set existing transient so its TTL restarts from now $existing = AdvancedSteamWidget_get_cache($id); if ($existing) AdvancedSteamWidget_set_cache($id, $existing['data'], $existing['fetched_at']); return $err->getMessage(); } } //on-demand single-event hook used by the block render path //blocks have no recurring per-instance cron - they schedule a single refresh when their cache goes stale add_action('advanced_steam_widget_refresh', 'AdvancedSteamWidget_refresh_instance', 10, 2); //schedules an immediate background refresh for the given instance if one isn't already queued //safe to call on every block render function AdvancedSteamWidget_maybe_schedule_refresh($id, $profile_url) { if (!wp_next_scheduled('advanced_steam_widget_refresh', array($id, $profile_url))) { wp_schedule_single_event(time(), 'advanced_steam_widget_refresh', array($id, $profile_url)); } }