settings.php
1 <?php 2 /** 3 * Settings page view. 4 * 5 * @package RESTai 6 */ 7 8 if ( ! defined( 'ABSPATH' ) ) { 9 exit; 10 } 11 12 $settings = get_option( 'restai_settings', array() ); 13 $widget = get_option( 'restai_widget_settings', array() ); 14 $map = get_option( 'restai_project_map', array() ); 15 $tasks = \RESTai\Provisioner::definitions(); 16 $connected = \RESTai\Plugin::is_connected(); 17 ?> 18 <div class="wrap restai-settings"> 19 <h1><?php esc_html_e( 'RESTai for WordPress', 'restai' ); ?></h1> 20 21 <?php settings_errors( 'restai_settings_group' ); ?> 22 23 <form method="post" action="options.php" id="restai-settings-form"> 24 <?php settings_fields( 'restai_settings_group' ); ?> 25 26 <h2 class="title"><?php esc_html_e( 'Connection', 'restai' ); ?></h2> 27 <table class="form-table" role="presentation"> 28 <tr> 29 <th scope="row"><label for="restai_url"><?php esc_html_e( 'RESTai URL', 'restai' ); ?></label></th> 30 <td> 31 <input type="url" id="restai_url" name="restai_settings[url]" class="regular-text" placeholder="https://your-restai.example.com" value="<?php echo esc_attr( isset( $settings['url'] ) ? $settings['url'] : '' ); ?>" /> 32 <p class="description"><?php esc_html_e( 'Base URL of your RESTai instance.', 'restai' ); ?></p> 33 </td> 34 </tr> 35 <tr> 36 <th scope="row"><label for="restai_api_key"><?php esc_html_e( 'API Key', 'restai' ); ?></label></th> 37 <td> 38 <input type="password" id="restai_api_key" name="restai_settings[api_key]" class="regular-text" autocomplete="off" value="<?php echo esc_attr( isset( $settings['api_key'] ) ? $settings['api_key'] : '' ); ?>" /> 39 <button type="button" class="button" id="restai-test-connection"><?php esc_html_e( 'Test connection', 'restai' ); ?></button> 40 <span id="restai-connection-status" style="margin-left:8px;"></span> 41 <p class="description"><?php esc_html_e( 'Create one in RESTai under Profile → API Keys.', 'restai' ); ?></p> 42 </td> 43 </tr> 44 <tr> 45 <th scope="row"><label for="restai_team_id"><?php esc_html_e( 'Team', 'restai' ); ?></label></th> 46 <td> 47 <select id="restai_team_id" name="restai_settings[team_id]" data-current="<?php echo esc_attr( isset( $settings['team_id'] ) ? $settings['team_id'] : '' ); ?>"> 48 <option value=""><?php esc_html_e( '— select a team —', 'restai' ); ?></option> 49 <?php if ( ! empty( $settings['team_id'] ) ) : ?> 50 <option value="<?php echo esc_attr( $settings['team_id'] ); ?>" selected><?php echo esc_html( sprintf( __( 'Team #%d', 'restai' ), $settings['team_id'] ) ); ?></option> 51 <?php endif; ?> 52 </select> 53 <p class="description"><?php esc_html_e( 'Projects auto-provisioned by the plugin will be created in this team. Test the connection first to load the list.', 'restai' ); ?></p> 54 </td> 55 </tr> 56 </table> 57 58 <h2 class="title"><?php esc_html_e( 'Features', 'restai' ); ?></h2> 59 <table class="form-table" role="presentation"> 60 <?php 61 $feature_rows = array( 62 'enable_widget' => array( __( 'Embed chat widget', 'restai' ), __( 'Add the RESTai chat bubble to public pages.', 'restai' ) ), 63 'enable_search' => array( __( 'AI site search', 'restai' ), __( 'Replace native WordPress search with semantic search via the Support Bot project.', 'restai' ) ), 64 'enable_knowledge' => array( __( 'Knowledge sync', 'restai' ), __( 'Push every published post and page into the Support Bot RAG project, so the bot is always current.', 'restai' ) ), 65 'enable_moderation' => array( __( 'AI comment moderation', 'restai' ), __( 'Auto-flag spam and toxic comments; suggest replies for moderators.', 'restai' ) ), 66 'enable_email_ai' => array( __( 'AI email personalization', 'restai' ), __( 'Personalize transactional emails (welcome, password reset…) using the Email Personalizer project.', 'restai' ) ), 67 'auto_alt_text' => array( __( 'Auto alt text on uploads', 'restai' ), __( 'Generate alt text for newly uploaded images using a vision model.', 'restai' ) ), 68 ); 69 foreach ( $feature_rows as $key => $row ) : 70 $checked = ! empty( $settings[ $key ] ); 71 ?> 72 <tr> 73 <th scope="row"><?php echo esc_html( $row[0] ); ?></th> 74 <td> 75 <label> 76 <input type="checkbox" name="restai_settings[<?php echo esc_attr( $key ); ?>]" value="1" <?php checked( $checked ); ?> /> 77 <?php echo esc_html( $row[1] ); ?> 78 </label> 79 </td> 80 </tr> 81 <?php endforeach; ?> 82 <tr> 83 <th scope="row"><label for="restai_image_generator"><?php esc_html_e( 'Image generator', 'restai' ); ?></label></th> 84 <td> 85 <?php $current_gen = isset( $settings['image_generator'] ) ? $settings['image_generator'] : ''; ?> 86 <select id="restai_image_generator" name="restai_settings[image_generator]" data-current="<?php echo esc_attr( $current_gen ); ?>"> 87 <option value=""><?php esc_html_e( 'Auto (first available in team)', 'restai' ); ?></option> 88 <?php if ( ! empty( $current_gen ) ) : ?> 89 <option value="<?php echo esc_attr( $current_gen ); ?>" selected><?php echo esc_html( $current_gen ); ?></option> 90 <?php endif; ?> 91 </select> 92 <p class="description"><?php esc_html_e( 'Used for featured-image generation. The list is loaded from the selected team after testing the connection.', 'restai' ); ?></p> 93 </td> 94 </tr> 95 </table> 96 97 <h2 class="title"><?php esc_html_e( 'Task → Project mapping', 'restai' ); ?></h2> 98 <p> 99 <?php esc_html_e( 'Each plugin task is handled by one RESTai project. Click below to auto-create starter projects, or pick existing ones from the dropdowns.', 'restai' ); ?> 100 </p> 101 <p> 102 <button type="button" class="button button-secondary" id="restai-provision" <?php disabled( ! $connected ); ?>> 103 <?php esc_html_e( 'Auto-provision starter projects', 'restai' ); ?> 104 </button> 105 <span id="restai-provision-status" style="margin-left:8px;"></span> 106 </p> 107 108 <table class="form-table" role="presentation"> 109 <?php foreach ( $tasks as $task_key => $task ) : ?> 110 <tr> 111 <th scope="row"><?php echo esc_html( $task['label'] ); ?></th> 112 <td> 113 <select name="restai_project_map[<?php echo esc_attr( $task_key ); ?>]" data-task="<?php echo esc_attr( $task_key ); ?>" class="restai-project-select"> 114 <option value=""><?php esc_html_e( '— not configured —', 'restai' ); ?></option> 115 <?php if ( ! empty( $map[ $task_key ] ) ) : ?> 116 <option value="<?php echo esc_attr( $map[ $task_key ] ); ?>" selected><?php echo esc_html( sprintf( __( 'Project #%s', 'restai' ), $map[ $task_key ] ) ); ?></option> 117 <?php endif; ?> 118 </select> 119 <p class="description"><?php echo esc_html( $task['name'] ); ?> · <?php echo esc_html( strtoupper( $task['type'] ) ); ?></p> 120 </td> 121 </tr> 122 <?php endforeach; ?> 123 </table> 124 125 <h2 class="title"><?php esc_html_e( 'Chat widget', 'restai' ); ?></h2> 126 <table class="form-table" role="presentation"> 127 <tr> 128 <th scope="row"><label for="restai_widget_title"><?php esc_html_e( 'Widget title', 'restai' ); ?></label></th> 129 <td><input type="text" id="restai_widget_title" name="restai_widget_settings[title]" class="regular-text" value="<?php echo esc_attr( isset( $widget['title'] ) ? $widget['title'] : 'Chat with us' ); ?>" /></td> 130 </tr> 131 <tr> 132 <th scope="row"><label for="restai_widget_color"><?php esc_html_e( 'Primary color', 'restai' ); ?></label></th> 133 <td><input type="color" id="restai_widget_color" name="restai_widget_settings[color]" value="<?php echo esc_attr( isset( $widget['color'] ) ? $widget['color'] : '#6366f1' ); ?>" /></td> 134 </tr> 135 <tr> 136 <th scope="row"><label for="restai_widget_welcome"><?php esc_html_e( 'Welcome message', 'restai' ); ?></label></th> 137 <td><input type="text" id="restai_widget_welcome" name="restai_widget_settings[welcome]" class="regular-text" value="<?php echo esc_attr( isset( $widget['welcome'] ) ? $widget['welcome'] : __( 'Hi! How can I help?', 'restai' ) ); ?>" /></td> 138 </tr> 139 </table> 140 141 <?php submit_button(); ?> 142 </form> 143 </div>