← All changes
|
admin/views/sp-framework/classes/options.class.php
+124
-255
2.3.6
→
2.2.10
View file →
| @@ -1,80 +1,28 @@ | ||
| 1 | 1 | <?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 | 2 | die; } // Cannot access directly. |
| 3 | - | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * Options Class | |
| 6 | + * | |
| 7 | + * @since 1.0.0 | |
| 8 | + * @version 1.0.0 | |
| 9 | + */ | |
| 4 | 10 | if ( ! class_exists( 'SP_PC_Options' ) ) { |
| 5 | - /** | |
| 6 | - * Options Class | |
| 7 | - * | |
| 8 | - * @since 1.0.0 | |
| 9 | - * @version 1.0.0 | |
| 10 | - */ | |
| 11 | 11 | class SP_PC_Options extends SP_PC_Abstract { |
| 12 | 12 | |
| 13 | - /** | |
| 14 | - * Unique ID/Name | |
| 15 | - * | |
| 16 | - * @var string | |
| 17 | - */ | |
| 18 | - public $unique = ''; | |
| 19 | - /** | |
| 20 | - * Notice. | |
| 21 | - * | |
| 22 | - * @var string | |
| 23 | - */ | |
| 24 | - public $notice = ''; | |
| 25 | - /** | |
| 26 | - * Abstract. | |
| 27 | - * | |
| 28 | - * @var string | |
| 29 | - */ | |
| 30 | - public $abstract = 'options'; | |
| 31 | - /** | |
| 32 | - * Setions. | |
| 33 | - * | |
| 34 | - * @var array | |
| 35 | - */ | |
| 36 | - public $sections = array(); | |
| 37 | - /** | |
| 38 | - * Options | |
| 39 | - * | |
| 40 | - * @var array | |
| 41 | - */ | |
| 42 | - public $options = array(); | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Errors. | |
| 46 | - * | |
| 47 | - * @var array | |
| 48 | - */ | |
| 49 | - public $errors = array(); | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * Pre tabs. | |
| 53 | - * | |
| 54 | - * @var array | |
| 55 | - */ | |
| 56 | - public $pre_tabs = array(); | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * Pre fields. | |
| 60 | - * | |
| 61 | - * @var array | |
| 62 | - */ | |
| 63 | - public $pre_fields = array(); | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * Pre sections. | |
| 67 | - * | |
| 68 | - * @var array | |
| 69 | - */ | |
| 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(); | |
| 70 | 22 | public $pre_sections = array(); |
| 71 | 23 | |
| 72 | - /** | |
| 73 | - * Default arguments. | |
| 74 | - * | |
| 75 | - * @var array | |
| 76 | - */ | |
| 24 | + // default args. | |
| 77 | 25 | public $args = array( |
| 78 | 26 | |
| 79 | 27 | // framework title. |
| 80 | 28 | 'framework_title' => 'SPF Framework <small>by SP</small>', |
| @@ -83,9 +31,9 @@ | ||
| 83 | 31 | // menu settings. |
| 84 | 32 | 'menu_title' => '', |
| 85 | 33 | 'menu_slug' => '', |
| 86 | 34 | 'menu_type' => 'menu', |
| 87 | - // 'menu_capability' => 'manage_options', It's implemented in add_admin_menu() | |
| 35 | + 'menu_capability' => 'manage_options', | |
| 88 | 36 | 'menu_icon' => null, |
| 89 | 37 | 'menu_position' => null, |
| 90 | 38 | 'menu_hidden' => false, |
| 91 | 39 | 'menu_parent' => '', |
| @@ -138,14 +86,9 @@ | ||
| 138 | 86 | 'defaults' => array(), |
| 139 | 87 | |
| 140 | 88 | ); |
| 141 | 89 | |
| 142 | - /** | |
| 143 | - * Run framework construct. | |
| 144 | - * | |
| 145 | - * @param string $key The filter unique key. | |
| 146 | - * @param array $params The parameters. | |
| 147 | - */ | |
| 90 | + // run framework construct. | |
| 148 | 91 | public function __construct( $key, $params = array() ) { |
| 149 | 92 | |
| 150 | 93 | $this->unique = $key; |
| 151 | 94 | $this->args = apply_filters( "spf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this ); |
| @@ -172,24 +115,13 @@ | ||
| 172 | 115 | parent::__construct(); |
| 173 | 116 | |
| 174 | 117 | } |
| 175 | 118 | |
| 176 | - /** | |
| 177 | - * Instance. | |
| 178 | - * | |
| 179 | - * @param object $key The instance key. | |
| 180 | - * @param array $params All the parameters. | |
| 181 | - * @return mixed | |
| 182 | - */ | |
| 119 | + // instance. | |
| 183 | 120 | public static function instance( $key, $params = array() ) { |
| 184 | 121 | return new self( $key, $params ); |
| 185 | 122 | } |
| 186 | - /** | |
| 187 | - * Pre tabs. | |
| 188 | - * | |
| 189 | - * @param array $sections All the sections. | |
| 190 | - * @return mixed | |
| 191 | - */ | |
| 123 | + | |
| 192 | 124 | public function pre_tabs( $sections ) { |
| 193 | 125 | |
| 194 | 126 | $result = array(); |
| 195 | 127 | $parents = array(); |
| @@ -215,14 +147,8 @@ | ||
| 215 | 147 | |
| 216 | 148 | return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true ); |
| 217 | 149 | } |
| 218 | 150 | |
| 219 | - /** | |
| 220 | - * Pre fields method. | |
| 221 | - * | |
| 222 | - * @param array $sections The sections. | |
| 223 | - * @return $result | |
| 224 | - */ | |
| 225 | 151 | public function pre_fields( $sections ) { |
| 226 | 152 | |
| 227 | 153 | $result = array(); |
| 228 | 154 | |
| @@ -236,14 +162,8 @@ | ||
| 236 | 162 | |
| 237 | 163 | return $result; |
| 238 | 164 | } |
| 239 | 165 | |
| 240 | - /** | |
| 241 | - * The pre sections. | |
| 242 | - * | |
| 243 | - * @param array $sections The sections. | |
| 244 | - * @return mixed | |
| 245 | - */ | |
| 246 | 166 | public function pre_sections( $sections ) { |
| 247 | 167 | |
| 248 | 168 | $result = array(); |
| 249 | 169 | |
| @@ -260,14 +180,9 @@ | ||
| 260 | 180 | |
| 261 | 181 | return $result; |
| 262 | 182 | } |
| 263 | 183 | |
| 264 | - /** | |
| 265 | - * Add admin bar menu. | |
| 266 | - * | |
| 267 | - * @param object $wp_admin_bar The admin bar. | |
| 268 | - * @return void | |
| 269 | - */ | |
| 184 | + // add admin bar menu. | |
| 270 | 185 | public function add_admin_bar_menu( $wp_admin_bar ) { |
| 271 | 186 | |
| 272 | 187 | if ( ! empty( $this->args['show_bar_menu'] ) && empty( $this->args['menu_hidden'] ) ) { |
| 273 | 188 | |
| @@ -310,45 +225,43 @@ | ||
| 310 | 225 | } |
| 311 | 226 | |
| 312 | 227 | } |
| 313 | 228 | |
| 314 | - /** | |
| 315 | - * Ajax save method. | |
| 316 | - * | |
| 317 | - * @return void | |
| 318 | - */ | |
| 319 | 229 | public function ajax_save() { |
| 320 | 230 | |
| 321 | - $result = $this->set_options( true ); | |
| 322 | - if ( ! $result ) { | |
| 323 | - wp_send_json_error( | |
| 324 | - array( | |
| 325 | - 'success' => false, | |
| 326 | - 'error' => esc_html__( | |
| 327 | - 'Error while saving.', | |
| 328 | - 'smart-post-show' | |
| 329 | - ), | |
| 330 | - ) | |
| 331 | - ); | |
| 231 | + if ( ! empty( $_POST['data'] ) ) { | |
| 332 | 232 | |
| 333 | - } else { | |
| 334 | - wp_send_json_success( | |
| 335 | - array( | |
| 336 | - 'success' => true, | |
| 337 | - 'notice' => $this->notice, | |
| 338 | - 'errors' => $this->errors, | |
| 339 | - ) | |
| 340 | - ); | |
| 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 | + } | |
| 341 | 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 | + | |
| 342 | 261 | } |
| 343 | 262 | |
| 344 | - /** | |
| 345 | - * Get default value. | |
| 346 | - * | |
| 347 | - * @param array $field The field array. | |
| 348 | - * @param array $options The options array. | |
| 349 | - * @return mixed | |
| 350 | - */ | |
| 263 | + // get default value | |
| 351 | 264 | public function get_default( $field, $options = array() ) { |
| 352 | 265 | |
| 353 | 266 | $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : ''; |
| 354 | 267 | $default = ( isset( $field['default'] ) ) ? $field['default'] : $default; |
| @@ -357,13 +270,9 @@ | ||
| 357 | 270 | return $default; |
| 358 | 271 | |
| 359 | 272 | } |
| 360 | 273 | |
| 361 | - /** | |
| 362 | - * Save defaults and set new fields value to main options. | |
| 363 | - * | |
| 364 | - * @return void | |
| 365 | - */ | |
| 274 | + // save defaults and set new fields value to main options. | |
| 366 | 275 | public function save_defaults() { |
| 367 | 276 | |
| 368 | 277 | $tmp_options = $this->options; |
| 369 | 278 | |
| @@ -378,50 +287,30 @@ | ||
| 378 | 287 | } |
| 379 | 288 | |
| 380 | 289 | } |
| 381 | 290 | |
| 382 | - /** | |
| 383 | - * Set options. | |
| 384 | - * | |
| 385 | - * @param boolean $ajax The ajax save. | |
| 386 | - * | |
| 387 | - * @return mixed | |
| 388 | - */ | |
| 389 | - public function set_options( $ajax = false ) { | |
| 291 | + // set options. | |
| 292 | + public function set_options() { | |
| 390 | 293 | |
| 391 | - // XSS ok. | |
| 392 | - // No worries, This "POST" requests is sanitizing in the below foreach. see #L380 - #L384. | |
| 393 | - $response = ( $ajax && ! empty( $_POST['data'] ) ) ? json_decode( wp_unslash( trim( $_POST['data'] ) ), true ) : $_POST; // phpcs:ignore | |
| 294 | + if ( wp_verify_nonce( spf_get_var( 'spf_options_nonce' . $this->unique ), 'spf_options_nonce' ) ) { | |
| 394 | 295 | |
| 395 | - // Set variables. | |
| 396 | - $data = array(); | |
| 397 | - $noncekey = 'spf_options_nonce' . $this->unique; | |
| 398 | - $nonce = ( ! empty( $response[ $noncekey ] ) ) ? $response[ $noncekey ] : ''; | |
| 399 | - $options = ( ! empty( $response[ $this->unique ] ) ) ? $response[ $this->unique ] : array(); | |
| 400 | - $transient = ( ! empty( $response['spf_transient'] ) ) ? $response['spf_transient'] : array(); | |
| 401 | - | |
| 402 | - if ( wp_verify_nonce( $nonce, 'spf_options_nonce' ) ) { | |
| 403 | - | |
| 404 | - $importing = false; | |
| 296 | + $request = spf_get_var( $this->unique, array() ); | |
| 297 | + $transient = spf_get_var( 'spf_transient' ); | |
| 405 | 298 | $section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : ''; |
| 406 | 299 | |
| 407 | 300 | // import data. |
| 408 | - if ( ! $ajax && ! empty( $response['spf_import_data'] ) ) { | |
| 301 | + if ( ! empty( $transient['spf_import_data'] ) ) { | |
| 409 | 302 | |
| 410 | - // XSS ok. | |
| 411 | - // No worries, This "POST" requests is sanitizing in the below foreach. see #L380 - #L384. | |
| 412 | - $import_data = json_decode( wp_unslash( trim( $response['spf_import_data'] ) ), true ); | |
| 413 | - $options = ( is_array( $import_data ) && ! empty( $import_data ) ) ? $import_data : array(); | |
| 414 | - $importing = true; | |
| 415 | - $this->notice = esc_html__( 'Settings successfully imported.', 'smart-post-show' ); | |
| 303 | + $import_data = json_decode( stripslashes( trim( $transient['spf_import_data'] ) ), true ); | |
| 304 | + $request = ( is_array( $import_data ) ) ? $import_data : array(); | |
| 416 | 305 | |
| 417 | - } | |
| 306 | + $this->notice = esc_html__( 'Success. Imported backup options.', 'smart-post-show' ); | |
| 418 | 307 | |
| 419 | - if ( ! empty( $transient['reset'] ) ) { | |
| 308 | + } elseif ( ! empty( $transient['reset'] ) ) { | |
| 420 | 309 | |
| 421 | 310 | foreach ( $this->pre_fields as $field ) { |
| 422 | 311 | if ( ! empty( $field['id'] ) ) { |
| 423 | - $data[ $field['id'] ] = $this->get_default( $field ); | |
| 312 | + $request[ $field['id'] ] = $this->get_default( $field ); | |
| 424 | 313 | } |
| 425 | 314 | } |
| 426 | 315 | |
| 427 | 316 | $this->notice = esc_html__( 'Default options restored.', 'smart-post-show' ); |
| @@ -431,14 +320,13 @@ | ||
| 431 | 320 | if ( ! empty( $this->pre_sections[ $section_id - 1 ]['fields'] ) ) { |
| 432 | 321 | |
| 433 | 322 | foreach ( $this->pre_sections[ $section_id - 1 ]['fields'] as $field ) { |
| 434 | 323 | if ( ! empty( $field['id'] ) ) { |
| 435 | - $data[ $field['id'] ] = $this->get_default( $field ); | |
| 324 | + $request[ $field['id'] ] = $this->get_default( $field ); | |
| 436 | 325 | } |
| 437 | 326 | } |
| 438 | 327 | } |
| 439 | 328 | |
| 440 | - $data = wp_parse_args( $data, $this->options ); | |
| 441 | 329 | $this->notice = esc_html__( 'Default options restored for only this section.', 'smart-post-show' ); |
| 442 | 330 | |
| 443 | 331 | } else { |
| 444 | 332 | |
| @@ -446,104 +334,87 @@ | ||
| 446 | 334 | foreach ( $this->pre_fields as $field ) { |
| 447 | 335 | |
| 448 | 336 | if ( ! empty( $field['id'] ) ) { |
| 449 | 337 | |
| 450 | - $field_id = $field['id']; | |
| 451 | - $field_value = isset( $options[ $field_id ] ) ? $options[ $field_id ] : ''; | |
| 452 | - | |
| 453 | - // Ajax and Importing doing wp_unslash already. | |
| 454 | - if ( ! $ajax && ! $importing ) { | |
| 455 | - $field_value = wp_unslash( $field_value ); | |
| 456 | - } | |
| 457 | - | |
| 458 | 338 | // sanitize. |
| 459 | - if ( ! isset( $field['sanitize'] ) ) { | |
| 460 | - if ( is_array( $field_value ) ) { | |
| 339 | + if ( ! empty( $field['sanitize'] ) ) { | |
| 461 | 340 | |
| 462 | - $data[ $field_id ] = wp_kses_post_deep( $field_value ); | |
| 341 | + $sanitize = $field['sanitize']; | |
| 342 | + $value_sanitize = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : ''; | |
| 343 | + $request[ $field['id'] ] = call_user_func( $sanitize, $value_sanitize ); | |
| 463 | 344 | |
| 464 | - } else { | |
| 465 | - | |
| 466 | - $data[ $field_id ] = wp_kses_post( $field_value ); | |
| 467 | - } | |
| 468 | - } elseif ( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) { | |
| 469 | - | |
| 470 | - $data[ $field_id ] = call_user_func( $field['sanitize'], $field_value ); | |
| 471 | - | |
| 472 | - } else { | |
| 473 | - $data[ $field_id ] = $field_value; | |
| 474 | - | |
| 475 | 345 | } |
| 476 | 346 | |
| 477 | - // Validate "post" request of field. | |
| 478 | - if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) { | |
| 347 | + // validate. | |
| 348 | + if ( ! empty( $field['validate'] ) ) { | |
| 479 | 349 | |
| 480 | - $has_validated = call_user_func( $field['validate'], $field_value ); | |
| 350 | + $value_validate = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : ''; | |
| 351 | + $has_validated = call_user_func( $field['validate'], $value_validate ); | |
| 481 | 352 | |
| 482 | 353 | if ( ! empty( $has_validated ) ) { |
| 483 | - $data[ $field_id ] = ( isset( $this->options[ $field_id ] ) ) ? $this->options[ $field_id ] : ''; | |
| 484 | - $this->errors[ $field_id ] = $has_validated; | |
| 354 | + $request[ $field['id'] ] = ( isset( $this->options[ $field['id'] ] ) ) ? $this->options[ $field['id'] ] : ''; | |
| 355 | + $this->errors[ $field['id'] ] = $has_validated; | |
| 485 | 356 | } |
| 486 | 357 | } |
| 358 | + | |
| 359 | + // auto sanitize. | |
| 360 | + if ( ! isset( $request[ $field['id'] ] ) || is_null( $request[ $field['id'] ] ) ) { | |
| 361 | + $request[ $field['id'] ] = ''; | |
| 362 | + } | |
| 487 | 363 | } |
| 488 | 364 | } |
| 489 | 365 | } |
| 490 | 366 | |
| 491 | - $data = apply_filters( "spf_{$this->unique}_save", $data, $this ); | |
| 367 | + // ignore nonce requests. | |
| 368 | + if ( isset( $request['_nonce'] ) ) { | |
| 369 | + unset( $request['_nonce'] ); } | |
| 492 | 370 | |
| 493 | - do_action( "spf_{$this->unique}_save_before", $data, $this ); | |
| 371 | + $request = wp_unslash( $request ); | |
| 494 | 372 | |
| 495 | - $this->options = $data; | |
| 373 | + $request = apply_filters( "spf_{$this->unique}_save", $request, $this ); | |
| 496 | 374 | |
| 497 | - $this->save_options( $data ); | |
| 375 | + do_action( "spf_{$this->unique}_save_before", $request, $this ); | |
| 498 | 376 | |
| 499 | - do_action( "spf_{$this->unique}_save_after", $data, $this ); | |
| 377 | + $this->options = $request; | |
| 500 | 378 | |
| 379 | + $this->save_options( $request ); | |
| 380 | + | |
| 381 | + do_action( "spf_{$this->unique}_save_after", $request, $this ); | |
| 382 | + | |
| 501 | 383 | if ( empty( $this->notice ) ) { |
| 502 | 384 | $this->notice = esc_html__( 'Settings saved.', 'smart-post-show' ); |
| 503 | 385 | } |
| 504 | - | |
| 505 | - return true; | |
| 506 | 386 | } |
| 507 | 387 | |
| 508 | - return false; | |
| 388 | + return true; | |
| 509 | 389 | |
| 510 | 390 | } |
| 511 | 391 | |
| 512 | - /** | |
| 513 | - * Save options database. | |
| 514 | - * | |
| 515 | - * @param array $data The options values. | |
| 516 | - * @return void | |
| 517 | - */ | |
| 518 | - public function save_options( $data ) { | |
| 392 | + // save options database. | |
| 393 | + public function save_options( $request ) { | |
| 519 | 394 | |
| 520 | - if ( 'transient' === $this->args['database'] ) { | |
| 521 | - set_transient( $this->unique, $data, $this->args['transient_time'] ); | |
| 522 | - } elseif ( 'theme_mod' === $this->args['database'] ) { | |
| 523 | - set_theme_mod( $this->unique, $data ); | |
| 524 | - } elseif ( 'network' === $this->args['database'] ) { | |
| 525 | - update_site_option( $this->unique, $data ); | |
| 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 ); | |
| 526 | 401 | } else { |
| 527 | - update_option( $this->unique, $data ); | |
| 402 | + update_option( $this->unique, $request ); | |
| 528 | 403 | } |
| 529 | 404 | |
| 530 | - do_action( "spf_{$this->unique}_saved", $data, $this ); | |
| 405 | + do_action( "spf_{$this->unique}_saved", $request, $this ); | |
| 531 | 406 | |
| 532 | 407 | } |
| 533 | 408 | |
| 534 | - /** | |
| 535 | - * Get options from database. | |
| 536 | - * | |
| 537 | - * @return mixed | |
| 538 | - */ | |
| 409 | + // get options from database. | |
| 539 | 410 | public function get_options() { |
| 540 | 411 | |
| 541 | - if ( 'transient' === $this->args['database'] ) { | |
| 412 | + if ( $this->args['database'] === 'transient' ) { | |
| 542 | 413 | $this->options = get_transient( $this->unique ); |
| 543 | - } elseif ( 'theme_mod' === $this->args['database'] ) { | |
| 414 | + } elseif ( $this->args['database'] === 'theme_mod' ) { | |
| 544 | 415 | $this->options = get_theme_mod( $this->unique ); |
| 545 | - } elseif ( 'network' === $this->args['database'] ) { | |
| 416 | + } elseif ( $this->args['database'] === 'network' ) { | |
| 546 | 417 | $this->options = get_site_option( $this->unique ); |
| 547 | 418 | } else { |
| 548 | 419 | $this->options = get_option( $this->unique ); |
| 549 | 420 | } |
| @@ -556,17 +427,15 @@ | ||
| 556 | 427 | |
| 557 | 428 | } |
| 558 | 429 | |
| 559 | 430 | /** |
| 560 | - * WP api – admin menu. | |
| 431 | + * wp api: admin menu. | |
| 561 | 432 | */ |
| 562 | 433 | public function add_admin_menu() { |
| 563 | - // Show plugin setting menu as per user role. – ShapedPlugin | |
| 564 | - // Use the hook 'sp_pc_dashboard_capability' to change user capability. | |
| 565 | - $menu_capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' ); | |
| 434 | + | |
| 566 | 435 | extract( $this->args ); |
| 567 | 436 | |
| 568 | - if ( 'submenu' === $menu_type ) { | |
| 437 | + if ( $menu_type === 'submenu' ) { | |
| 569 | 438 | |
| 570 | 439 | $menu_page = call_user_func( 'add_submenu_page', $menu_parent, $menu_title, $menu_title, $menu_capability, $menu_slug, array( &$this, 'add_options_html' ) ); |
| 571 | 440 | |
| 572 | 441 | } else { |
| @@ -674,22 +543,22 @@ | ||
| 674 | 543 | $wrapper_class = ( $this->args['framework_class'] ) ? ' ' . $this->args['framework_class'] : ''; |
| 675 | 544 | $theme = ( $this->args['theme'] ) ? ' spf-theme-' . $this->args['theme'] : ''; |
| 676 | 545 | $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : ''; |
| 677 | 546 | |
| 678 | - echo '<div class="wrap"><h1>' . esc_html( $this->args['menu_title'] ) . '</h1></div>'; | |
| 679 | - echo '<div class="spf spf-options' . esc_attr( $theme ) . esc_attr( $class ) . esc_attr( $wrapper_class ) . '" data-slug="' . esc_attr( $this->args['menu_slug'] ) . '" data-unique="' . esc_attr( $this->unique ) . '">'; | |
| 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 . '">'; | |
| 680 | 549 | |
| 681 | 550 | $notice_class = ( ! empty( $this->notice ) ) ? ' spf-form-show' : ''; |
| 682 | 551 | $notice_text = ( ! empty( $this->notice ) ) ? $this->notice : ''; |
| 683 | 552 | |
| 684 | - echo '<div class="spf-form-result spf-form-success' . esc_attr( $notice_class ) . '">' . esc_html( $notice_text ) . '</div>'; | |
| 553 | + echo '<div class="spf-form-result spf-form-success' . $notice_class . '">' . $notice_text . '</div>'; | |
| 685 | 554 | |
| 686 | 555 | $error_class = ( ! empty( $this->errors ) ) ? ' spf-form-show' : ''; |
| 687 | 556 | |
| 688 | - echo '<div class="spf-form-result spf-form-error' . esc_attr( $error_class ) . '">'; | |
| 557 | + echo '<div class="spf-form-result spf-form-error' . $error_class . '">'; | |
| 689 | 558 | if ( ! empty( $this->errors ) ) { |
| 690 | 559 | foreach ( $this->errors as $error ) { |
| 691 | - echo '<i class="spf-label-error">!</i> ' . esc_html( $error ) . '<br />'; | |
| 560 | + echo '<i class="spf-label-error">!</i> ' . $error . '<br />'; | |
| 692 | 561 | } |
| 693 | 562 | } |
| 694 | 563 | echo '</div>'; |
| 695 | 564 | |
| @@ -713,9 +582,9 @@ | ||
| 713 | 582 | |
| 714 | 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>' : ''; |
| 715 | 584 | |
| 716 | 585 | echo '<div class="spf-buttons">'; |
| 717 | - echo '<input type="submit" name="' . esc_attr( $this->unique ) . '[_nonce][save]" class="button button-primary spf-save' . esc_attr( $ajax_class ) . '" value="' . esc_html__( 'Save', 'smart-post-show' ) . '" data-save="' . esc_html__( 'Saving...', 'smart-post-show' ) . '">'; | |
| 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' ) . '">'; | |
| 718 | 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' ) . '">' : ''; |
| 719 | 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' ) . '">' : ''; |
| 720 | 589 | echo '</div>'; |
| 721 | 590 | |
| @@ -724,9 +593,9 @@ | ||
| 724 | 593 | echo '<div class="clear"></div>'; |
| 725 | 594 | echo '</div>'; |
| 726 | 595 | echo '</div>'; |
| 727 | 596 | |
| 728 | - echo '<div class="spf-wrapper' . esc_attr( $show_all ) . '">'; | |
| 597 | + echo '<div class="spf-wrapper' . $show_all . '">'; | |
| 729 | 598 | |
| 730 | 599 | if ( $has_nav ) { |
| 731 | 600 | echo '<div class="spf-nav spf-nav-options">'; |
| 732 | 601 | |
| @@ -742,9 +611,9 @@ | ||
| 742 | 611 | if ( ! empty( $tab['subs'] ) ) { |
| 743 | 612 | |
| 744 | 613 | echo '<li class="spf-tab-depth-0">'; |
| 745 | 614 | |
| 746 | - echo '<a href="#tab=' . esc_attr( $tab_key ) . '" class="spf-arrow">' . wp_kses_post( $tab_icon ) . esc_html( $tab['title'] ) . esc_html( $tab_error ) . '</a>'; | |
| 615 | + echo '<a href="#tab=' . $tab_key . '" class="spf-arrow">' . $tab_icon . $tab['title'] . $tab_error . '</a>'; | |
| 747 | 616 | |
| 748 | 617 | echo '<ul>'; |
| 749 | 618 | |
| 750 | 619 | foreach ( $tab['subs'] as $sub ) { |
| @@ -751,9 +620,9 @@ | ||
| 751 | 620 | |
| 752 | 621 | $sub_error = $this->error_check( $sub ); |
| 753 | 622 | $sub_icon = ( ! empty( $sub['icon'] ) ) ? '<i class="' . $sub['icon'] . '"></i>' : ''; |
| 754 | 623 | |
| 755 | - echo '<li class="spf-tab-depth-1"><a id="spf-tab-link-' . esc_attr( $tab_key ) . '" href="#tab=' . esc_attr( $tab_key ) . '">' . wp_kses_post( $sub_icon ) . esc_html( $sub['title'] ) . esc_html( $sub_error ) . '</a></li>'; | |
| 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>'; | |
| 756 | 625 | |
| 757 | 626 | $tab_key++; |
| 758 | 627 | } |
| 759 | 628 | |
| @@ -762,9 +631,9 @@ | ||
| 762 | 631 | echo '</li>'; |
| 763 | 632 | |
| 764 | 633 | } else { |
| 765 | 634 | |
| 766 | - echo '<li class="spf-tab-depth-0"><a id="spf-tab-link-' . esc_attr( $tab_key ) . '" href="#tab=' . esc_attr( $tab_key ) . '">' . wp_kses_post( $tab_icon ) . esc_html( $tab['title'] ) . esc_html( $tab_error ) . '</a></li>'; | |
| 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>'; | |
| 767 | 636 | |
| 768 | 637 | $tab_key++; |
| 769 | 638 | } |
| 770 | 639 | } |
| @@ -785,11 +654,11 @@ | ||
| 785 | 654 | |
| 786 | 655 | $onload = ( ! $has_nav ) ? ' spf-onload' : ''; |
| 787 | 656 | $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="spf-icon ' . $section['icon'] . '"></i>' : ''; |
| 788 | 657 | |
| 789 | - echo '<div id="spf-section-' . esc_attr( $section_key ) . '" class="spf-section' . esc_attr( $onload ) . '">'; | |
| 790 | - echo ( $has_nav ) ? '<div class="spf-section-title"><h3>' . wp_kses_post( $section_icon ) . esc_html( $section['title'] ) . '</h3></div>' : ''; | |
| 791 | - echo ( ! empty( $section['description'] ) ) ? '<div class="spf-field spf-section-description">' . esc_html( $section['description'] ) . '</div>' : ''; | |
| 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>' : ''; | |
| 792 | 661 | |
| 793 | 662 | if ( ! empty( $section['fields'] ) ) { |
| 794 | 663 | |
| 795 | 664 | foreach ( $section['fields'] as $field ) { |
| @@ -830,14 +699,14 @@ | ||
| 830 | 699 | |
| 831 | 700 | echo '<div class="spf-footer">'; |
| 832 | 701 | |
| 833 | 702 | echo '<div class="spf-buttons">'; |
| 834 | - echo '<input type="submit" name="spf_transient[save]" class="button button-primary spf-save' . esc_attr( $ajax_class ) . '" value="' . esc_html__( 'Save', 'smart-post-show' ) . '" data-save="' . esc_html__( 'Saving...', 'smart-post-show' ) . '">'; | |
| 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' ) . '">'; | |
| 835 | 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' ) . '">' : ''; |
| 836 | 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' ) . '">' : ''; |
| 837 | 706 | echo '</div>'; |
| 838 | 707 | |
| 839 | - echo ( ! empty( $this->args['footer_text'] ) ) ? '<div class="spf-copyright">' . esc_html( $this->args['footer_text'] ) . '</div>' : ''; | |
| 708 | + echo ( ! empty( $this->args['footer_text'] ) ) ? '<div class="spf-copyright">' . $this->args['footer_text'] . '</div>' : ''; | |
| 840 | 709 | |
| 841 | 710 | echo '<div class="clear"></div>'; |
| 842 | 711 | echo '</div>'; |
| 843 | 712 | |
| @@ -848,9 +717,9 @@ | ||
| 848 | 717 | echo '</div>'; |
| 849 | 718 | |
| 850 | 719 | echo '<div class="clear"></div>'; |
| 851 | 720 | |
| 852 | - echo ( ! empty( $this->args['footer_after'] ) ) ? wp_kses_post( $this->args['footer_after'] ) : ''; | |
| 721 | + echo ( ! empty( $this->args['footer_after'] ) ) ? $this->args['footer_after'] : ''; | |
| 853 | 722 | |
| 854 | 723 | echo '</div>'; |
| 855 | 724 | |
| 856 | 725 | } |