post_content, 'aicl_ai_notice' ); if ( ! $auto && ! $has ) { return; } wp_enqueue_style( 'aicl-notice', AICL_URL . 'assets/css/notice.css', array(), AICL_VERSION ); if ( ! $auto ) { return; } wp_enqueue_script( 'aicl-notice', AICL_URL . 'assets/js/notice.js', array(), AICL_VERSION, true ); wp_add_inline_script( 'aicl-notice', 'window.AICL_NOTICE=' . wp_json_encode( $this->config() ), 'before' ); } /** * The front-end config passed to notice.js. * * @since 1.1.0 * * @return array Disclosure text, corner position, and the chat-widget selectors to watch. */ protected function config() { return array( 'text' => $this->text(), 'position' => (string) AICL_Plugin::opt( 'chatbot_notice_position' ), 'selectors' => $this->selectors(), ); } /** * Render the [aicl_ai_notice] inline disclosure notice. * * @since 1.1.0 * * @param array|string $atts Shortcode attributes: 'text' overrides the configured disclosure. * @return string The notice HTML. */ public function shortcode( $atts ) { $atts = shortcode_atts( array( 'text' => '' ), $atts, 'aicl_ai_notice' ); $text = ( '' !== trim( (string) $atts['text'] ) ) ? (string) $atts['text'] : $this->text(); wp_enqueue_style( 'aicl-notice', AICL_URL . 'assets/css/notice.css', array(), AICL_VERSION ); return '' . '' . '' . esc_html( $text ) . ''; } /** * The disclosure text, falling back to the built-in default when the option is empty. * * @since 1.1.0 * * @return string */ protected function text() { $text = trim( (string) AICL_Plugin::opt( 'chatbot_notice_text' ) ); return '' !== $text ? $text : __( 'You are chatting with an AI assistant, not a human.', 'aim-transparency' ); } /** * The built-in chat-widget selectors plus any the deployer added. * * @since 1.1.0 * * @return string[] CSS selectors whose presence indicates a chat widget is on the page. */ protected function selectors() { $presets = array( '#tidio-chat', '.crisp-client', '#intercom-container', '#hubspot-messages-iframe-container', '.drift-frame-controller', '#chat-widget-container', 'df-messenger', '#tawkchat-container', '#chatbase-bubble-button', '#zsiq_float', ); $custom = preg_split( '/[\r\n,]+/', (string) AICL_Plugin::opt( 'chatbot_notice_selectors' ) ); $custom = is_array( $custom ) ? array_filter( array_map( 'trim', $custom ) ) : array(); return array_values( array_unique( array_merge( $presets, $custom ) ) ); } }