PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.6.9
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.6.9
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.6.9, at includes/framework/class-settings-page.php

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