PHP Core Logic
Overview
The core logic of the Supervised AI Bots plugin is handled via WordPress hooks to manage asset delivery and provide a shortcode-based interface for content editors. The PHP component acts as the bridge between the stored Supervised AI bot URLs and the frontend interactive popup.
Shortcode Implementation
The plugin provides a primary shortcode to embed chatbots into any page, post, or widget area.
[supervised_ai_bot]
This shortcode generates the HTML structure required for the chatbot popup and ensures the necessary scripts are triggered.
Attributes:
id(integer|string): The row index of the bot URL configured in the settings page.- Example:
id="1"refers to the first URL in your settings list.
- Example:
Usage:
[supervised_ai_bot id="1"]
Output: The shortcode renders:
- A floating action button (trigger).
- A hidden iframe container mapped to the Supervised AI URL.
- The necessary state-management classes to interface with the CSS and JavaScript.
Asset Management
The plugin automatically handles the registration and enqueuing of frontend assets. This ensures that the chatbot's visual style and toggle functionality are only loaded when WordPress renders the site.
Script and Style Enqueuing
The PHP core utilizes the wp_enqueue_scripts hook to load the following:
custom-popup-style.css: Defines the layout, positioning (fixed bottom-right), and iframe dimensions.custom-popup-script.js: Controls thetogglePopup()andclosePopup()logic.
Internal logic ensures these assets are loaded correctly to prevent conflicts with other WordPress themes or plugins.
Administration Interface
The plugin registers a custom settings page within the WordPress Dashboard. This interface allows administrators to manage the bot data used by the shortcode.
Bot URL Management
- Location:
Settings>Supervised AI Bots. - Data Structure: A textarea field accepts one URL per line.
- Persistence: Data is sanitized and stored in the WordPress
optionstable.
The PHP core logic retrieves these stored URLs during the shortcode execution, mapping the id attribute provided by the user to the corresponding line in the saved settings.
Technical Hooks (Internal)
While intended for use via the administration interface, the plugin utilizes standard WordPress hooks that are important to be aware of:
add_shortcode(): Registers thesupervised_ai_bottag.admin_menu: Injects the settings page into the dashboard.admin_init: Handles the registration of settings and sanitization of the URL input.