AIVASTARK_WIDGET_BAKED_KEY ), $opts ); } /** * Enqueue the widget for the given key. Idempotent — inline data is only * attached the first time, so multiple shortcodes on one page are safe. */ function aivastark_widget_enqueue( $key ) { static $attached = false; $key = trim( (string) $key ); if ( '' === $key ) { return; } wp_enqueue_script( 'aivastark-widget' ); if ( $attached ) { return; } $attached = true; $config = wp_json_encode( array( 'key' => $key ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); wp_add_inline_script( 'aivastark-widget', 'window.AivastarkConfig=' . $config . ';', 'before' ); } /** * Origin of the Aivastark dashboard SPA (OAuth approval + embed iframe). * Filterable so staging / self-hosted dashboards can be targeted. */ function aivastark_widget_dashboard_url() { $url = apply_filters( 'aivastark_widget_dashboard_url', AIVASTARK_WIDGET_DASHBOARD_URL ); return untrailingslashit( esc_url_raw( $url ) ); } /** * Base URL of the Aivastark Supabase Edge Functions (pairing + SSO). Filterable. */ function aivastark_widget_functions_url() { $url = apply_filters( 'aivastark_widget_functions_url', AIVASTARK_WIDGET_FUNCTIONS_URL ); return untrailingslashit( esc_url_raw( $url ) ); } /** * Public (publishable) anon key sent as the `apikey` header to the Edge * Functions gateway. Public value; filterable for staging. */ function aivastark_widget_anon_key() { return (string) apply_filters( 'aivastark_widget_anon_key', AIVASTARK_WIDGET_ANON_KEY ); } /** * Mask a Widget Key for display (show only the last 4 characters). */ function aivastark_widget_mask_key( $key ) { $key = trim( (string) $key ); if ( strlen( $key ) <= 4 ) { return $key; } return str_repeat( '•', max( 0, strlen( $key ) - 4 ) ) . substr( $key, -4 ); }