AI Disclosure). * * @package AI_Disclosure_For_Chatbots */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Settings module using the WordPress Settings API. */ class ADFC_Settings { /** * Plugin instance. * * @var ADFC_Plugin */ private $plugin; /** * Constructor. * * @param ADFC_Plugin $plugin Plugin instance. */ public function __construct( $plugin ) { $this->plugin = $plugin; add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_filter( 'plugin_action_links_' . plugin_basename( ADFC_PLUGIN_FILE ), array( $this, 'action_links' ) ); } /** * "Settings" link on the Plugins screen. * * @param array $links Existing links. * @return array */ public function action_links( $links ) { $url = admin_url( 'options-general.php?page=adfc-settings' ); array_unshift( $links, '' . esc_html__( 'Settings', 'ai-disclosure-for-chatbots' ) . '' ); return $links; } /** * Register the options page. * * @return void */ public function add_menu() { add_options_page( __( 'AI Disclosure', 'ai-disclosure-for-chatbots' ), __( 'AI Disclosure', 'ai-disclosure-for-chatbots' ), 'manage_options', 'adfc-settings', array( $this, 'render_page' ) ); } /** * Register setting + sections + fields. * * @return void */ public function register_settings() { register_setting( 'adfc_settings_group', ADFC_Plugin::OPTION_KEY, array( 'type' => 'array', 'sanitize_callback' => array( $this, 'sanitize' ), 'default' => ADFC_Plugin::defaults(), ) ); } /** * Sanitize submitted settings. * * @param array $input Raw input. * @return array */ public function sanitize( $input ) { $defaults = ADFC_Plugin::defaults(); $clean = array(); if ( ! is_array( $input ) ) { return $defaults; } $checkboxes = array( 'chatbot_disclosure_enabled', 'auto_detect_embeds', 'media_labels_enabled', 'media_auto_detect', 'media_machine_readable', ); foreach ( $checkboxes as $key ) { $clean[ $key ] = empty( $input[ $key ] ) ? 0 : 1; } $clean['chatbot_badge_text'] = isset( $input['chatbot_badge_text'] ) ? sanitize_text_field( $input['chatbot_badge_text'] ) : ''; $clean['media_badge_text'] = isset( $input['media_badge_text'] ) ? sanitize_text_field( $input['media_badge_text'] ) : ''; $position = isset( $input['chatbot_badge_position'] ) ? $input['chatbot_badge_position'] : 'top'; $clean['chatbot_badge_position'] = in_array( $position, array( 'top', 'bottom' ), true ) ? $position : 'top'; $style = isset( $input['media_badge_style'] ) ? $input['media_badge_style'] : 'corner'; $clean['media_badge_style'] = in_array( $style, array( 'corner', 'bar' ), true ) ? $style : 'corner'; $clean['custom_selectors'] = isset( $input['custom_selectors'] ) ? sanitize_textarea_field( $input['custom_selectors'] ) : ''; return array_merge( $defaults, $clean ); } /** * Render the settings page. * * @return void */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $p = $this->plugin; $detected = $p->detector->active_chatbot_plugins(); ?>