| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Control class for Control options. |
| 5 |
* |
| 6 |
* @link https://themeatelier.net |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package darkify |
| 10 |
* @subpackage darkify/src/Admin/Views/Control |
| 11 |
* @author ThemeAtelier<themeatelierbd@gmail.com> |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace ThemeAtelier\Darkify\Admin\Views; |
| 15 |
|
| 16 |
use ThemeAtelier\Darkify\Admin\Schema\SchemaRegistry as Darkify; |
| 17 |
|
| 18 |
class Control |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Create Option fields for the setting options. |
| 22 |
* |
| 23 |
* @param string $prefix Option setting key prefix. |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public static function options($prefix) |
| 27 |
{ |
| 28 |
Darkify::createSection( |
| 29 |
$prefix, |
| 30 |
array( |
| 31 |
// Explicit, locale-independent id. Without it the REST layer falls |
| 32 |
// back to sanitize_title() of the *translated* title, so the route |
| 33 |
// became #/sterowanie on a Polish site and every link 404'd inside |
| 34 |
// the SPA. Value matches the old English slug so existing |
| 35 |
// `#tab=` / `#/controls` bookmarks keep resolving. |
| 36 |
'id' => 'controls', |
| 37 |
'title' => esc_html__('Controls', 'darkify'), |
| 38 |
'icon' => 'icofont-ui-settings', |
| 39 |
'fields' => array( |
| 40 |
array( |
| 41 |
'type' => 'section_tab', |
| 42 |
'tabs' => array( |
| 43 |
|
| 44 |
array( |
| 45 |
'id' => 'frontend', |
| 46 |
'title' => esc_html__('Frontend', 'darkify'), |
| 47 |
'icon' => 'icofont-computer', |
| 48 |
'fields' => array( |
| 49 |
// Intro line with a docs link, rendered plain above the section cards. |
| 50 |
array( |
| 51 |
'type' => 'page_hint', |
| 52 |
'content' => sprintf( |
| 53 |
/* translators: %s: documentation link */ |
| 54 |
__('Decide how and when dark mode turns on for visitors on your public website. %s', 'darkify'), |
| 55 |
'<a href="https://darkifywp.com/docs/" target="_blank" rel="noopener noreferrer">' . esc_html__('View documentation', 'darkify') . '</a>' |
| 56 |
), |
| 57 |
), |
| 58 |
|
| 59 |
// ===== AVAILABILITY ===== |
| 60 |
array( |
| 61 |
'type' => 'heading', |
| 62 |
'title' => esc_html__('Availability', 'darkify'), |
| 63 |
'section_start' => true, |
| 64 |
), |
| 65 |
array( |
| 66 |
'id' => 'enable_dark_mode_switch', |
| 67 |
'type' => 'switcher', |
| 68 |
'title' => esc_html__('Frontend Dark Mode', 'darkify'), |
| 69 |
'title_help' => '<div class="darkify-info-label">' . |
| 70 |
__('Show the dark mode floating switch on your website frontend. This is the master control for everything below.', 'darkify') . |
| 71 |
'</div>' . '' . '', |
| 72 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 73 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 74 |
'text_width' => 100, |
| 75 |
'default' => true, |
| 76 |
// Commit instantly (master toggle governs the whole frontend feature). |
| 77 |
'auto_save' => true, |
| 78 |
), |
| 79 |
array( |
| 80 |
'id' => 'enable_default_dark_mode', |
| 81 |
'type' => 'switcher', |
| 82 |
'title' => esc_html__('Default Dark Mode', 'darkify'), |
| 83 |
'title_help' => |
| 84 |
'<div class="darkify-info-label">' . |
| 85 |
__('Enable dark mode by default on your website.', 'darkify') . |
| 86 |
'</div>' . |
| 87 |
'' . |
| 88 |
'', |
| 89 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 90 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 91 |
'text_width' => 100, |
| 92 |
// Commit instantly (the priority notice depends on it, which would |
| 93 |
// otherwise force the manual-Save workflow). |
| 94 |
'auto_save' => true, |
| 95 |
), |
| 96 |
array( |
| 97 |
'id' => 'enable_os_aware', |
| 98 |
'type' => 'switcher', |
| 99 |
'title' => esc_html__('OS Aware Dark Mode', 'darkify'), |
| 100 |
'title_help' => |
| 101 |
'<div class="darkify-info-label">' . |
| 102 |
__('Toggle dark mode based on the user’s device or operating system preference.', 'darkify') . |
| 103 |
'</div>' . |
| 104 |
'' . |
| 105 |
'', |
| 106 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 107 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 108 |
'text_width' => 100, |
| 109 |
'default' => true, |
| 110 |
// Commit instantly (the priority notice depends on it). |
| 111 |
'auto_save' => true, |
| 112 |
), |
| 113 |
// Priority notice: shown only when Default Dark Mode AND OS Aware are both on. |
| 114 |
array( |
| 115 |
'type' => 'submessage', |
| 116 |
'style' => 'info', |
| 117 |
'content' => '<strong>' . esc_html__('OS Aware takes priority.', 'darkify') . '</strong> ' . esc_html__('Both are on, so visitors following the system “dark” setting get dark mode automatically; Default Dark Mode applies only when no system preference is detected.', 'darkify'), |
| 118 |
'dependency' => array('enable_default_dark_mode|enable_os_aware', '==|==', 'true|true'), |
| 119 |
), |
| 120 |
|
| 121 |
// ===== ACTIVATION ===== |
| 122 |
array( |
| 123 |
'type' => 'heading', |
| 124 |
'title' => esc_html__('Activation', 'darkify'), |
| 125 |
'section_start' => true, |
| 126 |
), |
| 127 |
array( |
| 128 |
'id' => 'enable_keyboard_shortcut', |
| 129 |
'type' => 'switcher', |
| 130 |
'title' => esc_html__('Keyboard Shortcut', 'darkify'), |
| 131 |
'title_help' => |
| 132 |
'<div class="darkify-info-label">' . |
| 133 |
__('Let visitors toggle dark mode with a keyboard shortcut.', 'darkify') . |
| 134 |
'</div>' . |
| 135 |
'' . |
| 136 |
'', |
| 137 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 138 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 139 |
'text_width' => 100, |
| 140 |
'default' => true, |
| 141 |
// Commit instantly (the shortcut-keys field depends on it). |
| 142 |
'auto_save' => true, |
| 143 |
), |
| 144 |
// Editable shortcut combo (shown when the shortcut is enabled). |
| 145 |
array( |
| 146 |
'id' => 'keyboard_shortcut_keys', |
| 147 |
'type' => 'keyboard_shortcut', |
| 148 |
'default' => 'ctrl+alt+d', |
| 149 |
'dependency' => array('enable_keyboard_shortcut', '==', 'true'), |
| 150 |
), |
| 151 |
// Enable Time Based Auto Dark Mode |
| 152 |
array( |
| 153 |
'id' => 'enable_time', |
| 154 |
'type' => 'fieldset', |
| 155 |
'fields' => array( |
| 156 |
array( |
| 157 |
'id' => 'enable_time_based_dark', |
| 158 |
'type' => 'switcher', |
| 159 |
'title' => esc_html__('Time Based Auto Dark Mode', 'darkify'), |
| 160 |
'title_help' => |
| 161 |
'<div class="darkify-info-label">' . |
| 162 |
__('Automatically enable dark mode based on the user’s local time.', 'darkify') . |
| 163 |
'</div>' . |
| 164 |
'' . |
| 165 |
'', |
| 166 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 167 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 168 |
'text_width' => 100, |
| 169 |
), |
| 170 |
array( |
| 171 |
'id' => 'enable_time_fields', |
| 172 |
'type' => 'fieldset', |
| 173 |
'class' => 'enable_time_fields', |
| 174 |
'dependency' => array('enable_time_based_dark', '==', 'true'), |
| 175 |
'title' => esc_html__('Pick a Time', 'darkify'), |
| 176 |
'title_help' => |
| 177 |
'<div class="darkify-info-label">' . |
| 178 |
__('Set the exact start and end times when dark mode should be automatically enabled or disabled.', 'darkify') . |
| 179 |
'</div>' . |
| 180 |
'' . |
| 181 |
'', |
| 182 |
'fields' => array( |
| 183 |
/* |
| 184 |
* Which clock drives the schedule. Darkify Lite ships |
| 185 |
* only "fixed" (the start/end window below); the |
| 186 |
* sunrise/sunset schedule is a Pro feature, so its |
| 187 |
* option row carries `pro_only` — the REST layer turns |
| 188 |
* that into the `pro_options` stamp the React admin |
| 189 |
* renders as a locked, badged preview, and |
| 190 |
* strip_pro_keys() refuses to persist the value even |
| 191 |
* if a crafted request sends it. |
| 192 |
*/ |
| 193 |
array( |
| 194 |
'id' => 'time_based_dark_mode', |
| 195 |
'type' => 'button_set', |
| 196 |
'default' => 'fixed', |
| 197 |
'options' => array( |
| 198 |
'fixed' => esc_html__('Fixed times', 'darkify'), |
| 199 |
'suncycle' => array( |
| 200 |
'text' => esc_html__('Sunrise & sunset', 'darkify'), |
| 201 |
'pro_only' => true, |
| 202 |
), |
| 203 |
), |
| 204 |
), |
| 205 |
array( |
| 206 |
'id' => 'time_based_dark_start', |
| 207 |
'type' => 'datetime', |
| 208 |
'after' => esc_html__('From', 'darkify'), |
| 209 |
'placeholder' => esc_html__('From', 'darkify'), |
| 210 |
'settings' => array( |
| 211 |
'noCalendar' => true, |
| 212 |
'enableTime' => true, |
| 213 |
'dateFormat' => 'H:i', |
| 214 |
'time_24hr' => false, |
| 215 |
), |
| 216 |
), |
| 217 |
array( |
| 218 |
'id' => 'time_based_dark_end', |
| 219 |
'type' => 'datetime', |
| 220 |
'after' => esc_html__('To', 'darkify'), |
| 221 |
'placeholder' => esc_html__('To', 'darkify'), |
| 222 |
'settings' => array( |
| 223 |
'noCalendar' => true, |
| 224 |
'enableTime' => true, |
| 225 |
'dateFormat' => 'H:i', |
| 226 |
'time_24hr' => false, |
| 227 |
), |
| 228 |
), |
| 229 |
), |
| 230 |
), |
| 231 |
), |
| 232 |
), |
| 233 |
), |
| 234 |
), |
| 235 |
array( |
| 236 |
'id' => 'admin', |
| 237 |
'title' => esc_html__('Admin', 'darkify'), |
| 238 |
'icon' => 'icofont-dashboard-web', |
| 239 |
'fields' => array( |
| 240 |
// Intro line with a docs link, rendered plain above the section cards. |
| 241 |
array( |
| 242 |
'type' => 'page_hint', |
| 243 |
'content' => sprintf( |
| 244 |
/* translators: %s: documentation link */ |
| 245 |
__('Bring dark mode to the WordPress admin dashboard and editors. %s', 'darkify'), |
| 246 |
'<a href="https://darkifywp.com/docs/" target="_blank" rel="noopener noreferrer">' . esc_html__('View documentation', 'darkify') . '</a>' |
| 247 |
), |
| 248 |
), |
| 249 |
// ===== ADMIN APPEARANCE ===== |
| 250 |
array( |
| 251 |
'type' => 'heading', |
| 252 |
'title' => esc_html__('Admin Appearance', 'darkify'), |
| 253 |
'section_start' => true, |
| 254 |
), |
| 255 |
array( |
| 256 |
'id' => 'enable_admin_panel_dark_mode', |
| 257 |
'type' => 'switcher', |
| 258 |
'title' => esc_html__('Admin Panel Dark Mode', 'darkify'), |
| 259 |
'title_help' => |
| 260 |
'<div class="darkify-info-label">' . |
| 261 |
__('Enable dark mode in the WordPress admin dashboard.', 'darkify') . |
| 262 |
'</div>' . |
| 263 |
'' . |
| 264 |
'', |
| 265 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 266 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 267 |
'default' => false, |
| 268 |
'text_width' => 100, |
| 269 |
// Commit instantly even though other fields depend on it. |
| 270 |
'auto_save' => true, |
| 271 |
), |
| 272 |
|
| 273 |
array( |
| 274 |
'id' => 'block_editor_dark_mode', |
| 275 |
'type' => 'switcher', |
| 276 |
'title' => esc_html__('Block Editor Dark Mode', 'darkify'), |
| 277 |
'title_help' => |
| 278 |
'<div class="darkify-info-label">' . |
| 279 |
__('Enable the dark mode switch in the block editor to toggle between dark and light mode.', 'darkify') . |
| 280 |
'</div>' . |
| 281 |
'' . |
| 282 |
'', |
| 283 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 284 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 285 |
'default' => false, |
| 286 |
'text_width' => 100, |
| 287 |
), |
| 288 |
array( |
| 289 |
'id' => 'classic_editor_dark_mode', |
| 290 |
'type' => 'switcher', |
| 291 |
'title' => esc_html__('Classic Editor Dark Mode', 'darkify'), |
| 292 |
'title_help' => |
| 293 |
'<div class="darkify-info-label">' . |
| 294 |
__('Enable the dark mode switch in the classic editor to toggle between dark and light modes.', 'darkify') . |
| 295 |
'</div>' . |
| 296 |
'' . |
| 297 |
'', |
| 298 |
'text_on' => esc_html__('Enabled', 'darkify'), |
| 299 |
'text_off' => esc_html__('Disabled', 'darkify'), |
| 300 |
|
| 301 |
'default' => false, |
| 302 |
'text_width' => 100, |
| 303 |
), |
| 304 |
|
| 305 |
// ===== SCOPE & CUSTOMIZATION ===== |
| 306 |
array( |
| 307 |
'type' => 'heading', |
| 308 |
'title' => esc_html__('Scope & Customization', 'darkify'), |
| 309 |
'section_start' => true, |
| 310 |
'dependency' => array('enable_admin_panel_dark_mode', '==', 'true'), |
| 311 |
), |
| 312 |
array( |
| 313 |
'id' => 'disallowed_admin_pages', |
| 314 |
'type' => 'textarea', |
| 315 |
'title' => esc_html__('Disallowed Pages', 'darkify'), |
| 316 |
'title_help' => '<div class="darkify-info-text">' . |
| 317 |
__('If an admin page URL looks like http://example.com/wp-admin/admin.php?page=darkify, then "darkify" is the page slug.', 'darkify') . |
| 318 |
'</div>' . |
| 319 |
'' . |
| 320 |
'', |
| 321 |
'placeholder' => esc_html__('Enter comma-separated page slugs. Example: darkify-dashboard, elementor', 'darkify'), |
| 322 |
'dependency' => array('enable_admin_panel_dark_mode', '==', 'true'), |
| 323 |
'class' => 'only_pro' |
| 324 |
), |
| 325 |
array( |
| 326 |
'id' => 'admin_custom_css', |
| 327 |
'type' => 'code_editor', |
| 328 |
'title' => esc_html__('Admin Dark Mode CSS', 'darkify'), |
| 329 |
'title_help' => |
| 330 |
'<div class="darkify-info-label">' . |
| 331 |
__('The CSS code will only be applied when admin dark mode is active.', 'darkify') . |
| 332 |
'</div>', |
| 333 |
'settings' => array( |
| 334 |
'theme' => 'mbo', |
| 335 |
'mode' => 'css', |
| 336 |
), |
| 337 |
// Only relevant when admin dark mode is active — hide it while off. |
| 338 |
'dependency' => array('enable_admin_panel_dark_mode', '==', 'true'), |
| 339 |
), |
| 340 |
), |
| 341 |
), |
| 342 |
), |
| 343 |
), |
| 344 |
), |
| 345 |
), |
| 346 |
); |
| 347 |
} |
| 348 |
} |
| 349 |
|