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