'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ) ); register_setting( 'agentix_ia_options_group', 'agentix_ia_agent_id', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ) ); add_settings_section( 'agentix_ia_section', __( 'Agentix IA Integration Settings', 'agentix-ia-chatbot-ai-customer-support' ), 'agentix_ia_section_callback', 'agentix-ia' ); add_settings_field( 'agentix_ia_user_id', __( 'User ID', 'agentix-ia-chatbot-ai-customer-support' ), 'agentix_ia_user_id_render', 'agentix-ia', 'agentix_ia_section' ); add_settings_field( 'agentix_ia_agent_id', __( 'Agent ID', 'agentix-ia-chatbot-ai-customer-support' ), 'agentix_ia_agent_id_render', 'agentix-ia', 'agentix_ia_section' ); } /** * Settings section description. */ function agentix_ia_section_callback() { echo '

' . esc_html__( 'Enter your Agentix IA credentials below to embed your AI agent widget.', 'agentix-ia-chatbot-ai-customer-support' ) . '

'; } /** * User ID field. */ function agentix_ia_user_id_render() { $user_id = get_option( 'agentix_ia_user_id', '' ); echo ''; } /** * Agent ID field. */ function agentix_ia_agent_id_render() { $agent_id = get_option( 'agentix_ia_agent_id', '' ); echo ''; printf( '

%1$s %2$s.

', esc_html__( 'Need an AI agent?', 'agentix-ia-chatbot-ai-customer-support' ), esc_html__( 'Create your free account on Agentix IA', 'agentix-ia-chatbot-ai-customer-support' ) ); } /** * Plugin settings page. */ function agentix_ia_options_page() { ?>

true, 'strategy' => 'defer', ) ); wp_enqueue_script( 'agentix-widget-loader' ); } } add_filter( 'script_loader_tag', 'agentix_ia_add_script_attributes', 10, 3 ); /** * Add data attributes to the widget script tag. * * @param string $tag Script tag HTML. * @param string $handle Script handle. * @param string $src Script URL. * @return string */ function agentix_ia_add_script_attributes( $tag, $handle, $src ) { if ( 'agentix-widget-loader' !== $handle ) { return $tag; } $user_id = esc_attr( get_option( 'agentix_ia_user_id', '' ) ); $agent_id = esc_attr( get_option( 'agentix_ia_agent_id', '' ) ); if ( ! empty( $user_id ) && ! empty( $agent_id ) ) { return str_replace( ' src=', ' data-user-id="' . $user_id . '" data-agent-id="' . $agent_id . '" src=', $tag ); } return $tag; }