<?php
/**
* Plugin Name: thinnestAI Chat Widget
* Description: AI chat widget powered by thinnestAI
* Version: 1.0
*/
function thinnestai_enqueue_widget() {
$agent_id = get_option('thinnestai_agent_id', '');
if (empty($agent_id)) return;
wp_enqueue_script(
'thinnestai-embed',
'https://app.thinnest.ai/embed.js',
array(),
null,
true
);
wp_script_add_data('thinnestai-embed', 'data-agent-id', $agent_id);
}
add_action('wp_enqueue_scripts', 'thinnestai_enqueue_widget');
// Settings page
function thinnestai_settings_page() {
add_options_page(
'thinnestAI Settings',
'thinnestAI',
'manage_options',
'thinnestai',
'thinnestai_settings_html'
);
}
add_action('admin_menu', 'thinnestai_settings_page');
function thinnestai_settings_html() {
if (!current_user_can('manage_options')) return;
if (isset($_POST['thinnestai_agent_id'])) {
check_admin_referer('thinnestai_settings');
update_option('thinnestai_agent_id', sanitize_text_field($_POST['thinnestai_agent_id']));
echo '<div class="updated"><p>Settings saved.</p></div>';
}
$agent_id = get_option('thinnestai_agent_id', '');
?>
<div class="wrap">
<h1>thinnestAI Settings</h1>
<form method="post">
<?php wp_nonce_field('thinnestai_settings'); ?>
<table class="form-table">
<tr>
<th><label for="thinnestai_agent_id">Agent ID</label></th>
<td><input type="text" id="thinnestai_agent_id" name="thinnestai_agent_id"
value="<?php echo esc_attr($agent_id); ?>" class="regular-text" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Output embed script with data attributes
function thinnestai_add_widget_script() {
$agent_id = get_option('thinnestai_agent_id', '');
if (empty($agent_id)) return;
?>
<script
src="https://app.thinnest.ai/embed.js"
data-agent-id="<?php echo esc_attr($agent_id); ?>"
data-theme="light"
data-position="bottom-right"
async
></script>
<?php
}
add_action('wp_footer', 'thinnestai_add_widget_script');