Hooks and Registration
Shortcode Registration
The plugin registers a primary shortcode that allows you to embed specific AI chatbots into any post, page, or widget area.
[supervised_ai_bot]
This shortcode fetches the URL configured in the plugin settings based on the provided ID and renders the chatbot interface.
Attributes:
id(string/int): The row number of the chatbot URL as defined in the "Supervised AI Bots" settings page (e.g.,1for the first URL,2for the second).
Example Usage:
<!-- Display the first configured chatbot -->
[supervised_ai_bot id="1"]
Asset Enqueueing
The plugin automatically handles the registration and loading of frontend styles and scripts required for the chatbot popup to function and display correctly. These assets are enqueued on the frontend using the standard wp_enqueue_scripts hook.
CSS Styles
The plugin registers and enqueues custom-popup-style.css. This stylesheet defines:
- Popup Container: The fixed position, dimensions (670px height), and z-index of the chat window.
- Circle Button: The floating action button (FAB) used to trigger the chat.
- Responsive Iframe: Ensures the chatbot content fills the popup container.
JavaScript Scripts
The plugin registers and enqueues custom-popup-script.js. This script manages the visibility of the chatbot interface.
Public JavaScript API
While the plugin handles most interactions automatically via the floating action button, developers can programmatically control the chatbot popup using the following global functions exposed by the plugin's script:
togglePopup()
Switches the visibility of the chatbot between block and none.
- Usage: Can be attached to custom buttons or event listeners.
- Example:
<button onclick="togglePopup()">Chat with us</button>
closePopup()
Explicitly hides the chatbot popup.
- Usage: Useful for closing the chat window upon specific user actions or navigation events.
Admin Registration
The plugin integrates with the WordPress Dashboard to provide a management interface.
Menu Page
The plugin registers a top-level menu item titled Supervised AI Bots. This is where users input the chatbot URLs (one per line). These URLs are stored as WordPress options and are retrieved by the shortcode renderer.
Settings Lifecycle
- Registration: Settings are registered during
admin_init. - Menu Creation: The administration page is added via the
admin_menuhook. - Data Persistence: Chatbot URLs are saved to the
wp_optionstable, ensuring they are globally accessible via the shortcode.