api = new ActoSync_API(); } /** * Render shortcode */ public function render($atts = []) { $atts = shortcode_atts([ 'widget_id' => '', 'agent_id' => '', 'user_id' => '', ], $atts, 'actosync_chat_widget'); // Failsafe sanitation map $widget_id = sanitize_text_field(!empty($atts['widget_id']) ? $atts['widget_id'] : ''); $agent_id = sanitize_text_field(!empty($atts['agent_id']) ? $atts['agent_id'] : ''); $user_id = sanitize_text_field(!empty($atts['user_id']) ? $atts['user_id'] : ''); $config = $this->api->get_config(); // Fall back to config values if shortcode attributes are empty $widget_id = !empty($widget_id) ? $widget_id : ($config['widget_id'] ?? ''); $agent_id = !empty($agent_id) ? $agent_id : ($config['agent_id'] ?? ''); $user_id = !empty($user_id) ? $user_id : ($config['user_id'] ?? ''); // Ensure configuration strings pulled from settings are also safely treated $agent_name = esc_html($config['agent_name'] ?? 'AI Assistant'); // Validate configuration safely if (empty($widget_id) || empty($agent_id) || empty($user_id)) { return ''; } // Start output buffering to load template ob_start(); ?>