plugin = $plugin; add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); // Deep integration: prepend disclosure to AI Engine chatbot start sentence. add_filter( 'mwai_chatbot_params', array( $this, 'ai_engine_params' ), 20 ); } /** * Whether disclosure is enabled. * * @return bool */ private function enabled() { return (bool) $this->plugin->get_setting( 'chatbot_disclosure_enabled' ); } /** * The disclosure text (custom or locale default). * * @return string */ public function disclosure_text() { $text = trim( (string) $this->plugin->get_setting( 'chatbot_badge_text' ) ); if ( '' === $text ) { $text = $this->plugin->default_chatbot_text(); } /** * Filter the chatbot disclosure text. * * @param string $text Disclosure text. */ return apply_filters( 'adfc_chatbot_disclosure_text', $text ); } /** * Enqueue the front-end watcher script and styles. * * @return void */ public function enqueue_assets() { if ( ! $this->enabled() || is_admin() ) { return; } $watch = $this->plugin->detector->frontend_watch_list( $this->plugin ); if ( empty( $watch ) && ! $this->plugin->get_setting( 'media_labels_enabled' ) ) { return; } wp_enqueue_style( 'adfc-frontend', ADFC_PLUGIN_URL . 'assets/css/adfc.css', array(), ADFC_VERSION ); wp_enqueue_script( 'adfc-frontend', ADFC_PLUGIN_URL . 'assets/js/adfc.js', array(), ADFC_VERSION, true ); wp_localize_script( 'adfc-frontend', 'adfcConfig', array( 'watch' => $watch, 'text' => $this->disclosure_text(), 'position' => (string) $this->plugin->get_setting( 'chatbot_badge_position' ), 'ariaLabel' => __( 'AI disclosure notice', 'ai-disclosure-for-chatbots' ), ) ); } /** * AI Engine integration: make the disclosure part of the bot's own UI by * prepending it to the start sentence, so the notice appears at first * interaction inside the chat itself (Art. 50(1): at the latest at the * time of the first interaction, in a clear and distinguishable manner). * * @param array $params AI Engine chatbot params. * @return array */ public function ai_engine_params( $params ) { if ( ! $this->enabled() || ! is_array( $params ) ) { return $params; } $disclosure = $this->disclosure_text(); if ( isset( $params['startSentence'] ) && is_string( $params['startSentence'] ) ) { if ( false === strpos( $params['startSentence'], $disclosure ) ) { $params['startSentence'] = $disclosure . ' ' . $params['startSentence']; } } else { $params['startSentence'] = $disclosure; } return $params; } }