| 1 |
<?php if (!defined('ABSPATH')) { |
| 2 |
die; |
| 3 |
} // Cannot access directly. |
| 4 |
/** |
| 5 |
* |
| 6 |
* Options Class |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
* @version 1.0.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if (!class_exists('DRK_LITE_Options')) { |
| 13 |
class DRK_LITE_Options extends DRK_LITE_Abstract |
| 14 |
{ |
| 15 |
|
| 16 |
// constans |
| 17 |
public $unique = ''; |
| 18 |
public $notice = ''; |
| 19 |
public $abstract = 'options'; |
| 20 |
public $sections = array(); |
| 21 |
public $options = array(); |
| 22 |
public $errors = array(); |
| 23 |
public $pre_tabs = array(); |
| 24 |
public $pre_fields = array(); |
| 25 |
public $pre_sections = array(); |
| 26 |
public $args = array( |
| 27 |
|
| 28 |
// framework title |
| 29 |
'framework_title' => 'Codestar Framework <small>by Codestar</small>', |
| 30 |
'framework_class' => '', |
| 31 |
|
| 32 |
// menu settings |
| 33 |
'menu_title' => '', |
| 34 |
'menu_slug' => '', |
| 35 |
'menu_type' => 'menu', |
| 36 |
'menu_capability' => 'manage_options', |
| 37 |
'menu_icon' => null, |
| 38 |
'menu_position' => null, |
| 39 |
'menu_hidden' => false, |
| 40 |
'menu_parent' => '', |
| 41 |
'sub_menu_title' => '', |
| 42 |
|
| 43 |
// menu extras |
| 44 |
'show_bar_menu' => true, |
| 45 |
'show_sub_menu' => true, |
| 46 |
'show_in_network' => true, |
| 47 |
'show_in_customizer' => false, |
| 48 |
|
| 49 |
'show_search' => true, |
| 50 |
'show_reset_all' => true, |
| 51 |
'show_reset_section' => true, |
| 52 |
'show_footer' => true, |
| 53 |
'show_all_options' => true, |
| 54 |
'show_form_warning' => true, |
| 55 |
'sticky_header' => true, |
| 56 |
'save_defaults' => true, |
| 57 |
'ajax_save' => true, |
| 58 |
'form_action' => '', |
| 59 |
|
| 60 |
// admin bar menu settings |
| 61 |
'admin_bar_menu_icon' => '', |
| 62 |
'admin_bar_menu_priority' => 50, |
| 63 |
|
| 64 |
// footer |
| 65 |
'footer_text' => 'Thank you for creating with Codestar Framework', |
| 66 |
'footer_after' => '', |
| 67 |
'footer_credit' => '', |
| 68 |
|
| 69 |
// database model |
| 70 |
'database' => '', // options, transient, theme_mod, network |
| 71 |
'transient_time' => 0, |
| 72 |
|
| 73 |
// contextual help |
| 74 |
'contextual_help' => array(), |
| 75 |
'contextual_help_sidebar' => '', |
| 76 |
|
| 77 |
// typography options |
| 78 |
'enqueue_webfont' => true, |
| 79 |
'async_webfont' => false, |
| 80 |
|
| 81 |
// others |
| 82 |
'output_css' => true, |
| 83 |
|
| 84 |
// theme |
| 85 |
'nav' => 'normal', |
| 86 |
'theme' => 'dark', |
| 87 |
'class' => '', |
| 88 |
|
| 89 |
// external default values |
| 90 |
'defaults' => array(), |
| 91 |
|
| 92 |
); |
| 93 |
|
| 94 |
// run framework construct |
| 95 |
public function __construct($key, $params = array()) |
| 96 |
{ |
| 97 |
|
| 98 |
add_action('wp_ajax_set_options', array($this, 'set_options')); |
| 99 |
add_action('wp_ajax_nopriv_set_options', array($this, 'set_options')); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
$this->unique = $key; |
| 104 |
$this->args = apply_filters("drk_lite_{$this->unique}_args", wp_parse_args($params['args'], $this->args), $this); |
| 105 |
$this->sections = apply_filters("drk_lite_{$this->unique}_sections", $params['sections'], $this); |
| 106 |
|
| 107 |
// run only is admin panel options, avoid performance loss |
| 108 |
$this->pre_tabs = $this->pre_tabs($this->sections); |
| 109 |
$this->pre_fields = $this->pre_fields($this->sections); |
| 110 |
$this->pre_sections = $this->pre_sections($this->sections); |
| 111 |
|
| 112 |
|
| 113 |
$this->get_options(); |
| 114 |
$this->set_options(); |
| 115 |
$this->save_defaults(); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
add_action('admin_menu', array($this, 'add_admin_menu')); |
| 120 |
add_action('admin_bar_menu', array($this, 'add_admin_bar_menu'), $this->args['admin_bar_menu_priority']); |
| 121 |
add_action('wp_ajax_drk_lite_' . $this->unique . '_ajax_save', array($this, 'ajax_save')); |
| 122 |
|
| 123 |
if ($this->args['database'] === 'network' && !empty($this->args['show_in_network'])) { |
| 124 |
add_action('network_admin_menu', array($this, 'add_admin_menu')); |
| 125 |
} |
| 126 |
|
| 127 |
// wp enqeueu for typography and output css |
| 128 |
parent::__construct(); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
// instance |
| 138 |
public static function instance($key, $params = array()) |
| 139 |
{ |
| 140 |
return new self($key, $params); |
| 141 |
} |
| 142 |
|
| 143 |
// add admin bar menu |
| 144 |
public function add_admin_bar_menu($wp_admin_bar) |
| 145 |
{ |
| 146 |
|
| 147 |
if (!current_user_can($this->args['menu_capability'])) { |
| 148 |
return; |
| 149 |
} |
| 150 |
|
| 151 |
if (is_network_admin() && ($this->args['database'] !== 'network' || $this->args['show_in_network'] !== true)) { |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
if (!empty($this->args['show_bar_menu']) && empty($this->args['menu_hidden'])) { |
| 156 |
|
| 157 |
global $submenu; |
| 158 |
|
| 159 |
$menu_slug = $this->args['menu_slug']; |
| 160 |
$menu_icon = (!empty($this->args['admin_bar_menu_icon'])) ? '<span class="drk_lite-ab-icon ab-icon ' . esc_attr($this->args['admin_bar_menu_icon']) . '"></span>' : ''; |
| 161 |
|
| 162 |
$wp_admin_bar->add_node(array( |
| 163 |
'id' => $menu_slug, |
| 164 |
'title' => $menu_icon . esc_attr($this->args['menu_title']), |
| 165 |
'href' => esc_url((is_network_admin()) ? network_admin_url('admin.php?page=' . $menu_slug) : admin_url('admin.php?page=' . $menu_slug)), |
| 166 |
)); |
| 167 |
|
| 168 |
if (!empty($submenu[$menu_slug])) { |
| 169 |
foreach ($submenu[$menu_slug] as $menu_key => $menu_value) { |
| 170 |
$wp_admin_bar->add_node(array( |
| 171 |
'parent' => $menu_slug, |
| 172 |
'id' => $menu_slug . '-' . $menu_key, |
| 173 |
'title' => $menu_value[0], |
| 174 |
'href' => esc_url((is_network_admin()) ? network_admin_url('admin.php?page=' . $menu_value[2]) : admin_url('admin.php?page=' . $menu_value[2])), |
| 175 |
)); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
public function ajax_save() |
| 182 |
{ |
| 183 |
|
| 184 |
$result = $this->set_options(true); |
| 185 |
|
| 186 |
if (!$result) { |
| 187 |
wp_send_json_error(array('error' => esc_html__('Error while saving the changes.', 'darkify'))); |
| 188 |
} else { |
| 189 |
wp_send_json_success(array('notice' => $this->notice, 'errors' => $this->errors)); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
// get default value |
| 194 |
public function get_default($field) |
| 195 |
{ |
| 196 |
|
| 197 |
$default = (isset($field['default'])) ? $field['default'] : ''; |
| 198 |
$default = (isset($this->args['defaults'][$field['id']])) ? $this->args['defaults'][$field['id']] : $default; |
| 199 |
|
| 200 |
return $default; |
| 201 |
} |
| 202 |
|
| 203 |
// save defaults and set new fields value to main options |
| 204 |
public function save_defaults() |
| 205 |
{ |
| 206 |
|
| 207 |
|
| 208 |
$tmp_options = $this->options; |
| 209 |
|
| 210 |
foreach ($this->pre_fields as $field) { |
| 211 |
if (!empty($field['id'])) { |
| 212 |
$this->options[$field['id']] = (isset($this->options[$field['id']])) ? $this->options[$field['id']] : $this->get_default($field); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
if ($this->args['save_defaults'] && empty($tmp_options)) { |
| 217 |
$this->save_options($this->options); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
// set options |
| 222 |
public function set_options($ajax = false) |
| 223 |
{ |
| 224 |
|
| 225 |
if(isset($_POST['_ajax_nonce']) && !wp_verify_nonce( sanitize_text_field( wp_unslash ( $_POST['_ajax_nonce'] ) ) , 'save_options')){ |
| 226 |
return wp_send_json(['error' => 'Nonce is invalid']); |
| 227 |
} |
| 228 |
|
| 229 |
// Set variables. |
| 230 |
$data = array(); |
| 231 |
$response = ($ajax && !empty($_POST['data'])) ? wp_kses_post_deep(json_decode(wp_unslash(trim(wp_kses_post($_POST['data']))), true)) : wp_kses_post_deep(array()); |
| 232 |
|
| 233 |
$noncekey = 'drk_lite_options_nonce' . $this->unique; |
| 234 |
$nonce = (!empty($response[$noncekey])) ? $response[$noncekey] : ''; |
| 235 |
|
| 236 |
$options = (!empty($response[$this->unique])) ? $response[$this->unique] : array(); |
| 237 |
$transient = (!empty($response['drk_lite_transient'])) ? $response['drk_lite_transient'] : array(); |
| 238 |
|
| 239 |
if (wp_verify_nonce($nonce, 'drk_lite_options_nonce')) { |
| 240 |
|
| 241 |
$importing = false; |
| 242 |
$section_id = (!empty($transient['section'])) ? $transient['section'] : ''; |
| 243 |
|
| 244 |
if (!$ajax && !empty($response['drk_lite_import_data'])) { |
| 245 |
|
| 246 |
// XSS ok. |
| 247 |
// No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341 |
| 248 |
$import_data = json_decode(wp_unslash(trim($response['drk_lite_import_data'])), true); |
| 249 |
$options = (is_array($import_data) && !empty($import_data)) ? $import_data : array(); |
| 250 |
$importing = true; |
| 251 |
$this->notice = esc_html__('Settings successfully imported.', 'darkify'); |
| 252 |
} |
| 253 |
|
| 254 |
if (!empty($transient['reset'])) { |
| 255 |
|
| 256 |
foreach ($this->pre_fields as $field) { |
| 257 |
if (!empty($field['id'])) { |
| 258 |
$data[$field['id']] = $this->get_default($field); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
$this->notice = esc_html__('Default settings restored.', 'darkify'); |
| 263 |
} else if (!empty($transient['reset_section']) && !empty($section_id)) { |
| 264 |
|
| 265 |
if (!empty($this->pre_sections[$section_id - 1]['fields'])) { |
| 266 |
|
| 267 |
foreach ($this->pre_sections[$section_id - 1]['fields'] as $field) { |
| 268 |
if (!empty($field['id'])) { |
| 269 |
$data[$field['id']] = $this->get_default($field); |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
$data = wp_parse_args($data, $this->options); |
| 275 |
|
| 276 |
$this->notice = esc_html__('Default settings restored.', 'darkify'); |
| 277 |
} else { |
| 278 |
|
| 279 |
// sanitize and validate |
| 280 |
foreach ($this->pre_fields as $field) { |
| 281 |
|
| 282 |
if (!empty($field['id'])) { |
| 283 |
|
| 284 |
$field_id = $field['id']; |
| 285 |
$field_value = isset($options[$field_id]) ? $options[$field_id] : ''; |
| 286 |
|
| 287 |
// Ajax and Importing doing wp_unslash already. |
| 288 |
if (!$ajax && !$importing) { |
| 289 |
$field_value = wp_unslash($field_value); |
| 290 |
} |
| 291 |
|
| 292 |
// Sanitize "post" request of field. |
| 293 |
if (!isset($field['sanitize'])) { |
| 294 |
|
| 295 |
if (is_array($field_value)) { |
| 296 |
|
| 297 |
$data[$field_id] = wp_kses_post_deep($field_value); |
| 298 |
} else { |
| 299 |
|
| 300 |
$data[$field_id] = wp_kses_post($field_value); |
| 301 |
} |
| 302 |
} else if (isset($field['sanitize']) && is_callable($field['sanitize'])) { |
| 303 |
|
| 304 |
$data[$field_id] = call_user_func($field['sanitize'], $field_value); |
| 305 |
} else { |
| 306 |
|
| 307 |
$data[$field_id] = $field_value; |
| 308 |
} |
| 309 |
|
| 310 |
// Validate "post" request of field. |
| 311 |
if (isset($field['validate']) && is_callable($field['validate'])) { |
| 312 |
|
| 313 |
$has_validated = call_user_func($field['validate'], $field_value); |
| 314 |
|
| 315 |
if (!empty($has_validated)) { |
| 316 |
|
| 317 |
$data[$field_id] = (isset($this->options[$field_id])) ? $this->options[$field_id] : ''; |
| 318 |
$this->errors[$field_id] = $has_validated; |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
$data = apply_filters("drk_lite_{$this->unique}_save", $data, $this); |
| 326 |
|
| 327 |
do_action("drk_lite_{$this->unique}_save_before", $data, $this); |
| 328 |
|
| 329 |
$this->options = $data; |
| 330 |
|
| 331 |
$this->save_options($data); |
| 332 |
|
| 333 |
do_action("drk_lite_{$this->unique}_save_after", $data, $this); |
| 334 |
|
| 335 |
if (empty($this->notice)) { |
| 336 |
$this->notice = esc_html__('Settings saved.', 'darkify'); |
| 337 |
} |
| 338 |
|
| 339 |
return true; |
| 340 |
} |
| 341 |
|
| 342 |
return false; |
| 343 |
|
| 344 |
wp_die(); |
| 345 |
} |
| 346 |
|
| 347 |
// save options database |
| 348 |
public function save_options($data) |
| 349 |
{ |
| 350 |
|
| 351 |
if ($this->args['database'] === 'transient') { |
| 352 |
set_transient($this->unique, $data, $this->args['transient_time']); |
| 353 |
} else if ($this->args['database'] === 'theme_mod') { |
| 354 |
set_theme_mod($this->unique, $data); |
| 355 |
} else if ($this->args['database'] === 'network') { |
| 356 |
update_site_option($this->unique, $data); |
| 357 |
} else { |
| 358 |
update_option($this->unique, $data); |
| 359 |
} |
| 360 |
|
| 361 |
do_action("drk_lite_{$this->unique}_saved", $data, $this); |
| 362 |
} |
| 363 |
|
| 364 |
// get options from database |
| 365 |
public function get_options() |
| 366 |
{ |
| 367 |
|
| 368 |
|
| 369 |
if ($this->args['database'] === 'transient') { |
| 370 |
$this->options = get_transient($this->unique); |
| 371 |
} else if ($this->args['database'] === 'theme_mod') { |
| 372 |
$this->options = get_theme_mod($this->unique); |
| 373 |
} else if ($this->args['database'] === 'network') { |
| 374 |
$this->options = get_site_option($this->unique); |
| 375 |
} else { |
| 376 |
$this->options = get_option($this->unique); |
| 377 |
} |
| 378 |
|
| 379 |
if (empty($this->options)) { |
| 380 |
$this->options = array(); |
| 381 |
} |
| 382 |
|
| 383 |
return $this->options; |
| 384 |
} |
| 385 |
|
| 386 |
// admin menu |
| 387 |
public function add_admin_menu() |
| 388 |
{ |
| 389 |
|
| 390 |
extract($this->args); |
| 391 |
|
| 392 |
if ($menu_type === 'submenu') { |
| 393 |
|
| 394 |
$menu_page = call_user_func('add_submenu_page', $menu_parent, esc_attr($menu_title), esc_attr($menu_title), $menu_capability, $menu_slug, array($this, 'add_options_html')); |
| 395 |
} else { |
| 396 |
|
| 397 |
$menu_page = call_user_func('add_menu_page', esc_attr($menu_title), esc_attr($menu_title), $menu_capability, $menu_slug, array($this, 'add_options_html'), $menu_icon, $menu_position); |
| 398 |
|
| 399 |
if (!empty($sub_menu_title)) { |
| 400 |
call_user_func('add_submenu_page', $menu_slug, esc_attr($sub_menu_title), esc_attr($sub_menu_title), $menu_capability, $menu_slug, array($this, 'add_options_html')); |
| 401 |
} |
| 402 |
|
| 403 |
if (!empty($this->args['show_sub_menu']) && count($this->pre_tabs) > 1) { |
| 404 |
|
| 405 |
// create submenus |
| 406 |
foreach ($this->pre_tabs as $section) { |
| 407 |
call_user_func('add_submenu_page', $menu_slug, esc_attr($section['title']), esc_attr($section['title']), $menu_capability, $menu_slug . '#tab=' . sanitize_title($section['title']), '__return_null'); |
| 408 |
} |
| 409 |
|
| 410 |
remove_submenu_page($menu_slug, $menu_slug); |
| 411 |
} |
| 412 |
|
| 413 |
if (!empty($menu_hidden)) { |
| 414 |
remove_menu_page($menu_slug); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
add_action('load-' . $menu_page, array($this, 'add_page_on_load')); |
| 419 |
} |
| 420 |
|
| 421 |
public function add_page_on_load() |
| 422 |
{ |
| 423 |
|
| 424 |
if (!empty($this->args['contextual_help'])) { |
| 425 |
|
| 426 |
$screen = get_current_screen(); |
| 427 |
|
| 428 |
foreach ($this->args['contextual_help'] as $tab) { |
| 429 |
$screen->add_help_tab($tab); |
| 430 |
} |
| 431 |
|
| 432 |
if (!empty($this->args['contextual_help_sidebar'])) { |
| 433 |
$screen->set_help_sidebar($this->args['contextual_help_sidebar']); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
if (!empty($this->args['footer_credit'])) { |
| 438 |
add_filter('admin_footer_text', array($this, 'add_admin_footer_text')); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
public function add_admin_footer_text() |
| 443 |
{ |
| 444 |
echo wp_kses_post($this->args['footer_credit']); |
| 445 |
} |
| 446 |
|
| 447 |
public function error_check($sections, $err = '') |
| 448 |
{ |
| 449 |
|
| 450 |
if (!$this->args['ajax_save']) { |
| 451 |
|
| 452 |
if (!empty($sections['fields'])) { |
| 453 |
foreach ($sections['fields'] as $field) { |
| 454 |
if (!empty($field['id'])) { |
| 455 |
if (array_key_exists($field['id'], $this->errors)) { |
| 456 |
$err = '<span class="drk_lite-label-error">!</span>'; |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
if (!empty($sections['subs'])) { |
| 463 |
foreach ($sections['subs'] as $sub) { |
| 464 |
$err = $this->error_check($sub, $err); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
if (!empty($sections['id']) && array_key_exists($sections['id'], $this->errors)) { |
| 469 |
$err = $this->errors[$sections['id']]; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
return $err; |
| 474 |
} |
| 475 |
|
| 476 |
// option page html output |
| 477 |
public function add_options_html() |
| 478 |
{ |
| 479 |
|
| 480 |
$has_nav = (count($this->pre_tabs) > 1) ? true : false; |
| 481 |
$show_all = (!$has_nav) ? ' drk_lite-show-all' : ''; |
| 482 |
$ajax_class = ($this->args['ajax_save']) ? ' drk_lite-save-ajax' : ''; |
| 483 |
$sticky_class = ($this->args['sticky_header']) ? ' drk_lite-sticky-header' : ''; |
| 484 |
$wrapper_class = ($this->args['framework_class']) ? ' ' . $this->args['framework_class'] : ''; |
| 485 |
$theme = ($this->args['theme']) ? ' drk_lite-theme-' . $this->args['theme'] : ''; |
| 486 |
$class = ($this->args['class']) ? ' ' . $this->args['class'] : ''; |
| 487 |
$nav_type = ($this->args['nav'] === 'inline') ? 'inline' : 'normal'; |
| 488 |
$form_action = ($this->args['form_action']) ? $this->args['form_action'] : ''; |
| 489 |
|
| 490 |
do_action('drk_lite_options_before'); |
| 491 |
|
| 492 |
echo '<div class="drk_lite drk_lite-options' . esc_attr($theme . $class . $wrapper_class) . '" data-slug="' . esc_attr($this->args['menu_slug']) . '" data-unique="' . esc_attr($this->unique) . '">'; |
| 493 |
|
| 494 |
echo '<div class="drk_lite-container">'; |
| 495 |
|
| 496 |
echo '<form method="post" action="' . esc_attr($form_action) . '" enctype="multipart/form-data" id="drk_lite-form" autocomplete="off" novalidate="novalidate">'; |
| 497 |
|
| 498 |
echo '<input type="hidden" class="drk_lite-section-id" name="drk_lite_transient[section]" value="1">'; |
| 499 |
|
| 500 |
wp_nonce_field('drk_lite_options_nonce', 'drk_lite_options_nonce' . $this->unique); |
| 501 |
|
| 502 |
echo '<div class="drk_lite-header' . esc_attr($sticky_class) . '">'; |
| 503 |
echo '<div class="drk_lite-header-inner">'; |
| 504 |
|
| 505 |
echo '<div class="drk_lite-header-left">'; |
| 506 |
echo '<h1>' . esc_html($this->args['framework_title']) . '</h1>'; |
| 507 |
echo '</div>'; |
| 508 |
|
| 509 |
echo '<div class="drk_lite-header-right">'; |
| 510 |
|
| 511 |
$notice_class = (!empty($this->notice)) ? 'drk_lite-form-show' : ''; |
| 512 |
$notice_text = (!empty($this->notice)) ? $this->notice : ''; |
| 513 |
|
| 514 |
echo '<div class="drk_lite-form-result drk_lite-form-success ' . esc_attr($notice_class) . '">' . wp_kses_post($notice_text) . '</div>'; |
| 515 |
|
| 516 |
echo ($this->args['show_form_warning']) ? '<div class="drk_lite-form-result drk_lite-form-warning">' . esc_html__('You have unsaved changes, save your changes!', 'darkify') . '</div>' : ''; |
| 517 |
|
| 518 |
echo ($has_nav && $this->args['show_all_options']) ? '<div class="drk_lite-expand-all" title="' . esc_html__('show all settings', 'darkify') . '"><i class="fas fa-outdent"></i></div>' : ''; |
| 519 |
|
| 520 |
echo ($this->args['show_search']) ? '<div class="drk_lite-search"><input type="text" name="drk_lite-search" placeholder="' . esc_html__('Search...', 'darkify') . '" autocomplete="off" /></div>' : ''; |
| 521 |
|
| 522 |
echo '<div class="drk_lite-buttons">'; |
| 523 |
echo '<input type="submit" name="' . esc_attr($this->unique) . '[_nonce][save]" class="button button-primary drk_lite-top-save drk_lite-save' . esc_attr($ajax_class) . '" value="' . esc_html__('Save', 'darkify') . '" data-save="' . esc_html__('Saving...', 'darkify') . '">'; |
| 524 |
echo ($this->args['show_reset_section']) ? '<input type="submit" name="drk_lite_transient[reset_section]" class="button button-secondary drk_lite-reset-section drk_lite-confirm" value="' . esc_html__('Reset Section', 'darkify') . '" data-confirm="' . esc_html__('Are you sure to reset this section options?', 'darkify') . '">' : ''; |
| 525 |
echo ($this->args['show_reset_all']) ? '<input type="submit" name="drk_lite_transient[reset]" class="button drk_lite-warning-primary drk_lite-reset-all drk_lite-confirm" value="' . (($this->args['show_reset_section']) ? esc_html__('Reset All', 'darkify') : esc_html__('Reset', 'darkify')) . '" data-confirm="' . esc_html__('Are you sure you want to reset all settings to default values?', 'darkify') . '">' : ''; |
| 526 |
echo '</div>'; |
| 527 |
|
| 528 |
echo '</div>'; |
| 529 |
|
| 530 |
echo '<div class="clear"></div>'; |
| 531 |
echo '</div>'; |
| 532 |
echo '</div>'; |
| 533 |
|
| 534 |
echo '<div class="drk_lite-wrapper' . esc_attr($show_all) . '">'; |
| 535 |
|
| 536 |
if ($has_nav) { |
| 537 |
|
| 538 |
echo '<div class="drk_lite-nav drk_lite-nav-' . esc_attr($nav_type) . ' drk_lite-nav-options">'; |
| 539 |
|
| 540 |
echo '<ul>'; |
| 541 |
|
| 542 |
foreach ($this->pre_tabs as $tab) { |
| 543 |
|
| 544 |
$tab_id = sanitize_title($tab['title']); |
| 545 |
$tab_error = $this->error_check($tab); |
| 546 |
$tab_icon = (!empty($tab['icon'])) ? '<i class="drk_lite-tab-icon ' . esc_attr($tab['icon']) . '"></i>' : ''; |
| 547 |
|
| 548 |
if (!empty($tab['subs'])) { |
| 549 |
|
| 550 |
echo '<li class="drk_lite-tab-item">'; |
| 551 |
|
| 552 |
echo '<a href="#tab=' . esc_attr($tab_id) . '" data-tab-id="' . esc_attr($tab_id) . '" class="drk_lite-arrow">' . wp_kses_post($tab_icon) . esc_html($tab['title']) . esc_html($tab_error) . '</a>'; |
| 553 |
|
| 554 |
echo '<ul>'; |
| 555 |
|
| 556 |
foreach ($tab['subs'] as $sub) { |
| 557 |
|
| 558 |
$sub_id = $tab_id . '/' . sanitize_title($sub['title']); |
| 559 |
$sub_error = $this->error_check($sub); |
| 560 |
$sub_icon = (!empty($sub['icon'])) ? '<i class="drk_lite-tab-icon ' . esc_attr($sub['icon']) . '"></i>' : ''; |
| 561 |
|
| 562 |
echo '<li><a href="#tab=' . esc_attr($sub_id) . '" data-tab-id="' . esc_attr($sub_id) . '">' . wp_kses_post($sub_icon) . esc_html($sub['title']) . wp_kses_post($sub_error) . '</a></li>'; |
| 563 |
} |
| 564 |
|
| 565 |
echo '</ul>'; |
| 566 |
|
| 567 |
echo '</li>'; |
| 568 |
} else { |
| 569 |
|
| 570 |
echo '<li class="drk_lite-tab-item"><a href="#tab=' . esc_attr($tab_id) . '" data-tab-id="' . esc_attr($tab_id) . '">' . wp_kses_post($tab_icon) . esc_html($tab['title']) . esc_html($tab_error) . '</a></li>'; |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
echo '</ul>'; |
| 575 |
|
| 576 |
echo '</div>'; |
| 577 |
} |
| 578 |
|
| 579 |
echo '<div class="drk_lite-content">'; |
| 580 |
|
| 581 |
echo '<div class="drk_lite-sections">'; |
| 582 |
|
| 583 |
foreach ($this->pre_sections as $section) { |
| 584 |
|
| 585 |
$section_onload = (!$has_nav) ? ' drk_lite-onload' : ''; |
| 586 |
$section_class = (!empty($section['class'])) ? ' ' . $section['class'] : ''; |
| 587 |
$section_icon = (!empty($section['icon'])) ? '<i class="drk_lite-section-icon ' . esc_attr($section['icon']) . '"></i>' : ''; |
| 588 |
$section_title = (!empty($section['title'])) ? $section['title'] : ''; |
| 589 |
$section_parent = (!empty($section['ptitle'])) ? sanitize_title($section['ptitle']) . '/' : ''; |
| 590 |
$section_slug = (!empty($section['title'])) ? sanitize_title($section_title) : ''; |
| 591 |
|
| 592 |
echo '<div class="drk_lite-section hidden' . esc_attr($section_onload . $section_class) . '" data-section-id="' . esc_attr($section_parent . $section_slug) . '">'; |
| 593 |
echo ($has_nav) ? '<div class="drk_lite-section-title"><h3>' . wp_kses_post($section_icon) . esc_html($section_title) . '</h3></div>' : ''; |
| 594 |
echo (!empty($section['description'])) ? '<div class="drk_lite-field drk_lite-section-description">' . wp_kses_post($section['description']) . '</div>' : ''; |
| 595 |
|
| 596 |
if (!empty($section['fields'])) { |
| 597 |
|
| 598 |
foreach ($section['fields'] as $field) { |
| 599 |
|
| 600 |
$is_field_error = $this->error_check($field); |
| 601 |
|
| 602 |
if (!empty($is_field_error)) { |
| 603 |
$field['_error'] = $is_field_error; |
| 604 |
} |
| 605 |
|
| 606 |
if (!empty($field['id'])) { |
| 607 |
$field['default'] = $this->get_default($field); |
| 608 |
} |
| 609 |
|
| 610 |
$value = (!empty($field['id']) && isset($this->options[$field['id']])) ? $this->options[$field['id']] : ''; |
| 611 |
|
| 612 |
DRK_LITE::field($field, $value, $this->unique, 'options'); |
| 613 |
} |
| 614 |
} else { |
| 615 |
|
| 616 |
echo '<div class="drk_lite-no-option">' . esc_html__('No data available.', 'darkify') . '</div>'; |
| 617 |
} |
| 618 |
|
| 619 |
echo '</div>'; |
| 620 |
} |
| 621 |
|
| 622 |
echo '</div>'; |
| 623 |
|
| 624 |
echo '<div class="clear"></div>'; |
| 625 |
|
| 626 |
echo '</div>'; |
| 627 |
|
| 628 |
echo ($has_nav && $nav_type === 'normal') ? '<div class="drk_lite-nav-background"></div>' : ''; |
| 629 |
|
| 630 |
echo '</div>'; |
| 631 |
|
| 632 |
if (!empty($this->args['show_footer'])) { |
| 633 |
|
| 634 |
echo '<div class="drk_lite-footer">'; |
| 635 |
|
| 636 |
echo '<div class="drk_lite-buttons">'; |
| 637 |
echo '<input type="submit" name="drk_lite_transient[save]" class="button button-primary drk_lite-save' . esc_attr($ajax_class) . '" value="' . esc_html__('Save', 'darkify') . '" data-save="' . esc_html__('Saving...', 'darkify') . '">'; |
| 638 |
echo ($this->args['show_reset_section']) ? '<input type="submit" name="drk_lite_transient[reset_section]" class="button button-secondary drk_lite-reset-section drk_lite-confirm" value="' . esc_html__('Reset Section', 'darkify') . '" data-confirm="' . esc_html__('Are you sure to reset this section options?', 'darkify') . '">' : ''; |
| 639 |
echo ($this->args['show_reset_all']) ? '<input type="submit" name="drk_lite_transient[reset]" class="button drk_lite-warning-primary drk_lite-reset-all drk_lite-confirm" value="' . (($this->args['show_reset_section']) ? esc_html__('Reset All', 'darkify') : esc_html__('Reset', 'darkify')) . '" data-confirm="' . esc_html__('Are you sure you want to reset all settings to default values?', 'darkify') . '">' : ''; |
| 640 |
echo '</div>'; |
| 641 |
|
| 642 |
echo (!empty($this->args['footer_text'])) ? '<div class="drk_lite-copyright">' . wp_kses_post($this->args['footer_text']) . '</div>' : ''; |
| 643 |
|
| 644 |
echo '<div class="clear"></div>'; |
| 645 |
echo '</div>'; |
| 646 |
} |
| 647 |
|
| 648 |
echo '</form>'; |
| 649 |
|
| 650 |
echo '</div>'; |
| 651 |
|
| 652 |
echo '<div class="clear"></div>'; |
| 653 |
|
| 654 |
echo (!empty($this->args['footer_after'])) ? wp_kses_post($this->args['footer_after']) : ''; |
| 655 |
|
| 656 |
echo '</div>'; |
| 657 |
|
| 658 |
do_action('drk_lite_options_after'); |
| 659 |
} |
| 660 |
} |
| 661 |
} |
| 662 |
|