'', 'theme' => 'light', 'lang' => 'en', 'position' => 'bottom-right', 'button_color' => '', 'auto_open' => false, 'open_delay' => 0, 'greeting' => '', ); } /** * Get a single option value. */ function leezy_get_option( $key ) { $options = get_option( 'leezy_options', array() ); $defaults = leezy_defaults(); return isset( $options[ $key ] ) ? $options[ $key ] : ( isset( $defaults[ $key ] ) ? $defaults[ $key ] : '' ); } /* ────────────────────────────────────────────── * Admin Menu & Settings * ────────────────────────────────────────────── */ add_action( 'admin_menu', 'leezy_admin_menu' ); function leezy_admin_menu() { add_menu_page( __( 'Leezy Settings', 'leezy' ), __( 'Leezy', 'leezy' ), 'manage_options', 'leezy', 'leezy_settings_page', plugins_url( 'assets/images/favicon.svg', __FILE__ ), 80 ); } add_action( 'admin_init', 'leezy_register_settings' ); function leezy_register_settings() { register_setting( 'leezy_settings', 'leezy_options', array( 'type' => 'array', 'sanitize_callback' => 'leezy_sanitize_options', 'default' => leezy_defaults(), ) ); add_settings_section( 'leezy_main', __( 'Chatbot Configuration', 'leezy' ), 'leezy_section_main_cb', 'leezy' ); $fields = array( 'bot_id' => array( 'label' => __( 'Bot ID', 'leezy' ), 'cb' => 'leezy_field_bot_id' ), 'theme' => array( 'label' => __( 'Theme', 'leezy' ), 'cb' => 'leezy_field_theme' ), 'lang' => array( 'label' => __( 'Language', 'leezy' ), 'cb' => 'leezy_field_lang' ), 'position' => array( 'label' => __( 'Widget Position', 'leezy' ), 'cb' => 'leezy_field_position' ), 'button_color' => array( 'label' => __( 'Button Color', 'leezy' ), 'cb' => 'leezy_field_button_color' ), 'auto_open' => array( 'label' => __( 'Auto-Open', 'leezy' ), 'cb' => 'leezy_field_auto_open' ), 'open_delay' => array( 'label' => __( 'Open Delay (ms)', 'leezy' ), 'cb' => 'leezy_field_open_delay' ), 'greeting' => array( 'label' => __( 'Greeting Message', 'leezy' ), 'cb' => 'leezy_field_greeting' ), ); foreach ( $fields as $id => $field ) { add_settings_field( "leezy_{$id}", $field['label'], $field['cb'], 'leezy', 'leezy_main' ); } } function leezy_sanitize_options( $input ) { $clean = leezy_defaults(); $clean['bot_id'] = isset( $input['bot_id'] ) ? sanitize_text_field( $input['bot_id'] ) : ''; $clean['theme'] = isset( $input['theme'] ) && in_array( $input['theme'], array( 'light', 'dark' ), true ) ? $input['theme'] : 'light'; $clean['lang'] = isset( $input['lang'] ) ? sanitize_text_field( substr( $input['lang'], 0, 10 ) ) : 'en'; $positions = array( 'bottom-right', 'bottom-left', 'top-right', 'top-left' ); $clean['position'] = isset( $input['position'] ) && in_array( $input['position'], $positions, true ) ? $input['position'] : 'bottom-right'; $clean['button_color'] = isset( $input['button_color'] ) ? sanitize_hex_color( $input['button_color'] ) : ''; if ( null === $clean['button_color'] ) { $clean['button_color'] = ''; } $clean['auto_open'] = ! empty( $input['auto_open'] ); $clean['open_delay'] = isset( $input['open_delay'] ) ? absint( $input['open_delay'] ) : 0; $clean['greeting'] = isset( $input['greeting'] ) ? sanitize_text_field( $input['greeting'] ) : ''; return $clean; } /* ── Section Callback ─────────────────────── */ function leezy_section_main_cb() { echo '

' . wp_kses( __( 'Connect your Leezy chatbot. Find your Bot ID in your Leezy dashboard under Settings → Installation.', 'leezy' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) ) ) . '

'; echo '

' . wp_kses( __( 'Don\'t have an account yet? Sign up for free to create your AI chatbot.', 'leezy' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) ) ) . '

'; } /* ── Field Callbacks ──────────────────────── */ function leezy_field_bot_id() { $val = leezy_get_option( 'bot_id' ); echo ''; echo '

' . esc_html__( 'Your unique chatbot identifier from the Leezy dashboard.', 'leezy' ) . '

'; } function leezy_field_theme() { $val = leezy_get_option( 'theme' ); echo ''; } function leezy_field_lang() { $val = leezy_get_option( 'lang' ); $languages = array( 'en' => 'English', 'de' => 'Deutsch', 'fr' => 'Français', 'es' => 'Español', 'it' => 'Italiano', 'pt' => 'Português', 'nl' => 'Nederlands', 'pl' => 'Polski', 'ru' => 'Русский', 'ja' => '日本語', 'ko' => '한국어', 'zh' => '中文', 'ar' => 'العربية', 'tr' => 'Türkçe', 'sv' => 'Svenska', 'da' => 'Dansk', 'fi' => 'Suomi', 'nb' => 'Norsk', 'cs' => 'Čeština', 'uk' => 'Українська', ); echo ''; echo '

' . esc_html__( 'The chatbot interface language. Your bot responds in 50+ languages regardless of this setting.', 'leezy' ) . '

'; } function leezy_field_position() { $val = leezy_get_option( 'position' ); $opts = array( 'bottom-right' => __( 'Bottom Right', 'leezy' ), 'bottom-left' => __( 'Bottom Left', 'leezy' ), 'top-right' => __( 'Top Right', 'leezy' ), 'top-left' => __( 'Top Left', 'leezy' ), ); echo ''; } function leezy_field_button_color() { $val = leezy_get_option( 'button_color' ); echo ''; echo '

' . esc_html__( 'Leave empty to use your chatbot\'s configured color.', 'leezy' ) . '

'; } function leezy_field_auto_open() { $val = leezy_get_option( 'auto_open' ); echo ''; } function leezy_field_open_delay() { $val = leezy_get_option( 'open_delay' ); echo ''; echo '

' . esc_html__( 'Delay in milliseconds before auto-opening. Only applies when Auto-Open is enabled.', 'leezy' ) . '

'; } function leezy_field_greeting() { $val = leezy_get_option( 'greeting' ); echo ''; echo '

' . esc_html__( 'Custom greeting message. Leave empty to use the default from your Leezy dashboard.', 'leezy' ) . '

'; } /* ── Settings Page ────────────────────────── */ function leezy_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>
v

esc_attr( $bot_id ), ); // Optional attributes — only add if set. $theme = leezy_get_option( 'theme' ); if ( $theme && 'light' !== $theme ) { $attrs['data-theme'] = esc_attr( $theme ); } $lang = leezy_get_option( 'lang' ); if ( $lang && 'en' !== $lang ) { $attrs['data-lang'] = esc_attr( $lang ); } $position = leezy_get_option( 'position' ); if ( $position && 'bottom-right' !== $position ) { $attrs['data-position'] = esc_attr( $position ); } $color = leezy_get_option( 'button_color' ); if ( ! empty( $color ) ) { $attrs['data-button-color'] = esc_attr( $color ); } $auto_open = leezy_get_option( 'auto_open' ); if ( $auto_open ) { $attrs['data-auto-open'] = 'true'; $delay = leezy_get_option( 'open_delay' ); if ( $delay > 0 ) { $attrs['data-open-delay'] = intval( $delay ); } } $greeting = leezy_get_option( 'greeting' ); if ( ! empty( $greeting ) ) { $attrs['data-greeting'] = esc_attr( $greeting ); } $attr_str = ''; foreach ( $attrs as $key => $value ) { $attr_str .= ' ' . $key . '="' . $value . '"'; } // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript echo '' . "\n"; } /* ────────────────────────────────────────────── * Activation & Plugin Links * ────────────────────────────────────────────── */ register_activation_hook( __FILE__, 'leezy_activate' ); function leezy_activate() { if ( false === get_option( 'leezy_options' ) ) { add_option( 'leezy_options', leezy_defaults() ); } set_transient( 'leezy_activation_redirect', true, 30 ); } add_action( 'admin_init', 'leezy_activation_redirect' ); function leezy_activation_redirect() { if ( get_transient( 'leezy_activation_redirect' ) ) { delete_transient( 'leezy_activation_redirect' ); if ( ! isset( $_GET['activate-multi'] ) ) { wp_safe_redirect( admin_url( 'admin.php?page=leezy' ) ); exit; } } } // Add "Settings" link on Plugins page. add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'leezy_action_links' ); function leezy_action_links( $links ) { $settings_link = '' . __( 'Settings', 'leezy' ) . ''; array_unshift( $links, $settings_link ); return $links; } // Admin notice if Bot ID not configured. add_action( 'admin_notices', 'leezy_admin_notice' ); function leezy_admin_notice() { $bot_id = leezy_get_option( 'bot_id' ); if ( ! empty( $bot_id ) ) { return; } $screen = get_current_screen(); if ( $screen && 'toplevel_page_leezy' === $screen->id ) { return; } echo '

'; printf( /* translators: %s: link to settings page */ esc_html__( 'Leezy AI Chatbot is active but not configured. %s to connect your chatbot.', 'leezy' ), '' . esc_html__( 'Go to Settings', 'leezy' ) . '' ); echo '

'; } /* ────────────────────────────────────────────── * Uninstall: Clean up options * ────────────────────────────────────────────── */ register_uninstall_hook( __FILE__, 'leezy_uninstall' ); function leezy_uninstall() { delete_option( 'leezy_options' ); }