PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / framework / class-settings-page.php

class-settings-page.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/framework/class-settings-page.php

761 lines 29.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WeDevs\ERP\Framework;
4
5 /**
6 * Erp Settings page main class
7 */
8 class ERP_Settings_Page {
9
10 protected $id = '';
11 protected $label = '';
12 protected $single_option = false;
13 protected $section_fields = [];
14
15 /**
16 * Get id
17 *
18 * @return string
19 */
20 public function get_id() {
21 return $this->id;
22 }
23
24 /**
25 * Get saved option id
26 *
27 * @return string
28 */
29 public function get_option_id() {
30 $option_id = 'erp_settings_' . $this->id;
31
32 if ( $sections = $this->get_sections() ) {
33
34 if ( isset( $_REQUEST['section'] ) && array_key_exists( $_REQUEST['section'], $sections ) ) {
35 $current_section = $_REQUEST['section'];
36 $option_id = 'erp_settings_' . $this->id . '_' . $current_section;
37 } else {
38 $option_id = 'erp_settings_' . $this->id . '_' . strtolower( reset( $sections ) ); // section's first element
39 }
40 }
41
42 return $option_id;
43 }
44
45 /**
46 * Get label
47 *
48 * @return string
49 */
50 public function get_label() {
51 return $this->label;
52 }
53
54 /**
55 * Get settings array
56 *
57 * @return array
58 */
59 public function get_settings() {
60 return array();
61 }
62
63
64 public function save( $section = false ) {
65 global $current_class;
66
67 if ( isset( $_POST['_wpnonce']) && wp_verify_nonce( $_POST['_wpnonce'], 'erp-settings-nonce' ) ) {
68
69 $from_sections = false;
70
71 if ( isset( $this->sections ) && is_array( $this->sections ) && count( $this->sections ) ) {
72 $options = $this->get_section_fields($section);
73 $from_sections = true;
74 } else {
75 $options = $this->get_settings();
76 }
77
78 // Options to update will be stored here
79 $update_options = array();
80
81 // Loop options and get values to save
82 foreach ( $options as $value ) {
83
84 if ( ! isset( $value['id'] ) )
85 continue;
86
87 $option_value = $this->parse_option_value( $value );
88
89 if ( ! is_null( $option_value ) ) {
90 // Check if option is an array
91 if ( strstr( $value['id'], '[' ) ) {
92
93 parse_str( $value['id'], $option_array );
94
95 // Option name is first key
96 $option_name = current( array_keys( $option_array ) );
97
98 // Get old option value
99 if ( ! isset( $update_options[ $option_name ] ) )
100 $update_options[ $option_name ] = get_option( $option_name, array() );
101
102 if ( ! is_array( $update_options[ $option_name ] ) )
103 $update_options[ $option_name ] = array();
104
105 // Set keys and value
106 $key = key( $option_array[ $option_name ] );
107
108 $update_options[ $option_name ][ $key ] = $option_value;
109
110 // Single value
111 } else {
112 $update_options[ $value['id'] ] = $option_value;
113 }
114 }
115
116 // Custom handling
117 do_action( 'erp_update_option', $value );
118 }
119
120 // finally, update the option
121 if ( $update_options ) {
122
123 if ( $this->single_option ) {
124
125 foreach ( $update_options as $name => $value ) {
126 update_option( $name, $value );
127 }
128
129 } else {
130 update_option( $this->get_option_id(), $update_options );
131 }
132 }
133
134 do_action( 'erp_after_save_settings' );
135 }
136 }
137
138 function parse_option_value( $value ) {
139 $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
140 $option_value = null;
141
142 switch ( $type ) {
143
144 // Standard types
145 case "checkbox" :
146
147 if ( isset( $_POST[ $value['id'] ] ) ) {
148 $option_value = 'yes';
149 } else {
150 $option_value = 'no';
151 }
152
153 break;
154
155 case "textarea" :
156 case "wysiwyg" :
157
158 if ( isset( $_POST[$value['id']] ) ) {
159 $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) );
160 } else {
161 $option_value = '';
162 }
163
164 break;
165
166 case 'multicheck':
167
168 if ( isset( $_POST[$value['id']] ) ) {
169 $option_value = array_map( 'sanitize_text_field', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
170 } else {
171 $option_value = array();
172 }
173
174 break;
175
176 case "text" :
177 case 'email':
178 case 'number':
179 case "select" :
180 case "color" :
181 case 'password' :
182 case "single_select_page" :
183 case "image" :
184 case 'radio' :
185 case 'hidden' :
186
187 if ( isset( $_POST[$value['id']] ) ) {
188 $option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) );
189 } else {
190 $option_value = '';
191 }
192
193 break;
194
195 // Special types
196 case "multiselect" :
197
198 // Get countries array
199 if ( isset( $_POST[ $value['id'] ] ) )
200 $selected_countries = array_map( 'sanitize_text_field', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
201 else
202 $selected_countries = array();
203
204 $option_value = $selected_countries;
205
206 break;
207
208 // Custom handling
209 default :
210
211 do_action( 'erp_update_option_' . $type, $value );
212
213 break;
214
215 }
216
217 return $option_value;
218 }
219
220 /**
221 * Get sections
222 *
223 * @return array
224 */
225 public function get_sections() {
226 return array();
227 }
228
229 /**
230 * Get sections
231 *
232 * @return array
233 */
234 public function get_section_fields( $section = false ) {
235 return array();
236 }
237
238 public function get_section_field_items() {
239 return $this->section_fields;
240 }
241
242 public function output( $section = false ) {
243 $fields = $this->get_settings();
244 $sections = $this->get_sections();
245 $section_fields = $this->get_section_fields($section);
246 $query_arg = ERP_Admin_Settings::get_current_tab_and_section();
247
248 if ( count( $sections ) && $query_arg['subtab'] ) {
249 if ( ! array_key_exists( $query_arg['subtab'], $sections ) ) {
250 return;
251 }
252
253 $fields = $section_fields;
254 }
255
256 if ( $fields ) {
257 $this->section_fields = $fields;
258 $this->output_fields( $fields );
259 }
260 }
261
262 function output_fields( $fields ) {
263 $defaults = array(
264 'id' => '',
265 'title' => '',
266 'class' => '',
267 'css' => '',
268 'default' => '',
269 'desc' => '',
270 'tooltip' => false,
271 'custom_attributes' => array()
272 );
273
274 foreach ($fields as $field) {
275
276 if ( ! isset( $field['type'] ) ) {
277 continue;
278 }
279
280 $value = wp_parse_args( $field, $defaults );
281
282 // Custom attribute handling
283 $custom_attributes = array();
284
285 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
286 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
287 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
288 }
289 }
290
291 // Description handling
292 if ( $value['tooltip'] === true ) {
293 $description = '';
294 $tip = $value['desc'];
295 } elseif ( ! empty( $value['tooltip'] ) ) {
296 $description = $value['desc'];
297 $tip = $value['tooltip'];
298 } elseif ( ! empty( $value['desc'] ) ) {
299 $description = $value['desc'];
300 $tip = '';
301 } else {
302 $description = $tip = '';
303 }
304
305 if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
306 $description = '<p class="description">' . wp_kses_post( $description ) . '</p>';
307 } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
308 $description = wp_kses_post( $description );
309 } elseif ( $description ) {
310 $description = '<p class="description">' . wp_kses_post( $description ) . '</p>';
311 }
312
313 if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
314
315 $tip = '<p class="description">' . $tip . '</p>';
316
317 } elseif ( $tip ) {
318
319 $tip = '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . WPERP_ASSETS . '/images/help.png" height="16" width="16" />';
320
321 }
322
323 // Switch based on type
324 switch( $value['type'] ) {
325
326 // Section Titles
327 case 'title':
328 if ( ! empty( $value['title'] ) ) {
329 echo '<h3>' . esc_html( $value['title'] ) . '</h3>';
330 }
331 if ( ! empty( $value['desc'] ) ) {
332 echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
333 }
334 echo '<table class="form-table">'. "\n\n";
335 if ( ! empty( $value['id'] ) ) {
336 do_action( 'erp_settings_' . sanitize_title( $value['id'] ) );
337 }
338 break;
339
340 // Section Ends
341 case 'sectionend':
342 if ( ! empty( $value['id'] ) ) {
343 do_action( 'erp_settings_' . sanitize_title( $value['id'] ) . '_end' );
344 }
345 echo '</table>';
346
347 if ( ! empty( $value['id'] ) ) {
348 do_action( 'erp_settings_' . sanitize_title( $value['id'] ) . '_after' );
349 }
350 break;
351
352 // Standard text inputs and subtypes like 'number'
353 case 'text':
354 case 'email':
355 case 'number':
356 case 'color' :
357 case 'password' :
358 case 'hidden' :
359
360 $type = $value['type'];
361 $class = '';
362 $option_value = $this->get_option( $value['id'], $value['default'] );
363
364 if ( empty( $value['class'] ) ) {
365 $value['class'] = 'regular-text';
366 }
367
368 if ( $value['type'] == 'color' ) {
369 $type = 'text';
370 $value['class'] .= 'colorpick';
371 }
372
373 ?><tr valign="top">
374 <th scope="row" class="titledesc">
375 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
376 <?php echo $tip; ?>
377 </th>
378 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
379 <?php if ( ! empty( $value['title_before_field'] ) ): ?>
380 <h4 class="erp-settings-title-before-field"><?php echo $value['title_before_field']; ?></h4>
381 <?php endif; ?>
382 <input
383 name="<?php echo esc_attr( $value['id'] ); ?>"
384 id="<?php echo esc_attr( $value['id'] ); ?>"
385 type="<?php echo esc_attr( $type ); ?>"
386 style="<?php echo esc_attr( $value['css'] ); ?>"
387 value="<?php echo esc_attr( $option_value ); ?>"
388 class="<?php echo esc_attr( $value['class'] ); ?>"
389 <?php echo implode( ' ', $custom_attributes ); ?>
390 /> <?php echo $description; ?>
391 </td>
392 </tr><?php
393 break;
394
395 case 'image' :
396
397 $option_value = (int) $this->get_option( $value['id'], 0 );
398 $image_url = $option_value ? wp_get_attachment_url( $option_value ) : '';
399
400 ?><tr valign="top">
401 <th scope="row" class="titledesc">
402 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
403 <?php echo $tip; ?>
404 </th>
405
406 <td>
407 <div class="image-wrap<?php echo $option_value ? '' : ' erp-hide'; ?>">
408 <input type="hidden" class="erp-file-field" name="<?php echo esc_attr( $value['id'] ); ?>" value="<?php echo esc_attr( $option_value ); ?>">
409 <img class="erp-option-image" src="<?php echo esc_url( $image_url ); ?>">
410
411 <a class="erp-remove-image" title="<?php _e( 'Delete this image?', 'erp' ); ?>">&times;</a>
412 </div>
413
414 <div class="button-area<?php echo $option_value ? ' erp-hide' : ''; ?>">
415 <a href="#" class="erp-image-upload button"><?php _e( 'Upload Image', 'erp' ); ?></a>
416 <?php echo $description; ?>
417 </div>
418
419 </td>
420
421
422 </tr><?php
423 break;
424
425 // Textarea
426 case 'textarea':
427
428 $option_value = $this->get_option( $value['id'], $value['default'] );
429
430 ?><tr valign="top">
431 <th scope="row" class="titledesc">
432 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
433 <?php echo $tip; ?>
434 </th>
435 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
436 <?php if ( ! empty( $value['title_before_field'] ) ): ?>
437 <h4 class="erp-settings-title-before-field"><?php echo $value['title_before_field']; ?></h4>
438 <?php endif; ?>
439
440 <textarea
441 name="<?php echo esc_attr( $value['id'] ); ?>"
442 id="<?php echo esc_attr( $value['id'] ); ?>"
443 style="<?php echo esc_attr( $value['css'] ); ?>"
444 class="<?php echo esc_attr( $value['class'] ); ?>"
445 <?php echo implode( ' ', $custom_attributes ); ?>
446 ><?php echo esc_textarea( $option_value ); ?></textarea>
447
448 <?php echo $description; ?>
449 </td>
450 </tr><?php
451 break;
452
453 // Textarea
454 case 'wysiwyg':
455
456 $option_value = $this->get_option( $value['id'], $value['default'] );
457 $editor_args = [
458 'editor_class' => $value['css'],
459 'textarea_rows' => 10
460 ];
461
462 ?><tr valign="top">
463 <th scope="row" class="titledesc">
464 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
465 <?php echo $tip; ?>
466 </th>
467 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
468
469 <?php wp_editor( $option_value, $value['id'], $editor_args ); ?>
470
471 <?php echo $description; ?>
472 </td>
473 </tr><?php
474 break;
475
476 // Select boxes
477 case 'select' :
478 case 'multiselect' :
479
480 $option_value = $this->get_option( $value['id'], $value['default'] );
481
482 ?><tr valign="top">
483 <th scope="row" class="titledesc">
484 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
485 <?php echo $tip; ?>
486 </th>
487 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
488 <select
489 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
490 id="<?php echo esc_attr( $value['id'] ); ?>"
491 style="<?php echo esc_attr( $value['css'] ); ?>"
492 class="<?php echo esc_attr( $value['class'] ); ?>"
493 <?php echo implode( ' ', $custom_attributes ); ?>
494 <?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
495 >
496 <?php
497 foreach ( $value['options'] as $key => $val ) {
498 ?>
499 <option value="<?php echo esc_attr( $key ); ?>" <?php
500
501 if ( is_array( $option_value ) )
502 selected( in_array( $key, $option_value ), true );
503 else
504 selected( $option_value, $key );
505
506 ?>><?php echo $val ?></option>
507 <?php
508 }
509 ?>
510 </select> <?php echo $description; ?>
511 </td>
512 </tr><?php
513 break;
514
515 // Radio inputs
516 case 'radio' :
517
518 $option_value = $this->get_option( $value['id'], $value['default'] );
519
520 ?><tr valign="top">
521 <th scope="row" class="titledesc">
522 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
523 <?php echo $tip; ?>
524 </th>
525 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
526 <fieldset>
527 <ul class="erp-settings-radio">
528 <?php
529 foreach ( $value['options'] as $key => $val ) {
530 ?>
531 <li>
532 <label><input
533 name="<?php echo esc_attr( $value['id'] ); ?>"
534 value="<?php echo $key; ?>"
535 type="radio"
536 style="<?php echo esc_attr( $value['css'] ); ?>"
537 class="<?php echo esc_attr( $value['class'] ); ?>"
538 <?php echo implode( ' ', $custom_attributes ); ?>
539 <?php checked( $key, $option_value ); ?>
540 /> <?php echo $val ?></label>
541 </li>
542 <?php
543 }
544 ?>
545 </ul>
546 <?php echo $description; ?>
547 </fieldset>
548 </td>
549 </tr><?php
550 break;
551
552
553 // multi check
554 case 'multicheck' :
555
556 $default = is_array( $value['default'] ) ? $value['default'] : array();
557 $option_value = $this->get_option( $value['id'], $default );
558
559 ?><tr valign="top">
560 <th scope="row" class="titledesc">
561 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
562 <?php echo $tip; ?>
563 </th>
564 <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
565 <fieldset>
566 <ul>
567 <?php
568 foreach ( $value['options'] as $key => $val ) {
569 ?>
570 <li>
571 <label><input
572 name="<?php echo esc_attr( $value['id'] ); ?>[<?php echo esc_attr( $key ); ?>]"
573 value="<?php echo $key; ?>"
574 type="checkbox"
575 style="<?php echo esc_attr( $value['css'] ); ?>"
576 class="<?php echo esc_attr( $value['class'] ); ?>"
577 <?php echo implode( ' ', $custom_attributes ); ?>
578 <?php checked( in_array( $key, $option_value ) ); ?>
579 /> <?php echo $val ?></label>
580 </li>
581 <?php
582 }
583 ?>
584 </ul>
585 </fieldset>
586 <?php echo $description; ?>
587 </td>
588 </tr><?php
589 break;
590
591 // Checkbox input
592 case 'checkbox' :
593
594 $option_value = $this->get_option( $value['id'], $value['default'] );
595 $visbility_class = array();
596
597 if ( ! isset( $value['hide_if_checked'] ) ) {
598 $value['hide_if_checked'] = false;
599 }
600 if ( ! isset( $value['show_if_checked'] ) ) {
601 $value['show_if_checked'] = false;
602 }
603 if ( $value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes' ) {
604 $visbility_class[] = 'hidden_option';
605 }
606 if ( $value['hide_if_checked'] == 'option' ) {
607 $visbility_class[] = 'hide_options_if_checked';
608 }
609 if ( $value['show_if_checked'] == 'option' ) {
610 $visbility_class[] = 'show_options_if_checked';
611 }
612
613 if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
614 ?>
615 <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
616 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th>
617 <td class="forminp forminp-checkbox">
618 <fieldset>
619 <?php
620 } else {
621 ?>
622 <fieldset class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
623 <?php
624 }
625
626 if ( ! empty( $value['title'] ) ) {
627 ?>
628 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend>
629 <?php
630 }
631
632 ?>
633 <label for="<?php echo $value['id'] ?>">
634 <input
635 name="<?php echo esc_attr( $value['id'] ); ?>"
636 id="<?php echo esc_attr( $value['id'] ); ?>"
637 type="checkbox"
638 value="1"
639 <?php checked( $option_value, 'yes'); ?>
640 <?php echo implode( ' ', $custom_attributes ); ?>
641 /> <?php echo $description ?>
642 </label> <?php echo $tip; ?>
643 <?php
644
645 if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
646 ?>
647 </fieldset>
648 </td>
649 </tr>
650 <?php
651 } else {
652 ?>
653 </fieldset>
654 <?php
655 }
656 break;
657
658 // Image width settings
659 case 'image_width' :
660
661 $width = $this->get_option( $value['id'] . '[width]', $value['default']['width'] );
662 $height = $this->get_option( $value['id'] . '[height]', $value['default']['height'] );
663 $crop = checked( 1, $this->get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
664
665 ?><tr valign="top">
666 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
667 <td class="forminp image_width_settings">
668
669 <input name="<?php echo esc_attr( $value['id'] ); ?>[width]" id="<?php echo esc_attr( $value['id'] ); ?>-width" type="text" size="3" value="<?php echo $width; ?>" /> &times; <input name="<?php echo esc_attr( $value['id'] ); ?>[height]" id="<?php echo esc_attr( $value['id'] ); ?>-height" type="text" size="3" value="<?php echo $height; ?>" />px
670
671 <label><input name="<?php echo esc_attr( $value['id'] ); ?>[crop]" id="<?php echo esc_attr( $value['id'] ); ?>-crop" type="checkbox" <?php echo $crop; ?> /> <?php _e( 'Hard Crop?', 'erp' ); ?></label>
672
673 </td>
674 </tr><?php
675 break;
676
677 // Single page selects
678 case 'single_select_page' :
679
680 $args = array(
681 'name' => $value['id'],
682 'id' => $value['id'],
683 'sort_column' => 'menu_order',
684 'sort_order' => 'ASC',
685 'show_option_none' => ' ',
686 'class' => $value['class'],
687 'echo' => false,
688 'selected' => absint( $this->get_option( $value['id'] ) )
689 );
690
691 if ( isset( $value['args'] ) ) {
692 $args = wp_parse_args( $value['args'], $args );
693 }
694
695 ?><tr valign="top" class="single_select_page">
696 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
697 <td class="forminp">
698 <?php echo str_replace(' id=', " data-placeholder='" . __( 'Select a page&hellip;', 'erp' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); ?> <?php echo $description; ?>
699 </td>
700 </tr><?php
701 break;
702
703 // Default: run an action
704 default:
705 do_action( 'erp_admin_field_' . $value['type'], $value );
706 break;
707 }
708 }
709 }
710
711 /**
712 * Output sections
713 */
714 public function output_sections() {
715 global $current_section;
716
717 $sections = $this->get_sections();
718
719 if ( empty( $sections ) ) {
720 return;
721 }
722
723 echo '<ul class="subsubsub">';
724
725 $array_keys = array_keys( $sections );
726
727 foreach ( $sections as $id => $label ) {
728 echo '<li><a href="' . admin_url( 'admin.php?page=erp-settings&tab=' . $this->id . '&section=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
729 }
730
731 echo '</ul><br class="clear" />';
732 }
733
734 /**
735 * Get a setting from the settings API.
736 *
737 * @param mixed $option
738 * @return string
739 */
740 public function get_option( $option_name, $default = '' ) {
741
742 if ( $this->single_option ) {
743
744 $option_value = get_option( $option_name, $default );
745
746 } else {
747
748 $options = get_option( $this->get_option_id(), array() );
749 $option_value = isset( $options[$option_name] ) ? $options[$option_name] : $default;
750 }
751
752 if ( is_array( $option_value ) ) {
753 $option_value = array_map( 'stripslashes', $option_value );
754 } elseif ( ! is_null( $option_value ) ) {
755 $option_value = stripslashes( $option_value );
756 }
757
758 return $option_value;
759 }
760 }
761