PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.44
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.44
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / admin / layouts / ai-settings-page.php

ai-settings-page.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.44, at includes/admin/layouts/ai-settings-page.php

376 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AI Settings page - V3 Apple-inspired Design.
4 *
5 * @package King_Addons
6 */
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 // Theme mode is per-user
13 $theme_mode = get_user_meta(get_current_user_id(), 'king_addons_theme_mode', true);
14 $allowed_theme_modes = ['dark', 'light', 'auto'];
15 if (!in_array($theme_mode, $allowed_theme_modes, true)) {
16 $theme_mode = 'dark';
17 }
18
19 // Enqueue shared V3 styles
20 wp_enqueue_style(
21 'king-addons-admin-v3',
22 KING_ADDONS_URL . 'includes/admin/layouts/shared/admin-v3-styles.css',
23 [],
24 KING_ADDONS_VERSION
25 );
26 ?>
27 <script>
28 (function() {
29 document.body.classList.add('ka-admin-v3');
30
31 const mode = '<?php echo esc_js($theme_mode); ?>';
32 const mql = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
33 const isDark = mode === 'auto' ? !!(mql && mql.matches) : mode === 'dark';
34
35 document.documentElement.classList.toggle('ka-v3-dark', isDark);
36 document.body.classList.toggle('ka-v3-dark', isDark);
37 })();
38 </script>
39
40 <style>
41 /* AI Settings V3 */
42 .ka-ai-settings .form-table {
43 margin: 0;
44 width: 100%;
45 }
46
47 .ka-ai-settings .form-table th,
48 .ka-ai-settings .form-table td {
49 padding: 18px 0;
50 border-bottom: 1px solid rgba(0, 0, 0, 0.04);
51 vertical-align: top;
52 }
53
54 body.ka-v3-dark .ka-ai-settings .form-table th,
55 body.ka-v3-dark .ka-ai-settings .form-table td {
56 border-bottom-color: rgba(255, 255, 255, 0.04);
57 }
58
59 .ka-ai-settings .form-table tr:last-child th,
60 .ka-ai-settings .form-table tr:last-child td {
61 border-bottom: none;
62 }
63
64 .ka-ai-settings .form-table th {
65 width: 200px;
66 font-size: 15px;
67 font-weight: 500;
68 color: #1d1d1f;
69 padding-right: 20px;
70 }
71
72 body.ka-v3-dark .ka-ai-settings .form-table th {
73 color: #f5f5f7;
74 }
75
76 .ka-ai-settings .form-table td {
77 color: #1d1d1f;
78 }
79
80 body.ka-v3-dark .ka-ai-settings .form-table td {
81 color: #f5f5f7;
82 }
83
84 .ka-ai-settings input[type="text"],
85 .ka-ai-settings input[type="password"],
86 .ka-ai-settings input[type="number"],
87 .ka-ai-settings textarea,
88 .ka-ai-settings select {
89 width: 100%;
90 max-width: 400px;
91 padding: 12px 16px;
92 border: 1px solid rgba(0, 0, 0, 0.1);
93 border-radius: 12px;
94 font-size: 15px;
95 font-family: inherit;
96 background: #fff;
97 transition: border-color 0.2s, box-shadow 0.2s;
98 }
99
100 body.ka-v3-dark .ka-ai-settings input[type="text"],
101 body.ka-v3-dark .ka-ai-settings input[type="password"],
102 body.ka-v3-dark .ka-ai-settings input[type="number"],
103 body.ka-v3-dark .ka-ai-settings textarea,
104 body.ka-v3-dark .ka-ai-settings select {
105 background: #2c2c2e;
106 border-color: rgba(255, 255, 255, 0.1);
107 color: #f5f5f7;
108 }
109
110 .ka-ai-settings input:focus,
111 .ka-ai-settings textarea:focus,
112 .ka-ai-settings select:focus {
113 outline: none;
114 border-color: #8b5cf6;
115 box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
116 }
117
118 body.ka-v3-dark .ka-ai-settings input:focus,
119 body.ka-v3-dark .ka-ai-settings textarea:focus,
120 body.ka-v3-dark .ka-ai-settings select:focus {
121 border-color: #a78bfa;
122 box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2);
123 }
124
125 .ka-ai-settings .description {
126 font-size: 13px;
127 color: #86868b;
128 margin-top: 8px;
129 line-height: 1.5;
130 }
131
132 .ka-ai-settings select {
133 -webkit-appearance: none;
134 -moz-appearance: none;
135 appearance: none;
136 background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3e%3cpath fill='%2386868b' d='M6 8L0 0h12z'/%3e%3c/svg%3e");
137 background-repeat: no-repeat;
138 background-position: right 16px center;
139 background-size: 10px 6px;
140 padding-right: 44px;
141 }
142
143 /* Section titles */
144 .ka-ai-settings .ka-card-body h2 {
145 font-size: 17px;
146 font-weight: 600;
147 color: #1d1d1f;
148 margin: 24px 0 8px 0;
149 padding: 24px 0 0 0;
150 border-top: 1px solid rgba(0, 0, 0, 0.04);
151 }
152
153 body.ka-v3-dark .ka-ai-settings .ka-card-body h2 {
154 color: #f5f5f7;
155 border-top-color: rgba(255, 255, 255, 0.04);
156 }
157
158 .ka-ai-settings .ka-card-body h2:first-of-type {
159 margin-top: 0;
160 padding-top: 0;
161 border-top: none;
162 }
163
164 .ka-ai-settings .ka-card-body h2 + p {
165 color: #86868b;
166 font-size: 14px;
167 margin: 0 0 16px 0;
168 }
169
170 /* Button styles */
171 .ka-ai-settings .button {
172 padding: 10px 20px;
173 border-radius: 980px;
174 font-size: 14px;
175 font-weight: 400;
176 background: rgba(0, 0, 0, 0.06);
177 border: none;
178 color: #1d1d1f;
179 cursor: pointer;
180 transition: all 0.2s;
181 }
182
183 body.ka-v3-dark .ka-ai-settings .button {
184 background: rgba(255, 255, 255, 0.1);
185 color: #f5f5f7;
186 }
187
188 .ka-ai-settings .button:hover {
189 background: rgba(0, 0, 0, 0.1);
190 }
191
192 body.ka-v3-dark .ka-ai-settings .button:hover {
193 background: rgba(255, 255, 255, 0.15);
194 }
195 </style>
196
197 <div class="ka-admin-wrap ka-ai-settings">
198 <?php settings_errors('king_addons_ai'); ?>
199 <!-- Header -->
200 <div class="ka-admin-header">
201 <div class="ka-admin-header-left">
202 <div class="ka-admin-header-icon purple">
203 <span class="dashicons dashicons-admin-generic"></span>
204 </div>
205 <div>
206 <h1 class="ka-admin-title"><?php esc_html_e('AI Settings', 'king-addons'); ?></h1>
207 <p class="ka-admin-subtitle"><?php esc_html_e('Configure OpenAI integration and AI features for Elementor editor', 'king-addons'); ?></p>
208 </div>
209 </div>
210 <div class="ka-admin-header-actions">
211 <a href="https://platform.openai.com/usage" target="_blank" class="ka-btn ka-btn-secondary">
212 <span class="dashicons dashicons-external"></span>
213 <?php esc_html_e('OpenAI Dashboard', 'king-addons'); ?>
214 </a>
215 <div class="ka-v3-segmented" id="ka-v3-theme-segment" role="radiogroup" aria-label="<?php echo esc_attr(esc_html__('Theme', 'king-addons')); ?>" data-active="<?php echo esc_attr($theme_mode); ?>">
216 <span class="ka-v3-segmented-indicator" aria-hidden="true"></span>
217 <button type="button" class="ka-v3-segmented-btn" data-theme="light" aria-pressed="<?php echo $theme_mode === 'light' ? 'true' : 'false'; ?>">
218 <span class="ka-v3-segmented-icon" aria-hidden="true">☀︎</span>
219 <?php esc_html_e('Light', 'king-addons'); ?>
220 </button>
221 <button type="button" class="ka-v3-segmented-btn" data-theme="dark" aria-pressed="<?php echo $theme_mode === 'dark' ? 'true' : 'false'; ?>">
222 <span class="ka-v3-segmented-icon" aria-hidden="true">☾</span>
223 <?php esc_html_e('Dark', 'king-addons'); ?>
224 </button>
225 <button type="button" class="ka-v3-segmented-btn" data-theme="auto" aria-pressed="<?php echo $theme_mode === 'auto' ? 'true' : 'false'; ?>">
226 <?php esc_html_e('Auto', 'king-addons'); ?>
227 </button>
228 </div>
229 </div>
230 </div>
231
232 <!-- Settings Form -->
233 <div class="ka-card">
234 <div class="ka-card-header">
235 <span class="dashicons dashicons-admin-settings" style="color: #8b5cf6;"></span>
236 <h2><?php esc_html_e('AI Configuration', 'king-addons'); ?></h2>
237 </div>
238 <div class="ka-card-body">
239 <form method="post" action="options.php">
240 <?php
241 settings_fields('king_addons_ai');
242 do_settings_sections('king-addons-ai-settings');
243 ?>
244
245 <div style="margin-top: 24px; padding-top: 24px; border-top: 1px solid rgba(0,0,0,0.04);">
246 <button type="submit" class="ka-btn ka-btn-primary">
247 <?php esc_html_e('Save Settings', 'king-addons'); ?>
248 </button>
249 </div>
250 </form>
251 </div>
252 </div>
253
254 <!-- Info Card -->
255 <div class="ka-card">
256 <div class="ka-card-header">
257 <span class="dashicons dashicons-info" style="color: #0071e3;"></span>
258 <h3><?php esc_html_e('How to use AI features', 'king-addons'); ?></h3>
259 </div>
260 <div class="ka-card-body">
261 <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 24px;">
262 <div>
263 <h4 style="margin: 0 0 8px; font-size: 15px; font-weight: 600; color: inherit;">1. <?php esc_html_e('Get API Key', 'king-addons'); ?></h4>
264 <p class="ka-row-desc" style="margin: 0;"><?php esc_html_e('Create an account at OpenAI and generate an API key from the dashboard.', 'king-addons'); ?></p>
265 </div>
266 <div>
267 <h4 style="margin: 0 0 8px; font-size: 15px; font-weight: 600; color: inherit;">2. <?php esc_html_e('Enter Key Above', 'king-addons'); ?></h4>
268 <p class="ka-row-desc" style="margin: 0;"><?php esc_html_e('Paste your API key in the field above and select your preferred model.', 'king-addons'); ?></p>
269 </div>
270 <div>
271 <h4 style="margin: 0 0 8px; font-size: 15px; font-weight: 600; color: inherit;">3. <?php esc_html_e('Use in Editor', 'king-addons'); ?></h4>
272 <p class="ka-row-desc" style="margin: 0;"><?php esc_html_e('AI features will be available in the Elementor editor widgets.', 'king-addons'); ?></p>
273 </div>
274 </div>
275 </div>
276 </div>
277 </div>
278
279 <script>
280 // Dashboard-style segmented theme control
281 (function() {
282 const segment = document.getElementById('ka-v3-theme-segment');
283 if (!segment) {
284 return;
285 }
286
287 const ajaxUrl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>';
288 const nonce = '<?php echo esc_js(wp_create_nonce('king_addons_dashboard_ui')); ?>';
289 const buttons = segment.querySelectorAll('.ka-v3-segmented-btn');
290
291 const mql = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null;
292 let mode = (segment.getAttribute('data-active') || 'dark').toString();
293 let mqlHandler = null;
294
295 function setPressedState(activeMode) {
296 segment.setAttribute('data-active', activeMode);
297 buttons.forEach((btn) => {
298 const theme = btn.getAttribute('data-theme');
299 btn.setAttribute('aria-pressed', theme === activeMode ? 'true' : 'false');
300 });
301 }
302
303 function saveUISetting(key, value) {
304 try {
305 const body = new URLSearchParams();
306 body.set('action', 'king_addons_save_dashboard_ui');
307 body.set('nonce', nonce);
308 body.set('key', key);
309 body.set('value', value);
310
311 fetch(ajaxUrl, {
312 method: 'POST',
313 headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
314 body: body.toString(),
315 credentials: 'same-origin'
316 });
317 } catch (e) {}
318 }
319
320 function applyTheme(isDark) {
321 document.body.classList.toggle('ka-v3-dark', isDark);
322 document.documentElement.classList.toggle('ka-v3-dark', isDark);
323 }
324
325 function setThemeMode(nextMode, save) {
326 mode = nextMode;
327 setPressedState(nextMode);
328
329 if (mqlHandler && mql) {
330 if (mql.removeEventListener) {
331 mql.removeEventListener('change', mqlHandler);
332 } else if (mql.removeListener) {
333 mql.removeListener(mqlHandler);
334 }
335 mqlHandler = null;
336 }
337
338 if (nextMode === 'auto') {
339 applyTheme(!!(mql && mql.matches));
340 mqlHandler = (e) => {
341 if (mode !== 'auto') {
342 return;
343 }
344 applyTheme(!!e.matches);
345 };
346 if (mql) {
347 if (mql.addEventListener) {
348 mql.addEventListener('change', mqlHandler);
349 } else if (mql.addListener) {
350 mql.addListener(mqlHandler);
351 }
352 }
353 } else {
354 applyTheme(nextMode === 'dark');
355 }
356
357 if (save) {
358 saveUISetting('theme_mode', nextMode);
359 }
360 }
361
362 segment.addEventListener('click', (e) => {
363 const btn = e.target && e.target.closest ? e.target.closest('.ka-v3-segmented-btn') : null;
364 if (!btn) {
365 return;
366 }
367 e.preventDefault();
368 const theme = (btn.getAttribute('data-theme') || 'dark').toString();
369 setThemeMode(theme, true);
370 });
371
372 // Ensure mode applies for Auto (listener + system state)
373 setThemeMode(mode, false);
374 })();
375 </script>
376