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