'', ); } /** * Get a single option value. */ function leezy_get_option( $key ) { $options = get_option( 'leezy_options', array() ); $options = is_array( $options ) ? $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', 'ai-chatbot' ), __( 'Leezy', 'ai-chatbot' ), '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', 'ai-chatbot' ), 'leezy_section_main_cb', 'leezy' ); $fields = array( 'bot_id' => array( 'label' => __( 'Chatbot ID', 'ai-chatbot' ), 'cb' => 'leezy_field_bot_id' ), ); 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(); if ( ! is_array( $input ) ) { return $clean; } $clean['bot_id'] = isset( $input['bot_id'] ) ? sanitize_text_field( $input['bot_id'] ) : ''; return $clean; } /* ── Section Callback ─────────────────────── */ function leezy_section_main_cb() { echo '
' . esc_html__( 'Connect your Leezy chatbot. Find your Chatbot ID in the Leezy dashboard, then paste it here. Widget behavior and appearance are managed in Leezy.', 'ai-chatbot' ) . '
'; } /* ── 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.', 'ai-chatbot' ) . '
'; } /* ── Settings Page ────────────────────────── */ function leezy_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?> ' . __( 'Settings', 'ai-chatbot' ) . ''; array_unshift( $links, $settings_link ); return $links; } // Admin notice if Chatbot ID is 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 no Chatbot ID is configured. %s to connect your chatbot.', 'ai-chatbot' ), '' . esc_html__( 'Go to Settings', 'ai-chatbot' ) . '' ); echo '