post_content : '';
$has = has_shortcode( $content, 'aicl_ai_notice' ) || has_shortcode( $content, 'aicl_disclosure' );
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 ''
. 'AI'
. '' . esc_html( $text ) . '';
}
/**
* Render the [aicl_disclosure] AI-content disclosure notice.
*
* A reusable, server-rendered notice for placing an AI disclosure anywhere shortcodes run
* (posts, pages, widgets, block templates), covering AI-generated/edited/assisted content
* (Article 50(2)) as well as chatbot interaction (Article 50(1)). Falls back to a per-type default.
*
* @since 1.2.6
*
* @param array|string $atts Attributes: type (ai-generated|ai-edited|ai-assisted|chatbot),
* style (inline|badge|banner), and an optional text override.
* @return string The disclosure HTML.
*/
public function disclosure( $atts ) {
$atts = shortcode_atts(
array(
'type' => 'ai-generated',
'style' => 'inline',
'text' => '',
),
$atts,
'aicl_disclosure'
);
$type = sanitize_key( (string) $atts['type'] );
$style = in_array( (string) $atts['style'], array( 'inline', 'badge', 'banner' ), true ) ? (string) $atts['style'] : 'inline';
$defaults = array(
'ai-generated' => __( 'This content was generated by AI.', 'aim-transparency' ),
'ai-edited' => __( 'This content was edited with AI.', 'aim-transparency' ),
'ai-assisted' => __( 'This content was produced with AI assistance.', 'aim-transparency' ),
'chatbot' => $this->text(),
);
$text = ( '' !== trim( (string) $atts['text'] ) )
? (string) $atts['text']
: ( isset( $defaults[ $type ] ) ? $defaults[ $type ] : $defaults['ai-generated'] );
wp_enqueue_style( 'aicl-notice', AICL_URL . 'assets/css/notice.css', array(), AICL_VERSION );
$tag = ( 'banner' === $style ) ? 'div' : 'span';
return '<' . $tag . ' class="aicl-ai-notice aicl-ai-notice-' . esc_attr( $style ) . '" role="note">'
. 'AI'
. '' . esc_html( $text ) . '' . $tag . '>';
}
/**
* 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 ) ) );
}
}