PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
← All changes | admin/views/sp-framework/classes/options.class.php +174 -393 4.0.82.2.10 View file →
@@ -1,89 +1,28 @@
1 -<?php
1 +<?php if ( ! defined( 'ABSPATH' ) ) {
2 + die; } // Cannot access directly.
2 3 /**
3 - * The options class of the plugin.
4 4 *
5 - * @package Smart_Post_Show
6 - * @subpackage Smart_Post_Show/views/sp-framework/classes
5 + * Options Class
6 + *
7 + * @since 1.0.0
8 + * @version 1.0.0
7 9 */
8 -
9 -if ( ! defined( 'ABSPATH' ) ) {
10 - exit; // Exit if accessed directly.
11 -}
12 -
13 10 if ( ! class_exists( 'SP_PC_Options' ) ) {
14 - /**
15 - * Options Class
16 - *
17 - * @since 1.0.0
18 - * @version 1.0.0
19 - */
20 11 class SP_PC_Options extends SP_PC_Abstract {
21 12
22 - /**
23 - * Unique ID/Name
24 - *
25 - * @var string
26 - */
27 - public $unique = '';
28 - /**
29 - * Notice.
30 - *
31 - * @var string
32 - */
33 - public $notice = '';
34 - /**
35 - * Abstract.
36 - *
37 - * @var string
38 - */
39 - public $abstract = 'options';
40 - /**
41 - * Setions.
42 - *
43 - * @var array
44 - */
45 - public $sections = array();
46 - /**
47 - * Options
48 - *
49 - * @var array
50 - */
51 - public $options = array();
52 -
53 - /**
54 - * Errors.
55 - *
56 - * @var array
57 - */
58 - public $errors = array();
59 -
60 - /**
61 - * Pre tabs.
62 - *
63 - * @var array
64 - */
65 - public $pre_tabs = array();
66 -
67 - /**
68 - * Pre fields.
69 - *
70 - * @var array
71 - */
72 - public $pre_fields = array();
73 -
74 - /**
75 - * Pre sections.
76 - *
77 - * @var array
78 - */
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();
79 22 public $pre_sections = array();
80 23
81 - /**
82 - * Default arguments.
83 - *
84 - * @var array
85 - */
24 + // default args.
86 25 public $args = array(
87 26
88 27 // framework title.
89 28 'framework_title' => 'SPF Framework <small>by SP</small>',
@@ -92,9 +31,9 @@
92 31 // menu settings.
93 32 'menu_title' => '',
94 33 'menu_slug' => '',
95 34 'menu_type' => 'menu',
96 - // 'menu_capability' => 'manage_options', It's implemented in add_admin_menu()
35 + 'menu_capability' => 'manage_options',
97 36 'menu_icon' => null,
98 37 'menu_position' => null,
99 38 'menu_hidden' => false,
100 39 'menu_parent' => '',
@@ -147,14 +86,9 @@
147 86 'defaults' => array(),
148 87
149 88 );
150 89
151 - /**
152 - * Run framework construct.
153 - *
154 - * @param string $key The filter unique key.
155 - * @param array $params The parameters.
156 - */
90 + // run framework construct.
157 91 public function __construct( $key, $params = array() ) {
158 92
159 93 $this->unique = $key;
160 94 $this->args = apply_filters( "spf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
@@ -178,26 +112,16 @@
178 112 }
179 113
180 114 // wp enqeueu for typography and output css.
181 115 parent::__construct();
116 +
182 117 }
183 118
184 - /**
185 - * Instance.
186 - *
187 - * @param object $key The instance key.
188 - * @param array $params All the parameters.
189 - * @return mixed
190 - */
119 + // instance.
191 120 public static function instance( $key, $params = array() ) {
192 121 return new self( $key, $params );
193 122 }
194 - /**
195 - * Pre tabs.
196 - *
197 - * @param array $sections All the sections.
198 - * @return mixed
199 - */
123 +
200 124 public function pre_tabs( $sections ) {
201 125
202 126 $result = array();
203 127 $parents = array();
@@ -208,9 +132,9 @@
208 132 $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
209 133 $parents[ $section['parent'] ][] = $section;
210 134 unset( $sections[ $key ] );
211 135 }
212 - ++$count;
136 + $count++;
213 137 }
214 138
215 139 foreach ( $sections as $key => $section ) {
216 140 $section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
@@ -217,20 +141,14 @@
217 141 if ( ! empty( $section['id'] ) && ! empty( $parents[ $section['id'] ] ) ) {
218 142 $section['subs'] = wp_list_sort( $parents[ $section['id'] ], array( 'priority' => 'ASC' ), 'ASC', true );
219 143 }
220 144 $result[] = $section;
221 - ++$count;
145 + $count++;
222 146 }
223 147
224 148 return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true );
225 149 }
226 150
227 - /**
228 - * Pre fields method.
229 - *
230 - * @param array $sections The sections.
231 - * @return $result
232 - */
233 151 public function pre_fields( $sections ) {
234 152
235 153 $result = array();
236 154
@@ -244,14 +162,8 @@
244 162
245 163 return $result;
246 164 }
247 165
248 - /**
249 - * The pre sections.
250 - *
251 - * @param array $sections The sections.
252 - * @return mixed
253 - */
254 166 public function pre_sections( $sections ) {
255 167
256 168 $result = array();
257 169
@@ -268,14 +180,9 @@
268 180
269 181 return $result;
270 182 }
271 183
272 - /**
273 - * Add admin bar menu.
274 - *
275 - * @param object $wp_admin_bar The admin bar.
276 - * @return void
277 - */
184 + // add admin bar menu.
278 185 public function add_admin_bar_menu( $wp_admin_bar ) {
279 186
280 187 if ( ! empty( $this->args['show_bar_menu'] ) && empty( $this->args['menu_hidden'] ) ) {
281 188
@@ -315,47 +222,46 @@
315 222 )
316 223 );
317 224 }
318 225 }
226 +
319 227 }
320 228
321 - /**
322 - * Ajax save method.
323 - *
324 - * @return void
325 - */
326 229 public function ajax_save() {
327 230
328 - $result = $this->set_options( true );
329 - if ( ! $result ) {
330 - wp_send_json_error(
331 - array(
332 - 'success' => false,
333 - 'error' => esc_html__(
334 - 'Error while saving.',
335 - 'post-carousel'
336 - ),
337 - )
338 - );
231 + if ( ! empty( $_POST['data'] ) ) {
339 232
340 - } else {
341 - wp_send_json_success(
342 - array(
343 - 'success' => true,
344 - 'notice' => $this->notice,
345 - 'errors' => $this->errors,
346 - )
347 - );
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 + }
348 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 +
349 261 }
350 262
351 - /**
352 - * Get default value.
353 - *
354 - * @param array $field The field array.
355 - * @param array $options The options array.
356 - * @return mixed
357 - */
263 + // get default value
358 264 public function get_default( $field, $options = array() ) {
359 265
360 266 $default = ( isset( $this->args['defaults'][ $field['id'] ] ) ) ? $this->args['defaults'][ $field['id'] ] : '';
361 267 $default = ( isset( $field['default'] ) ) ? $field['default'] : $default;
@@ -361,15 +267,12 @@
361 267 $default = ( isset( $field['default'] ) ) ? $field['default'] : $default;
362 268 $default = ( isset( $options[ $field['id'] ] ) ) ? $options[ $field['id'] ] : $default;
363 269
364 270 return $default;
271 +
365 272 }
366 273
367 - /**
368 - * Save defaults and set new fields value to main options.
369 - *
370 - * @return void
371 - */
274 + // save defaults and set new fields value to main options.
372 275 public function save_defaults() {
373 276
374 277 $tmp_options = $this->options;
375 278
@@ -381,233 +284,137 @@
381 284
382 285 if ( $this->args['save_defaults'] && empty( $tmp_options ) ) {
383 286 $this->save_options( $this->options );
384 287 }
288 +
385 289 }
386 290
387 - /**
388 - * Sanitize Smart Post Show plugin options.
389 - *
390 - * @param array $options Raw options array.
391 - * @return array Sanitized options array.
392 - */
393 - public function sanitize_options( $options ) {
394 - if ( ! is_array( $options ) ) {
395 - return array();
396 - }
291 + // set options.
292 + public function set_options() {
397 293
398 - $sanitized = array();
294 + if ( wp_verify_nonce( spf_get_var( 'spf_options_nonce' . $this->unique ), 'spf_options_nonce' ) ) {
399 295
400 - foreach ( $options as $key => $value ) {
401 - switch ( $key ) {
402 - case 'spf_transient':
403 - // Handle nested array.
404 - $sanitized['spf_transient'] = array();
405 - if ( is_array( $value ) ) {
406 - foreach ( $value as $sub_key => $sub_val ) {
407 - switch ( $sub_key ) {
408 - case 'section':
409 - $sanitized['spf_transient']['section'] = sanitize_text_field( $sub_val );
410 - break;
411 - default:
412 - $sanitized['spf_transient'][ $sub_key ] = sanitize_text_field( $sub_val );
413 - break;
414 - }
415 - }
416 - }
417 - break;
418 - case 'spf_options_noncesp_post_carousel_settings':
419 - case '_wp_http_referer':
420 - $sanitized[ $key ] = sanitize_text_field( $value );
421 - break;
422 - case 'sp_post_carousel_settings':
423 - $sanitized['sp_post_carousel_settings'] = array();
424 - if ( is_array( $value ) ) {
425 - foreach ( $value as $sub_key => $sub_val ) {
426 - switch ( $sub_key ) {
427 - case 'pcp_delete_all_data':
428 - case 'pcp_swiper_js':
429 - case 'pcp_swiper_css':
430 - case 'pcp_fontawesome_css':
431 - case 'accessibility':
432 - // These should be boolean-like (0/1).
433 - $sanitized['sp_post_carousel_settings'][ $sub_key ] = (int) $sub_val;
434 - break;
296 + $request = spf_get_var( $this->unique, array() );
297 + $transient = spf_get_var( 'spf_transient' );
298 + $section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : '';
435 299
436 - case 'prev_slide_message':
437 - case 'next_slide_message':
438 - case 'first_slide_message':
439 - case 'last_slide_message':
440 - case 'pagination_bullet_message':
441 - $sanitized['sp_post_carousel_settings'][ $sub_key ] = sanitize_text_field( $sub_val );
442 - break;
300 + // import data.
301 + if ( ! empty( $transient['spf_import_data'] ) ) {
443 302
444 - case 'pcp_custom_css':
445 - $sanitized['sp_post_carousel_settings'][ $sub_key ] = wp_strip_all_tags( $sub_val );
446 - break;
447 - case 'pcp_custom_js':
448 - $sanitized['sp_post_carousel_settings'][ $sub_key ] = wp_kses_post( $sub_val );
449 - break;
450 - default:
451 - $sanitized['sp_post_carousel_settings'][ $sub_key ] = sanitize_text_field( $sub_val );
452 - break;
453 - }
454 - }
455 - }
456 - break;
457 - default:
458 - // Fallback sanitization.
459 - $sanitized[ $key ] = is_scalar( $value ) ? wp_kses_post( $value ) : '';
460 - break;
461 - }
462 - }
303 + $import_data = json_decode( stripslashes( trim( $transient['spf_import_data'] ) ), true );
304 + $request = ( is_array( $import_data ) ) ? $import_data : array();
463 305
464 - return $sanitized;
465 - }
306 + $this->notice = esc_html__( 'Success. Imported backup options.', 'smart-post-show' );
466 307
308 + } elseif ( ! empty( $transient['reset'] ) ) {
467 309
310 + foreach ( $this->pre_fields as $field ) {
311 + if ( ! empty( $field['id'] ) ) {
312 + $request[ $field['id'] ] = $this->get_default( $field );
313 + }
314 + }
468 315
316 + $this->notice = esc_html__( 'Default options restored.', 'smart-post-show' );
469 317
470 - /**
471 - * Set options.
472 - *
473 - * @param boolean $ajax The ajax save.
474 - *
475 - * @return mixed
476 - */
477 - public function set_options( $ajax = false ) {
478 - // Check nonce.
479 - $nonce = $ajax && ( ! empty( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ( ( ! empty( $_POST[ 'spf_options_nonce' . $this->unique ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'spf_options_nonce' . $this->unique ] ) ) : '' );
480 - if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'spf_options_nonce' ) ) {
481 - return false;
482 - }
483 - // XSS ok.
484 - // No worries, This "POST" requests is sanitizing in the below.
485 - $response = ( $ajax && ! empty( $_POST['data'] ) ) ? json_decode( wp_unslash( trim( $_POST['data'] ) ), true ) : wp_unslash( $_POST ); // phpcs:ignore -- Sanitized below.
486 - $response = $this->sanitize_options( $response ); // Sanitize json response.
487 - // Set variables.
488 - $data = array();
489 - $options = ( ! empty( $response[ $this->unique ] ) ) ? $response[ $this->unique ] : array();
490 - $transient = ( ! empty( $response['spf_transient'] ) ) ? $response['spf_transient'] : array();
491 - $importing = false;
492 - $section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : '';
318 + } elseif ( ! empty( $transient['reset_section'] ) && ! empty( $section_id ) ) {
493 319
494 - if ( ! empty( $transient['reset'] ) ) {
320 + if ( ! empty( $this->pre_sections[ $section_id - 1 ]['fields'] ) ) {
495 321
496 - foreach ( $this->pre_fields as $field ) {
497 - if ( ! empty( $field['id'] ) ) {
498 - $data[ $field['id'] ] = $this->get_default( $field );
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 + }
499 327 }
500 - }
501 328
502 - $this->notice = esc_html__( 'Default options restored.', 'post-carousel' );
329 + $this->notice = esc_html__( 'Default options restored for only this section.', 'smart-post-show' );
503 330
504 - } elseif ( ! empty( $transient['reset_section'] ) && ! empty( $section_id ) ) {
331 + } else {
505 332
506 - if ( ! empty( $this->pre_sections[ $section_id - 1 ]['fields'] ) ) {
333 + // sanitize and validate.
334 + foreach ( $this->pre_fields as $field ) {
507 335
508 - foreach ( $this->pre_sections[ $section_id - 1 ]['fields'] as $field ) {
509 336 if ( ! empty( $field['id'] ) ) {
510 - $data[ $field['id'] ] = $this->get_default( $field );
511 - }
512 - }
513 - }
514 337
515 - $data = wp_parse_args( $data, $this->options );
516 - $this->notice = esc_html__( 'Default options restored for only this section.', 'post-carousel' );
338 + // sanitize.
339 + if ( ! empty( $field['sanitize'] ) ) {
517 340
518 - } else {
519 - // Sanitize and validate.
520 - foreach ( $this->pre_fields as $field ) {
341 + $sanitize = $field['sanitize'];
342 + $value_sanitize = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : '';
343 + $request[ $field['id'] ] = call_user_func( $sanitize, $value_sanitize );
521 344
522 - if ( ! empty( $field['id'] ) ) {
345 + }
523 346
524 - $field_id = $field['id'];
525 - $field_value = isset( $options[ $field_id ] ) ? $options[ $field_id ] : '';
347 + // validate.
348 + if ( ! empty( $field['validate'] ) ) {
526 349
527 - // Ajax and Importing doing wp_unslash already.
528 - if ( ! $ajax && ! $importing ) {
529 - $field_value = wp_unslash( $field_value );
530 - }
350 + $value_validate = isset( $request[ $field['id'] ] ) ? $request[ $field['id'] ] : '';
351 + $has_validated = call_user_func( $field['validate'], $value_validate );
531 352
532 - // sanitize.
533 - if ( ! isset( $field['sanitize'] ) ) {
534 - if ( is_array( $field_value ) ) {
535 - $data[ $field_id ] = wp_kses_post_deep( $field_value );
536 - } else {
537 - $data[ $field_id ] = wp_kses_post( $field_value );
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 + }
538 357 }
539 - } elseif ( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
540 - $data[ $field_id ] = call_user_func( $field['sanitize'], $field_value );
541 358
542 - } else {
543 - $data[ $field_id ] = wp_kses_post( $field_value );
544 -
545 - }
546 -
547 - // Validate "post" request of field.
548 - if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
549 -
550 - $has_validated = call_user_func( $field['validate'], $field_value );
551 -
552 - if ( ! empty( $has_validated ) ) {
553 - $data[ $field_id ] = ( isset( $this->options[ $field_id ] ) ) ? $this->options[ $field_id ] : '';
554 - $this->errors[ $field_id ] = $has_validated;
359 + // auto sanitize.
360 + if ( ! isset( $request[ $field['id'] ] ) || is_null( $request[ $field['id'] ] ) ) {
361 + $request[ $field['id'] ] = '';
555 362 }
556 363 }
557 364 }
558 365 }
559 - }
560 366
561 - $data = apply_filters( "spf_{$this->unique}_save", $data, $this );
367 + // ignore nonce requests.
368 + if ( isset( $request['_nonce'] ) ) {
369 + unset( $request['_nonce'] ); }
562 370
563 - do_action( "spf_{$this->unique}_save_before", $data, $this );
371 + $request = wp_unslash( $request );
564 372
565 - $this->options = $data;
373 + $request = apply_filters( "spf_{$this->unique}_save", $request, $this );
566 374
567 - $this->save_options( $data );
375 + do_action( "spf_{$this->unique}_save_before", $request, $this );
568 376
569 - do_action( "spf_{$this->unique}_save_after", $data, $this );
377 + $this->options = $request;
570 378
571 - if ( empty( $this->notice ) ) {
572 - $this->notice = esc_html__( 'Settings saved.', 'post-carousel' );
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 + }
573 386 }
574 387
575 388 return true;
389 +
576 390 }
577 - /**
578 - * Save options database.
579 - *
580 - * @param array $data The options values.
581 - * @return void
582 - */
583 - public function save_options( $data ) {
584 391
585 - if ( 'transient' === $this->args['database'] ) {
586 - set_transient( $this->unique, $data, $this->args['transient_time'] );
587 - } elseif ( 'theme_mod' === $this->args['database'] ) {
588 - set_theme_mod( $this->unique, $data );
589 - } elseif ( 'network' === $this->args['database'] ) {
590 - update_site_option( $this->unique, $data );
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 );
591 401 } else {
592 - update_option( $this->unique, $data );
402 + update_option( $this->unique, $request );
593 403 }
594 404
595 - do_action( "spf_{$this->unique}_saved", $data, $this );
405 + do_action( "spf_{$this->unique}_saved", $request, $this );
406 +
596 407 }
597 408
598 - /**
599 - * Get options from database.
600 - *
601 - * @return mixed
602 - */
409 + // get options from database.
603 410 public function get_options() {
604 411
605 - if ( 'transient' === $this->args['database'] ) {
412 + if ( $this->args['database'] === 'transient' ) {
606 413 $this->options = get_transient( $this->unique );
607 - } elseif ( 'theme_mod' === $this->args['database'] ) {
414 + } elseif ( $this->args['database'] === 'theme_mod' ) {
608 415 $this->options = get_theme_mod( $this->unique );
609 - } elseif ( 'network' === $this->args['database'] ) {
416 + } elseif ( $this->args['database'] === 'network' ) {
610 417 $this->options = get_site_option( $this->unique );
611 418 } else {
612 419 $this->options = get_option( $this->unique );
613 420 }
@@ -616,21 +423,20 @@
616 423 $this->options = array();
617 424 }
618 425
619 426 return $this->options;
427 +
620 428 }
621 429
622 430 /**
623 - * WP api – admin menu.
431 + * wp api: admin menu.
624 432 */
625 433 public function add_admin_menu() {
626 - // Show plugin setting menu as per user role. – ShapedPlugin
627 - // Use the hook 'sp_pc_dashboard_capability' to change user capability.
628 - $menu_capability = apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
629 - extract( $this->args ); // phpcs:ignore
630 434
631 - if ( 'submenu' === $menu_type ) {
435 + extract( $this->args );
632 436
437 + if ( $menu_type === 'submenu' ) {
438 +
633 439 $menu_page = call_user_func( 'add_submenu_page', $menu_parent, $menu_title, $menu_title, $menu_capability, $menu_slug, array( &$this, 'add_options_html' ) );
634 440
635 441 } else {
636 442
@@ -647,9 +453,9 @@
647 453 if ( ! empty( $section['subs'] ) ) {
648 454 $tab_key += ( count( $section['subs'] ) - 1 );
649 455 }
650 456
651 - ++$tab_key;
457 + $tab_key++;
652 458
653 459 }
654 460
655 461 remove_submenu_page( $menu_slug, $menu_slug );
@@ -661,8 +467,9 @@
661 467 }
662 468 }
663 469
664 470 add_action( 'load-' . $menu_page, array( &$this, 'add_page_on_load' ) );
471 +
665 472 }
666 473
667 474 /**
668 475 * Add page on load.
@@ -680,8 +487,9 @@
680 487 if ( ! empty( $this->args['contextual_help_sidebar'] ) ) {
681 488 $screen->set_help_sidebar( $this->args['contextual_help_sidebar'] );
682 489 }
683 490 }
491 +
684 492 }
685 493
686 494 /**
687 495 * Error check function.
@@ -729,10 +537,8 @@
729 537 public function add_options_html() {
730 538
731 539 $has_nav = ( count( $this->pre_tabs ) > 1 ) ? true : false;
732 540 $show_all = ( ! $has_nav ) ? ' spf-show-all' : '';
733 - $show_buttons = isset( $this->args['show_buttons'] ) ? $this->args['show_buttons'] : true;
734 - $menu_slug = isset( $this->args['menu_slug'] ) ? $this->args['menu_slug'] : '';
735 541 $ajax_class = ( $this->args['ajax_save'] ) ? ' spf-save-ajax' : '';
736 542 $sticky_class = ( $this->args['sticky_header'] ) ? ' spf-sticky-header' : '';
737 543 $wrapper_class = ( $this->args['framework_class'] ) ? ' ' . $this->args['framework_class'] : '';
738 544 $theme = ( $this->args['theme'] ) ? ' spf-theme-' . $this->args['theme'] : '';
@@ -737,28 +543,22 @@
737 543 $wrapper_class = ( $this->args['framework_class'] ) ? ' ' . $this->args['framework_class'] : '';
738 544 $theme = ( $this->args['theme'] ) ? ' spf-theme-' . $this->args['theme'] : '';
739 545 $class = ( $this->args['class'] ) ? ' ' . $this->args['class'] : '';
740 546
741 - if ( 'pcp_replace_layout' === $menu_slug ) {
742 - echo '<div class="wrap pcp_replace_layout_notice"><p class="spf-text-desc">To unlock the Replace Layout on The Default Blog, WooCommerce Shop, Category, Tag, Taxonomy, Search, Author, Date... Pages, and Post Types, <a target="__blank" href="https://wpsmartpost.com/pricing/?ref=1"><b>Upgrade To Pro</b></a></p></div>';
743 - }
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 . '">';
744 549
745 - 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 ) . '">';
746 -
747 - if ( 'pcp_replace_layout' === $menu_slug ) {
748 - echo '<div class="sp-smart-post-upgrade-to-pro-button">
749 - <a href="https://wpsmartpost.com/pricing/?ref=1" target="_blank">Upgrade to Pro!</a>
750 - </div>';
751 - }
752 550 $notice_class = ( ! empty( $this->notice ) ) ? ' spf-form-show' : '';
753 551 $notice_text = ( ! empty( $this->notice ) ) ? $this->notice : '';
754 552
553 + echo '<div class="spf-form-result spf-form-success' . $notice_class . '">' . $notice_text . '</div>';
554 +
755 555 $error_class = ( ! empty( $this->errors ) ) ? ' spf-form-show' : '';
756 556
757 - 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 . '">';
758 558 if ( ! empty( $this->errors ) ) {
759 559 foreach ( $this->errors as $error ) {
760 - echo '<i class="spf-label-error">!</i> ' . esc_html( $error ) . '<br />';
560 + echo '<i class="spf-label-error">!</i> ' . $error . '<br />';
761 561 }
762 562 }
763 563 echo '</div>';
764 564
@@ -772,41 +572,30 @@
772 572 echo '<div class="spf-header' . esc_attr( $sticky_class ) . '">';
773 573 echo '<div class="spf-header-inner">';
774 574
775 575 echo '<div class="spf-header-left">';
776 - if ( 'pcp_replace_layout' === $menu_slug ) {
777 - echo '<h1><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
778 - <style type="text/css">
779 - .st0{fill:#D64224;}
780 - </style>
781 - <path class="st0" d="M0,69.3V0h69.4v18.6H18.6v50.7L0,69.3L0,69.3z M100,100H30.6V30.7H100V100z"/>
782 - </svg>' . esc_html__( 'Replace Layout (Pro)', 'post-carousel' ) . '</h1>';
783 - } elseif ( $show_buttons ) {
784 - echo '<h1><svg width="30" height="30" viewBox="0 0 800 800" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 100C0 44.772 44.772 0 100 0h600c55.229 0 100 44.772 100 100v600c0 55.229-44.771 100-100 100H100C44.772 800 0 755.229 0 700z" fill="url(#a)"/><path d="M115.997 471.75c0-24.162 19.587-43.75 43.749-43.75h164.498c24.162 0 43.75 19.588 43.75 43.75v164.5c0 24.163-19.588 43.75-43.75 43.75H159.746c-24.162 0-43.749-19.587-43.749-43.75zM423.993 246c0-69.588 56.411-126 125.998-126s125.998 56.412 125.998 126-56.411 126-125.998 126-125.998-56.412-125.998-126m-307.996-82.25c0-24.162 19.587-43.75 43.749-43.75h164.498c24.162 0 43.75 19.588 43.75 43.75v164.5c0 24.163-19.588 43.75-43.75 43.75H159.746c-24.162 0-43.749-19.587-43.749-43.75zm308.006 301.584c0-10.309 8.357-18.666 18.667-18.666h214.663c10.309 0 18.666 8.357 18.666 18.666s-8.357 18.667-18.666 18.667H442.67c-10.31 0-18.667-8.357-18.667-18.667m0 88.534c0-10.31 8.357-18.667 18.667-18.667h214.663c10.309 0 18.666 8.357 18.666 18.667 0 10.309-8.357 18.666-18.666 18.666H442.67c-10.31 0-18.667-8.357-18.667-18.666m0 88.533c0-10.309 8.357-18.667 18.667-18.667h214.663c10.309 0 18.666 8.358 18.666 18.667s-8.357 18.667-18.666 18.667H442.67c-10.31 0-18.667-8.358-18.667-18.667" fill="#fff"/><defs><linearGradient id="a" x1="400" y1="0" x2="400" y2="800" gradientUnits="userSpaceOnUse"><stop stop-color="#e1624b"/><stop offset="1" stop-color="#e1624b"/></linearGradient></defs></svg>' . esc_html__( 'Settings', 'post-carousel' ) . '</h1>';
785 - } else {
786 - echo '<h1 class="export-import"><img src="' . esc_url( SP_PC_URL ) . 'admin/assets/img/import-export.svg">' . esc_html( $this->args['framework_title'] ) . '</h1>';
787 - }
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>';
788 577 echo '</div>';
789 578
790 579 echo '<div class="spf-header-right">';
791 580
792 - echo ( $has_nav && $this->args['show_all_options'] ) ? '<div class="spf-expand-all" title="' . esc_html__( 'show all options', 'post-carousel' ) . '"><i class="fa fa-outdent"></i></div>' : '';
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>' : '';
793 582
794 - echo ( $this->args['show_search'] ) ? '<div class="spf-search"><input type="text" name="spf-search" placeholder="' . esc_html__( 'Search option(s)', 'post-carousel' ) . '" autocomplete="off" /></div>' : '';
795 - if ( $show_buttons ) {
796 - echo '<div class="spf-buttons">';
797 - 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 Settings', 'post-carousel' ) . '" data-save="' . esc_html__( 'Saving...', 'post-carousel' ) . '">';
798 - 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 Tab', 'post-carousel' ) . '" data-confirm="' . esc_html__( 'Are you sure you want to reset all settings to default values?', 'post-carousel' ) . '">' : '';
799 - 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', 'post-carousel' ) . '" data-confirm="' . esc_html__( 'Are you sure to reset all options?', 'post-carousel' ) . '">' : '';
800 - echo '</div>';
801 - }
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' ) . '">' : '';
802 589 echo '</div>';
803 590
591 + echo '</div>';
592 +
804 593 echo '<div class="clear"></div>';
805 594 echo '</div>';
806 595 echo '</div>';
807 596
808 - echo '<div class="spf-wrapper' . esc_attr( $show_all ) . '">';
597 + echo '<div class="spf-wrapper' . $show_all . '">';
809 598
810 599 if ( $has_nav ) {
811 600 echo '<div class="spf-nav spf-nav-options">';
812 601
@@ -822,9 +611,9 @@
822 611 if ( ! empty( $tab['subs'] ) ) {
823 612
824 613 echo '<li class="spf-tab-depth-0">';
825 614
826 - 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>';
827 616
828 617 echo '<ul>';
829 618
830 619 foreach ( $tab['subs'] as $sub ) {
@@ -831,11 +620,11 @@
831 620
832 621 $sub_error = $this->error_check( $sub );
833 622 $sub_icon = ( ! empty( $sub['icon'] ) ) ? '<i class="' . $sub['icon'] . '"></i>' : '';
834 623
835 - 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>';
836 625
837 - ++$tab_key;
626 + $tab_key++;
838 627 }
839 628
840 629 echo '</ul>';
841 630
@@ -842,11 +631,11 @@
842 631 echo '</li>';
843 632
844 633 } else {
845 634
846 - 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>';
847 636
848 - ++$tab_key;
637 + $tab_key++;
849 638 }
850 639 }
851 640
852 641 echo '</ul>';
@@ -865,11 +654,11 @@
865 654
866 655 $onload = ( ! $has_nav ) ? ' spf-onload' : '';
867 656 $section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="spf-icon ' . $section['icon'] . '"></i>' : '';
868 657
869 - echo '<div id="spf-section-' . esc_attr( $section_key ) . '" class="spf-section' . esc_attr( $onload ) . '">';
870 - echo ( $has_nav ) ? '<div class="spf-section-title"><h3>' . wp_kses_post( $section_icon ) . esc_html( $section['title'] ) . '</h3></div>' : '';
871 - 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>' : '';
872 661
873 662 if ( ! empty( $section['fields'] ) ) {
874 663
875 664 foreach ( $section['fields'] as $field ) {
@@ -886,15 +675,15 @@
886 675
887 676 }
888 677 } else {
889 678
890 - echo '<div class="spf-no-option spf-text-muted">' . esc_html__( 'No option provided by developer.', 'post-carousel' ) . '</div>';
679 + echo '<div class="spf-no-option spf-text-muted">' . esc_html__( 'No option provided by developer.', 'smart-post-show' ) . '</div>';
891 680
892 681 }
893 682
894 683 echo '</div>';
895 684
896 - ++$section_key;
685 + $section_key++;
897 686 }
898 687
899 688 echo '</div>';
900 689
@@ -910,14 +699,14 @@
910 699
911 700 echo '<div class="spf-footer">';
912 701
913 702 echo '<div class="spf-buttons">';
914 - echo '<input type="submit" name="spf_transient[save]" class="button button-primary spf-save' . esc_attr( $ajax_class ) . '" value="' . esc_html__( 'Save', 'post-carousel' ) . '" data-save="' . esc_html__( 'Saving...', 'post-carousel' ) . '">';
915 - 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', 'post-carousel' ) . '" data-confirm="' . esc_html__( 'Are you sure to reset this section options?', 'post-carousel' ) . '">' : '';
916 - 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', 'post-carousel' ) . '" data-confirm="' . esc_html__( 'Are you sure to reset all options?', 'post-carousel' ) . '">' : '';
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' ) . '">' : '';
917 706 echo '</div>';
918 707
919 - 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>' : '';
920 709
921 710 echo '<div class="clear"></div>';
922 711 echo '</div>';
923 712
@@ -928,19 +717,11 @@
928 717 echo '</div>';
929 718
930 719 echo '<div class="clear"></div>';
931 720
932 - echo ( ! empty( $this->args['footer_after'] ) ) ? wp_kses_post( $this->args['footer_after'] ) : '';
721 + echo ( ! empty( $this->args['footer_after'] ) ) ? $this->args['footer_after'] : '';
933 722
934 723 echo '</div>';
935 724
936 - if ( 'pcp_settings' === $menu_slug ) {
937 - echo '<a href="' . esc_url( admin_url( 'edit.php?post_type=sp_post_carousel&page=pcp_help#settings' ) ) . '" rel="noopener noreferrer" class="sp-pcp-classic-settings-page-link">
938 - Back to Block Settings
939 - <span class="sp-pcp-classic-settings-page-link-arrow">
940 - <img src="' . esc_url( SP_PC_URL ) . 'admin/views/sp-framework/assets/img/block-settings-arrow.svg">
941 - </span>
942 - </a>';
943 - }
944 725 }
945 726 }
946 727 }