| 1 |
<?php |
| 2 |
/** |
| 3 |
* AI Settings page - V3 Premium style 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 |
<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); ?>"> |
| 212 |
<span class="ka-v3-segmented-indicator" aria-hidden="true"></span> |
| 213 |
<button type="button" class="ka-v3-segmented-btn" data-theme="light" aria-pressed="<?php echo $theme_mode === 'light' ? 'true' : 'false'; ?>"> |
| 214 |
<span class="ka-v3-segmented-icon" aria-hidden="true">☀︎</span> |
| 215 |
<?php esc_html_e('Light', 'king-addons'); ?> |
| 216 |
</button> |
| 217 |
<button type="button" class="ka-v3-segmented-btn" data-theme="dark" aria-pressed="<?php echo $theme_mode === 'dark' ? 'true' : 'false'; ?>"> |
| 218 |
<span class="ka-v3-segmented-icon" aria-hidden="true">☾</span> |
| 219 |
<?php esc_html_e('Dark', 'king-addons'); ?> |
| 220 |
</button> |
| 221 |
<button type="button" class="ka-v3-segmented-btn" data-theme="auto" aria-pressed="<?php echo $theme_mode === 'auto' ? 'true' : 'false'; ?>"> |
| 222 |
<span class="ka-v3-segmented-icon" aria-hidden="true">◐</span> |
| 223 |
<?php esc_html_e('Auto', 'king-addons'); ?> |
| 224 |
</button> |
| 225 |
</div> |
| 226 |
<a href="https://platform.openai.com/usage" target="_blank" class="ka-btn ka-btn-secondary"> |
| 227 |
<span class="dashicons dashicons-external"></span> |
| 228 |
<?php esc_html_e('OpenAI Dashboard', 'king-addons'); ?> |
| 229 |
</a> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
|
| 233 |
<!-- Info Card --> |
| 234 |
<div class="ka-card"> |
| 235 |
<div class="ka-card-header"> |
| 236 |
<span class="dashicons dashicons-info" style="color: #0071e3;"></span> |
| 237 |
<h3><?php esc_html_e('How to use AI features', 'king-addons'); ?></h3> |
| 238 |
</div> |
| 239 |
<div class="ka-card-body"> |
| 240 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 24px;"> |
| 241 |
<div> |
| 242 |
<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> |
| 243 |
<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> |
| 244 |
</div> |
| 245 |
<div> |
| 246 |
<h4 style="margin: 0 0 8px; font-size: 15px; font-weight: 600; color: inherit;">2. <?php esc_html_e('Enter Key Below', 'king-addons'); ?></h4> |
| 247 |
<p class="ka-row-desc" style="margin: 0;"><?php esc_html_e('Paste your API key in the field below and select your preferred model.', 'king-addons'); ?></p> |
| 248 |
</div> |
| 249 |
<div> |
| 250 |
<h4 style="margin: 0 0 8px; font-size: 15px; font-weight: 600; color: inherit;">3. <?php esc_html_e('Use', 'king-addons'); ?></h4> |
| 251 |
<p class="ka-row-desc" style="margin: 0;"><?php esc_html_e('AI features will be available in the Elementor editor, widgets, and other supported areas.', 'king-addons'); ?></p> |
| 252 |
</div> |
| 253 |
</div> |
| 254 |
</div> |
| 255 |
</div> |
| 256 |
|
| 257 |
<!-- Settings Form --> |
| 258 |
<div class="ka-card"> |
| 259 |
<div class="ka-card-header"> |
| 260 |
<span class="dashicons dashicons-admin-settings" style="color: #8b5cf6;"></span> |
| 261 |
<h2><?php esc_html_e('AI Configuration', 'king-addons'); ?></h2> |
| 262 |
</div> |
| 263 |
<div class="ka-card-body"> |
| 264 |
<form method="post" action="options.php"> |
| 265 |
<?php |
| 266 |
settings_fields('king_addons_ai'); |
| 267 |
do_settings_sections('king-addons-ai-settings'); |
| 268 |
?> |
| 269 |
|
| 270 |
<div style="margin-top: 24px; padding-top: 24px; border-top: 1px solid rgba(0,0,0,0.04);"> |
| 271 |
<button type="submit" class="ka-btn ka-btn-primary"> |
| 272 |
<?php esc_html_e('Save Settings', 'king-addons'); ?> |
| 273 |
</button> |
| 274 |
</div> |
| 275 |
</form> |
| 276 |
</div> |
| 277 |
</div> |
| 278 |
|
| 279 |
</div> |
| 280 |
|
| 281 |
<script> |
| 282 |
// Dashboard-style segmented theme control |
| 283 |
(function() { |
| 284 |
const segment = document.getElementById('ka-v3-theme-segment'); |
| 285 |
if (!segment) { |
| 286 |
return; |
| 287 |
} |
| 288 |
|
| 289 |
const ajaxUrl = '<?php echo esc_url(admin_url('admin-ajax.php')); ?>'; |
| 290 |
const nonce = '<?php echo esc_js(wp_create_nonce('king_addons_dashboard_ui')); ?>'; |
| 291 |
const buttons = segment.querySelectorAll('.ka-v3-segmented-btn'); |
| 292 |
|
| 293 |
const mql = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null; |
| 294 |
let mode = (segment.getAttribute('data-active') || 'dark').toString(); |
| 295 |
let mqlHandler = null; |
| 296 |
|
| 297 |
function setPressedState(activeMode) { |
| 298 |
segment.setAttribute('data-active', activeMode); |
| 299 |
buttons.forEach((btn) => { |
| 300 |
const theme = btn.getAttribute('data-theme'); |
| 301 |
btn.setAttribute('aria-pressed', theme === activeMode ? 'true' : 'false'); |
| 302 |
}); |
| 303 |
} |
| 304 |
|
| 305 |
function saveUISetting(key, value) { |
| 306 |
try { |
| 307 |
const body = new URLSearchParams(); |
| 308 |
body.set('action', 'king_addons_save_dashboard_ui'); |
| 309 |
body.set('nonce', nonce); |
| 310 |
body.set('key', key); |
| 311 |
body.set('value', value); |
| 312 |
|
| 313 |
fetch(ajaxUrl, { |
| 314 |
method: 'POST', |
| 315 |
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, |
| 316 |
body: body.toString(), |
| 317 |
credentials: 'same-origin' |
| 318 |
}); |
| 319 |
} catch (e) {} |
| 320 |
} |
| 321 |
|
| 322 |
function applyTheme(isDark) { |
| 323 |
document.body.classList.toggle('ka-v3-dark', isDark); |
| 324 |
document.documentElement.classList.toggle('ka-v3-dark', isDark); |
| 325 |
} |
| 326 |
|
| 327 |
function setThemeMode(nextMode, save) { |
| 328 |
mode = nextMode; |
| 329 |
setPressedState(nextMode); |
| 330 |
|
| 331 |
if (mqlHandler && mql) { |
| 332 |
if (mql.removeEventListener) { |
| 333 |
mql.removeEventListener('change', mqlHandler); |
| 334 |
} else if (mql.removeListener) { |
| 335 |
mql.removeListener(mqlHandler); |
| 336 |
} |
| 337 |
mqlHandler = null; |
| 338 |
} |
| 339 |
|
| 340 |
if (nextMode === 'auto') { |
| 341 |
applyTheme(!!(mql && mql.matches)); |
| 342 |
mqlHandler = (e) => { |
| 343 |
if (mode !== 'auto') { |
| 344 |
return; |
| 345 |
} |
| 346 |
applyTheme(!!e.matches); |
| 347 |
}; |
| 348 |
if (mql) { |
| 349 |
if (mql.addEventListener) { |
| 350 |
mql.addEventListener('change', mqlHandler); |
| 351 |
} else if (mql.addListener) { |
| 352 |
mql.addListener(mqlHandler); |
| 353 |
} |
| 354 |
} |
| 355 |
} else { |
| 356 |
applyTheme(nextMode === 'dark'); |
| 357 |
} |
| 358 |
|
| 359 |
if (save) { |
| 360 |
saveUISetting('theme_mode', nextMode); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
segment.addEventListener('click', (e) => { |
| 365 |
const btn = e.target && e.target.closest ? e.target.closest('.ka-v3-segmented-btn') : null; |
| 366 |
if (!btn) { |
| 367 |
return; |
| 368 |
} |
| 369 |
e.preventDefault(); |
| 370 |
const theme = (btn.getAttribute('data-theme') || 'dark').toString(); |
| 371 |
setThemeMode(theme, true); |
| 372 |
}); |
| 373 |
|
| 374 |
// Ensure mode applies for Auto (listener + system state) |
| 375 |
setThemeMode(mode, false); |
| 376 |
})(); |
| 377 |
</script> |
| 378 |
|