PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.16.3
GiveWP – Donation Plugin and Fundraising Platform v3.16.3
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-admin-settings.php
give / includes / admin Last commit date
add-ons 4 years ago donors 2 years ago emails 3 years ago forms 1 year ago payments 2 years ago reports 4 years ago settings 1 year ago shortcodes 4 years ago tools 1 year ago upgrades 3 years ago views 3 years ago abstract-admin-settings-page.php 2 years ago admin-actions.php 1 year ago admin-filters.php 3 years ago admin-footer.php 2 years ago admin-pages.php 2 years ago class-addon-activation-banner.php 4 years ago class-admin-settings.php 1 year ago class-api-keys-table.php 4 years ago class-blank-slate.php 3 years ago class-give-admin.php 5 years ago class-give-html-elements.php 6 years ago class-i18n-module.php 4 years ago dashboard-widgets.php 3 years ago give-metabox-functions.php 3 years ago import-functions.php 2 years ago misc-functions.php 2 years ago plugins.php 3 years ago setting-page-functions.php 6 years ago
class-admin-settings.php
1271 lines
1 <?php
2 /**
3 * Give Admin Settings Class
4 *
5 * @package Give
6 * @subpackage Classes/Give_Admin_Settings
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 if ( ! class_exists( 'Give_Admin_Settings' ) ) :
17
18 /**
19 * Give_Admin_Settings Class.
20 *
21 * @since 1.8
22 */
23 class Give_Admin_Settings {
24
25 /**
26 * Setting pages.
27 *
28 * @since 1.8
29 * @var array List of settings.
30 */
31 private static $settings = [];
32
33 /**
34 * Setting filter and action prefix.
35 *
36 * @since 1.8
37 * @var string setting filter and action name prefix.
38 */
39 private static $setting_filter_prefix = '';
40
41 /**
42 * Error messages.
43 *
44 * @since 1.8
45 * @var array List of errors.
46 */
47 private static $errors = [];
48
49 /**
50 * Update messages.
51 *
52 * @since 1.8
53 * @var array List of messages.
54 */
55 private static $messages = [];
56
57 /**
58 * Include the settings page classes.
59 *
60 * @since 1.8
61 * @return array
62 */
63 public static function get_settings_pages() {
64 /**
65 * Filter the setting page.
66 *
67 * Note: filter dynamically fire on basis of setting page slug.
68 * For example: if you register a setting page with give-settings menu slug
69 * then filter will be give-settings_get_settings_pages
70 *
71 * @since 1.8
72 *
73 * @param array $settings Array of settings class object.
74 */
75 self::$settings = apply_filters( self::$setting_filter_prefix . '_get_settings_pages', [] );
76
77 return self::$settings;
78 }
79
80 /**
81 * Verify admin setting nonce
82 *
83 * @since 1.8.14
84 * @access public
85 *
86 * @return bool
87 */
88 public static function verify_nonce() {
89 if ( empty( $_REQUEST['_give-save-settings'] ) || ! wp_verify_nonce( $_REQUEST['_give-save-settings'], 'give-save-settings' ) ) {
90 return false;
91 }
92
93 return true;
94 }
95
96 /**
97 * Save the settings.
98 *
99 * @since 1.8
100 * @return void
101 */
102 public static function save() {
103 $current_tab = give_get_current_setting_tab();
104
105 if ( ! self::verify_nonce() ) {
106 echo '<div class="notice error"><p>' . esc_attr__( 'Action failed. Please refresh the page and retry.', 'give' ) . '</p></div>';
107 die();
108 }
109
110 /**
111 * Trigger Action.
112 *
113 * Note: action dynamically fire on basis of setting page slug and current tab.
114 * For example: if you register a setting page with give-settings menu slug and general current tab name
115 * then action will be give-settings_save_general
116 *
117 * @since 1.8
118 */
119 do_action( self::$setting_filter_prefix . '_save_' . $current_tab );
120
121 self::add_message( 'give-setting-updated', __( 'Your settings have been saved.', 'give' ) );
122
123 /**
124 * Trigger Action.
125 *
126 * Note: action dynamically fire on basis of setting page slug.
127 * For example: if you register a setting page with give-settings menu slug
128 * then action will be give-settings_saved
129 *
130 * @since 1.8
131 */
132 do_action( self::$setting_filter_prefix . '_saved' );
133 }
134
135 /**
136 * Add a message.
137 *
138 * @since 1.8
139 *
140 * @param string $code Message code (Note: This should be unique).
141 * @param string $message Message text.
142 *
143 * @return void
144 */
145 public static function add_message( $code, $message ) {
146 self::$messages[ $code ] = $message;
147 }
148
149 /**
150 * Add an error.
151 *
152 * @since 1.8
153 *
154 * @param string $code Message code (Note: This should be unique).
155 * @param string $message Message text.
156 *
157 * @return void
158 */
159 public static function add_error( $code, $message ) {
160 self::$errors[ $code ] = $message;
161 }
162
163 /**
164 * Output messages + errors.
165 *
166 * @since 1.8
167 * @return void
168 */
169 public static function show_messages() {
170 $notice_html = '';
171 $classes = 'give-notice settings-error notice is-dismissible';
172
173 self::$errors = apply_filters( self::$setting_filter_prefix . '_error_notices', self::$errors );
174 self::$messages = apply_filters( self::$setting_filter_prefix . '_update_notices', self::$messages );
175
176 if ( 0 < count( self::$errors ) ) {
177 foreach ( self::$errors as $code => $message ) {
178 $notice_html .= sprintf(
179 '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p>%3$s</p></div>',
180 $code,
181 $classes,
182 $message
183 );
184 }
185 }
186
187 if ( 0 < count( self::$messages ) ) {
188 foreach ( self::$messages as $code => $message ) {
189 $notice_html .= sprintf(
190 '<div id="setting-error-%1$s" class="%2$s updated" style="display: none"><p><strong>%3$s</strong></p></div>',
191 $code,
192 $classes,
193 $message
194 );
195 }
196 }
197
198 echo $notice_html;
199 }
200
201 /**
202 * Settings page.
203 *
204 * Handles the display of the main give settings page in admin.
205 *
206 * @since 1.8
207 * @return bool
208 */
209 public static function output() {
210 // Get current setting page.
211 self::$setting_filter_prefix = give_get_current_setting_page();
212
213 // Bailout: Exit if setting page is not defined.
214 if ( empty( self::$setting_filter_prefix ) ) {
215 return false;
216 }
217
218 /**
219 * Trigger Action.
220 *
221 * Note: action dynamically fire on basis of setting page slug
222 * For example: if you register a setting page with give-settings menu slug
223 * then action will be give-settings_start
224 *
225 * @since 1.8
226 */
227 do_action( self::$setting_filter_prefix . '_start' );
228
229 $current_tab = give_get_current_setting_tab();
230 $current_section = give_get_current_setting_section();
231
232 // Include settings pages.
233 $all_setting = self::get_settings_pages();
234
235 /* @var object $current_setting_obj */
236 $current_setting_obj = new StdClass();
237
238 foreach ( $all_setting as $setting ) {
239 if (
240 is_object($setting) && method_exists( $setting, 'get_id' ) &&
241 $current_tab === $setting->get_id()
242 ) {
243 $current_setting_obj = $setting;
244 break;
245 }
246 }
247
248 // Save settings if data has been posted.
249 if ( isset( $_POST['_give-save-settings'] ) ) {
250 self::save();
251 }
252
253 /**
254 * Filter the tabs for current setting page.
255 *
256 * Note: filter dynamically fire on basis of setting page slug.
257 * For example: if you register a setting page with give-settings menu slug and general current tab name
258 * then action will be give-settings_tabs_array
259 *
260 * @since 1.8
261 */
262 $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', [] );
263
264 include 'views/html-admin-settings.php';
265
266 return true;
267 }
268
269 /**
270 * Get a setting from the settings API.
271 *
272 * @since 1.8
273 *
274 * @param string $option_name Option Name.
275 * @param string $field_id Field ID.
276 * @param mixed $default Default.
277 *
278 * @return string|bool
279 */
280 public static function get_option( $option_name = '', $field_id = '', $default = false ) {
281 // Bailout.
282 if ( empty( $option_name ) && empty( $field_id ) ) {
283 return false;
284 }
285
286 if ( ! empty( $field_id ) && ! empty( $option_name ) ) {
287 // Get field value if any.
288 $option_value = get_option( $option_name );
289
290 $option_value = ( is_array( $option_value ) && array_key_exists( $field_id, $option_value ) )
291 ? $option_value[ $field_id ]
292 : $default;
293 } else {
294 // If option name is empty but not field name then this means, setting is direct store to option table under there field name.
295 $option_name = ! $option_name ? $field_id : $option_name;
296
297 // Get option value if any.
298 $option_value = get_option( $option_name, $default );
299 }
300
301 /**
302 * Filter the option value
303 *
304 * @since 2.2.3
305 *
306 * @param mixed $option_value
307 * @param string $option_name
308 * @param string $field_id
309 * @param mixed $default
310 */
311 return apply_filters( 'give_admin_field_get_value', $option_value, $option_name, $field_id, $default );
312 }
313
314 /**
315 * Output admin fields.
316 *
317 * Loops though the give options array and outputs each field.
318 *
319 * @todo Refactor this function
320 *
321 * @since 1.8
322 * @access public
323 *
324 * @param array $sections Opens array to output.
325 * @param string $option_name Opens array to output.
326 *
327 * @return void
328 */
329 public static function output_fields( $sections, $option_name = '' ) {
330
331 $current_page = give_get_current_setting_page();
332 $current_tab = give_get_current_setting_tab();
333 $current_section = give_get_current_setting_section();
334 $groups = give_get_settings_groups();
335
336 if ( $groups ) {
337 $defaultGroup = current( array_keys( $groups ) );
338 ?>
339 <div class="give-settings-section-content">
340 <div class="give-settings-section-group-menu">
341 <ul>
342 <?php
343 foreach ( $groups as $slug => $group ) {
344 $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup;
345 $active_class = ( $slug === $current_group ) ? 'active' : '';
346
347 echo sprintf(
348 '<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s</a></li>',
349 esc_html( $active_class ),
350 esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}" ) ),
351 esc_html( $slug ),
352 esc_html( $group )
353 );
354 }
355 ?>
356 </ul>
357 </div>
358 <div class="give-settings-section-group-content">
359 <?php
360 foreach ( $sections as $group => $fields ) {
361 $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $defaultGroup;
362 $hide_class = $group !== $current_group ? 'give-hidden' : '';
363
364 printf(
365 '<div id="give-settings-section-group-%1$s" class="give-settings-section-group %2$s">',
366 esc_attr( $group ),
367 esc_html( $hide_class )
368 );
369
370 /**
371 * Filter sub group settings.
372 *
373 * @since 2.8.0
374 */
375 $subGroups = apply_filters( "give_get_groups_{$current_section}_{$group}", [] );
376
377 if ( $subGroups ) {
378 $subGroupIds = array_keys( $subGroups );
379 $defaultSubGroup = current( $subGroupIds );
380 $lastSubGroupId = end( $subGroupIds );
381
382 echo '<ul class="give-subsubsub">';
383 foreach ( $subGroups as $id => $label ) {
384 $separator = $lastSubGroupId === $id ? '' : '&nbsp;|&nbsp;';
385 $currentSubGroup = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
386 $class = $id === $currentSubGroup ? 'current' : '';
387 printf(
388 '<li><a data-subgroup="%1$s" href="%2$s" class="%5$s">%3$s</a>%4$s</li>',
389 $id,
390 esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$group}&sub-group={$id}" ) ),
391 $label,
392 $separator,
393 $class
394 );
395 }
396 echo '</ul>';
397
398 foreach ( $fields as $id => $subgroup ) {
399 $current_group = ! empty( $_GET['sub-group'] ) ? give_clean( $_GET['sub-group'] ) : $defaultSubGroup;
400 $hide_class = $id !== $current_group ? 'give-hidden' : '';
401
402 printf(
403 '<div id="give-settings-section-subgroup-%1$s" class="give-settings-section-subgroup %2$s">',
404 esc_attr( $id ),
405 esc_html( $hide_class )
406 );
407
408 foreach ( $subgroup as $setting ) {
409 if ( ! isset( $setting['type'] ) ) {
410 continue;
411 }
412 self::prepare_settings_field( $setting, $option_name );
413 }
414
415 echo '</div>';
416 }
417 } else {
418 foreach ( $fields as $value ) {
419 if ( ! isset( $value['type'] ) ) {
420 continue;
421 }
422 self::prepare_settings_field( $value, $option_name );
423 }
424 }
425
426 echo '</div>';
427 }
428 ?>
429 </div>
430 </div>
431 <?php
432 } else {
433
434 // Loop through each section.
435 foreach ( $sections as $value ) {
436 if ( ! isset( $value['type'] ) ) {
437 continue;
438 }
439 self::prepare_settings_field( $value, $option_name );
440 }
441 }
442
443 }
444
445 /**
446 * This function will help you prepare the admin settings field.
447 *
448 * @since 2.5.5
449 * @access public
450 *
451 * @param array $value Settings Field Array.
452 * @param string $option_name Option Name.
453 *
454 * @return mixed
455 */
456 public static function prepare_settings_field( $value, $option_name ) {
457
458 $current_tab = give_get_current_setting_tab();
459
460 // Field Default values.
461 $defaults = [
462 'id' => '',
463 'class' => '',
464 'css' => '',
465 'default' => '',
466 'desc' => '',
467 'table_html' => true,
468 'repeat' => false,
469 'repeat_btn_title' => __( 'Add Field', 'give' ),
470 ];
471
472 // Set title.
473 $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
474
475 // Set default setting.
476 $value = wp_parse_args( $value, $defaults );
477
478 // Colorpicker field.
479 $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
480 $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
481
482 // Custom attribute handling.
483 $custom_attributes = [];
484
485 if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
486 foreach ( $value['attributes'] as $attribute => $attribute_value ) {
487 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
488 }
489 }
490
491 // Description handling.
492 $description = self::get_field_description( $value );
493
494 // Switch based on type.
495 switch ( $value['type'] ) {
496
497 // Section Titles.
498 case 'title':
499 if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
500 ?>
501 <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
502 <?php if ( ! empty( $value['title'] ) ) : ?>
503 <h2><?php echo self::get_field_title( $value ); ?></h2>
504 <hr>
505 <?php endif; ?>
506
507 <?php if ( ! empty( $value['desc'] ) ) : ?>
508 <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
509 <?php endif; ?>
510 </div>
511 <?php
512 }
513
514 if ( $value['table_html'] ) {
515 echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
516 }
517
518 if ( ! empty( $value['id'] ) ) {
519
520 /**
521 * Trigger Action.
522 *
523 * Note: action dynamically fire on basis of field id.
524 *
525 * @since 1.8
526 */
527 do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
528 }
529
530 break;
531
532 // Section Ends.
533 case 'sectionend':
534 if ( ! empty( $value['id'] ) ) {
535
536 /**
537 * Trigger Action.
538 *
539 * Note: action dynamically fire on basis of field id.
540 *
541 * @since 1.8
542 */
543 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
544 }
545
546 if ( $value['table_html'] ) {
547 echo '</table>';
548 }
549
550 if ( ! empty( $value['id'] ) ) {
551
552 /**
553 * Trigger Action.
554 *
555 * Note: action dynamically fire on basis of field id.
556 *
557 * @since 1.8
558 */
559 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
560 }
561
562 break;
563
564 // Standard text inputs and subtypes like 'number'.
565 case 'colorpicker':
566 case 'hidden':
567 $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
568 case 'text':
569 case 'email':
570 case 'number':
571 case 'password':
572 $type = $value['type'];
573 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
574
575 // Set default value for repeater field if not any value set yet.
576 if ( $value['repeat'] && is_string( $option_value ) ) {
577 $option_value = [ $value['default'] ];
578 }
579 ?>
580 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
581 <th scope="row" class="titledesc">
582 <label
583 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
584 </th>
585 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
586 <?php if ( $value['repeat'] ) : ?>
587 <?php foreach ( $option_value ?: [''] as $index => $field_value ) : ?>
588 <p>
589 <input
590 name="<?php echo esc_attr( $value['id'] ); ?>[]"
591 type="<?php echo esc_attr( $type ); ?>"
592 style="<?php echo esc_attr( $value['css'] ); ?>"
593 value="<?php echo esc_attr( $field_value ); ?>"
594 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
595 <?php echo implode( ' ', $custom_attributes ); ?>
596 />
597 <span class="give-remove-setting-field"
598 title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
599 </p>
600 <?php endforeach; ?>
601 <a href="#" data-id="<?php echo $value['id']; ?>"
602 class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
603 <?php else : ?>
604 <input
605 name="<?php echo esc_attr( $value['id'] ); ?>"
606 id="<?php echo esc_attr( $value['id'] ); ?>"
607 type="<?php echo esc_attr( $type ); ?>"
608 style="<?php echo esc_attr( $value['css'] ); ?>"
609 value="<?php echo esc_attr( $option_value ); ?>"
610 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
611 <?php echo implode( ' ', $custom_attributes ); ?>
612 />
613 <?php endif; ?>
614 <?php echo $description; ?>
615 </td>
616 </tr>
617 <?php
618 break;
619
620 // Textarea.
621 case 'textarea':
622 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
623 $default_attributes = [
624 'rows' => 10,
625 'cols' => 60,
626 ];
627 $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : [];
628 ?>
629 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
630 <th scope="row" class="titledesc">
631 <label
632 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
633 </th>
634 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
635 <textarea
636 name="<?php echo esc_attr( $value['id'] ); ?>"
637 id="<?php echo esc_attr( $value['id'] ); ?>"
638 style="<?php echo esc_attr( $value['css'] ); ?>"
639 class="<?php echo esc_attr( $value['class'] ); ?>"
640 <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
641 ><?php echo esc_textarea( $option_value ); ?></textarea>
642 <?php echo $description; ?>
643 </td>
644 </tr>
645 <?php
646 break;
647
648 // Select boxes.
649 case 'select':
650 case 'multiselect':
651 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
652 $setting_name = esc_attr( $value['id'] ) . ( 'multiselect' === $value['type'] ? '[]' : '' );
653
654 /**
655 * Insert page in option if missing.
656 *
657 * Check success_page setting in general settings.
658 */
659 if (
660 isset( $value['attributes'] ) &&
661 false !== strpos( $value['class'], 'give-select-chosen' ) &&
662 in_array( 'data-search-type', array_keys( $value['attributes'] ) ) &&
663 'pages' === $value['attributes']['data-search-type'] &&
664 ! in_array( $option_value, array_keys( $value['options'] ) )
665 ) {
666 $value['options'][ $option_value ] = get_the_title( $option_value );
667 }
668 ?>
669 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
670 <th scope="row" class="titledesc">
671 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
672 </th>
673 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
674 <select name="<?php echo $setting_name; ?>"
675 id="<?php echo esc_attr( $value['id'] ); ?>"
676 style="<?php echo esc_attr( $value['css'] ); ?>"
677 class="<?php echo esc_attr( $value['class'] ); ?>"
678 <?php echo implode( ' ', $custom_attributes ); ?>
679 <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
680 >
681
682 <?php
683 if ( ! empty( $value['options'] ) ) {
684 foreach ( $value['options'] as $key => $val ) {
685 ?>
686 <option value="<?php echo esc_attr( $key ); ?>"
687 <?php
688
689 if ( is_array( $option_value ) ) {
690 selected( in_array( $key, $option_value ), true );
691 } else {
692 selected( $option_value, $key );
693 }
694
695 ?>
696 ><?php echo $val; ?></option>
697 <?php
698 }
699 }
700 ?>
701
702 </select> <?php echo $description; ?>
703 </td>
704 </tr>
705 <?php
706 break;
707
708 // Radio inputs.
709 case 'radio_inline':
710 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
711 case 'radio':
712 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
713 ?>
714 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
715 <th scope="row" class="titledesc">
716 <label
717 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
718 </th>
719 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
720 <fieldset>
721 <ul>
722 <?php
723 foreach ( $value['options'] as $key => $val ) {
724 ?>
725 <li>
726 <label><input
727 name="<?php echo esc_attr( $value['id'] ); ?>"
728 value="<?php echo $key; ?>"
729 type="radio"
730 style="<?php echo esc_attr( $value['css'] ); ?>"
731 <?php echo implode( ' ', $custom_attributes ); ?>
732 <?php checked( $key, $option_value ); ?>
733 /> <?php echo $val; ?></label>
734 </li>
735 <?php
736 }
737 ?>
738 <?php echo $description; ?>
739 </fieldset>
740 </td>
741 </tr>
742 <?php
743 break;
744
745 // Checkbox input.
746 case 'checkbox':
747 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
748 ?>
749 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
750 <th scope="row" class="titledesc">
751 <label
752 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
753 </th>
754 <td class="give-forminp">
755 <input
756 name="<?php echo esc_attr( $value['id'] ); ?>"
757 id="<?php echo esc_attr( $value['id'] ); ?>"
758 type="checkbox"
759 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
760 value="1"
761 <?php checked( $option_value, 'on' ); ?>
762 <?php echo implode( ' ', $custom_attributes ); ?>
763 />
764 <?php echo $description; ?>
765 </td>
766 </tr>
767 <?php
768 break;
769
770 // Multi Checkbox input.
771 case 'multicheck':
772 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
773 $option_value = is_array( $option_value ) ? $option_value : [];
774 ?>
775 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
776 <th scope="row" class="titledesc">
777 <label
778 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
779 </th>
780 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
781 <fieldset>
782 <ul>
783 <?php
784 foreach ( $value['options'] as $key => $val ) {
785 ?>
786 <li>
787 <label>
788 <input
789 name="<?php echo esc_attr( $value['id'] ); ?>[]"
790 value="<?php echo $key; ?>"
791 type="checkbox"
792 style="<?php echo esc_attr( $value['css'] ); ?>"
793 <?php echo implode( ' ', $custom_attributes ); ?>
794 <?php
795 if ( in_array( $key, $option_value ) ) {
796 echo 'checked="checked"';
797 }
798 ?>
799 /> <?php echo $val; ?>
800 </label>
801 </li>
802 <?php
803 }
804 ?>
805 <?php echo $description; ?>
806 </fieldset>
807 </td>
808 </tr>
809 <?php
810 break;
811
812 // File input field.
813 case 'file':
814 case 'media':
815 $option_value = esc_url( self::get_option( $option_name, $value['id'], $value['default'] ) );
816 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
817 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
818
819 $allow_media_preview_tags = [ 'jpg', 'jpeg', 'png', 'gif', 'ico' ];
820 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
821 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
822 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
823 ?>
824 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
825 <th scope="row" class="titledesc">
826 <label
827 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
828 </th>
829 <td class="give-forminp">
830 <div class="give-field-wrap">
831 <label for="<?php echo $value['id']; ?>">
832 <input
833 name="<?php echo esc_attr( $value['id'] ); ?>"
834 id="<?php echo esc_attr( $value['id'] ); ?>"
835 type="text"
836 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
837 value="<?php echo $option_value; ?>"
838 style="<?php echo esc_attr( $value['css'] ); ?>"
839 <?php echo implode( ' ', $custom_attributes ); ?>
840 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
841 data-fvalue="<?php echo $fvalue; ?>"
842 data-field-type="<?php echo $value['type']; ?>"
843 value="<?php echo $button_label; ?>">
844 <?php echo $description; ?>
845 <div
846 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
847 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
848 <img src="<?php echo $preview_image_src; ?>" alt="">
849 </div>
850 </label>
851 </div>
852 </td>
853 </tr>
854 <?php
855 break;
856
857 // WordPress Editor.
858 case 'wysiwyg':
859 // Get option value.
860 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
861
862 // Get editor settings.
863 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : [];
864 ?>
865 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
866 <th scope="row" class="titledesc">
867 <label
868 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
869 </th>
870 <td class="give-forminp">
871 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
872 <?php echo $description; ?>
873 </td>
874 </tr>
875 <?php
876 break;
877
878 // Custom: Email preview buttons field.
879 case 'email_preview_buttons':
880 ?>
881 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
882 <th scope="row" class="titledesc">
883 <label
884 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
885 </th>
886 <td class="give-forminp">
887 <?php give_email_preview_buttons_callback( $value ); ?>
888 <?php echo $description; ?>
889 </td>
890 </tr>
891 <?php
892 break;
893
894 // Custom: API field.
895 case 'api':
896 give_api_callback();
897 echo $description;
898 break;
899
900 // Custom: Gateway API key.
901 case 'api_key':
902 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
903 $type = ! empty( $option_value ) ? 'password' : 'text';
904 ?>
905 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : ''; ?>>
906 <th scope="row" class="titledesc">
907 <label
908 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
909 </th>
910 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ); ?>">
911 <input
912 name="<?php echo esc_attr( $value['id'] ); ?>"
913 id="<?php echo esc_attr( $value['id'] ); ?>"
914 type="<?php echo esc_attr( $type ); ?>"
915 style="<?php echo esc_attr( $value['css'] ); ?>"
916 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
917 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
918 <?php echo implode( ' ', $custom_attributes ); ?>
919 /> <?php echo $description; ?>
920 </td>
921 </tr>
922 <?php
923 break;
924
925 // Note: only for internal use.
926 case 'chosen':
927 // Get option value.
928 $option_value = array_filter( (array) self::get_option( $option_name, $value['id'], $value['default'] ) );
929 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
930 $type = '';
931 $allow_new_values = ! empty( $value['allow-custom-values'] ) && (bool) $value['allow-custom-values'] ? 'data-allows-new-values="true"' : '';
932 $name = give_get_field_name( $value );
933 $choices = $value['options'];
934 $value['style'] = isset( $value['style'] ) ? $value['style'] : '';
935
936 // Set attributes based on multiselect datatype.
937 if ( ! empty( $value['data_type'] ) && 'multiselect' === $value['data_type'] ) {
938 $type = 'multiple';
939 $name .= '[]';
940 $option_value = empty( $option_value ) ? [] : $option_value;
941 }
942
943 // Add dynamically added values to options
944 // we can add option dynamically to chosen select field. For example: "Title Prefixes"
945 if ( $allow_new_values && $option_value ) {
946 $choices = array_merge( array_combine( $option_value, $option_value ), $value['options'] );
947 }
948 ?>
949 <tr valign="top" <?php echo $wrapper_class; ?>>
950 <th scope="row" class="titledesc">
951 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
952 </th>
953 <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
954 <select
955 class="give-select-chosen give-chosen-settings"
956 style="<?php echo esc_attr( $value['style'] ); ?>"
957 name="<?php echo esc_attr( $name ); ?>"
958 id="<?php echo esc_attr( $value['id'] ); ?>"
959 data-placeholder="<?php echo esc_attr__( 'Select Some Options', 'give'); ?>"
960 <?php
961 echo "{$type} {$allow_new_values}";
962 echo implode( ' ', $custom_attributes );
963 ?>
964 >
965 <?php
966 foreach ( $choices as $key => $name ) {
967 echo sprintf(
968 '<option %1$s value="%2$s">%3$s</option>',
969 in_array( $key, $option_value ) ? 'selected="selected"' : '',
970 esc_attr( $key ),
971 $name
972 );
973 }
974 ?>
975 </select>
976 <?php echo wp_kses_post( $description ); ?>
977 </td>
978 </tr>
979 <?php
980 break;
981
982 // Custom: Data field.
983 case 'data':
984 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
985
986 echo $description;
987 break;
988
989 // Custom: Give Docs Link field type.
990 case 'give_docs_link':
991 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
992 ?>
993 <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
994 <td class="give-docs-link" colspan="2">
995 <p class="give-docs-link">
996 <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
997 <?php
998 echo sprintf(
999 /* translators: %s Title */
1000 esc_html__( 'Need Help? See docs on "%s"', 'give' ),
1001 esc_html( $value['title'] )
1002 );
1003 ?>
1004 <span class="dashicons dashicons-editor-help"></span>
1005 </a>
1006 </p>
1007 </td>
1008 </tr>
1009 <?php
1010 break;
1011
1012 // Default: run an action
1013 // You can add or handle your custom field action.
1014 default:
1015 // Get option value.
1016 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
1017 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
1018 break;
1019 }
1020 }
1021
1022 /**
1023 * Helper function to get the formatted description for a given form field.
1024 * Plugins can call this when implementing their own custom settings types.
1025 *
1026 * @since 1.8
1027 *
1028 * @param array $value The form field value array
1029 *
1030 * @return string The HTML description of the field.
1031 */
1032 public static function get_field_description( $value ) {
1033 $description = '';
1034
1035 // Support for both 'description' and 'desc' args.
1036 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
1037 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
1038
1039 if ( ! empty( $value ) ) {
1040 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
1041 }
1042
1043 return $description;
1044 }
1045
1046
1047 /**
1048 * Helper function to get the formated title.
1049 * Plugins can call this when implementing their own custom settings types.
1050 *
1051 * @since 1.8
1052 *
1053 * @param array $value The form field value array
1054 *
1055 * @return array The description and tip as a 2 element array
1056 */
1057 public static function get_field_title( $value ) {
1058 $title = esc_html( $value['title'] );
1059
1060 // If html tag detected then allow them to print.
1061 if ( strip_tags( $title ) ) {
1062 $title = $value['title'];
1063 }
1064
1065 return $title;
1066 }
1067
1068 /**
1069 * Save admin fields.
1070 *
1071 * Loops though the give options array and outputs each field.
1072 *
1073 * @since 1.8
1074 *
1075 * @param array $options Options array to output
1076 * @param string $option_name Option name to save output. If empty then option will be store in there own option name i.e option id.
1077 *
1078 * @return bool
1079 */
1080 public static function save_fields( $options, $option_name = '' ) {
1081
1082 // Fetch form posted super global data.
1083 $post_data = give_clean( $_POST );
1084
1085 // Bailout, if posted data doesn't exists.
1086 if ( empty( $post_data ) ) {
1087 return false;
1088 }
1089
1090 $new_options = [];
1091 $options_keys = array_keys( $options );
1092 $is_vertical_tabs = is_array( $options_keys ) && count( $options_keys ) && ! is_numeric( $options_keys[0] );
1093
1094 if ( $is_vertical_tabs ) {
1095
1096 // Loop through each vertical tabs related field options to destructure into single array.
1097 foreach ( $options as $option ) {
1098 // Get option from a sub group (if any).
1099 if ( ! is_numeric( array_keys( $option )[0] ) ) {
1100 foreach ( $option as $subGroup ) {
1101 $new_options = array_merge( $new_options, $subGroup );
1102 }
1103 continue;
1104 }
1105
1106 $new_options = array_merge( $new_options, $option );
1107 }
1108
1109 // Assign new field options.
1110 $options = $new_options;
1111 }
1112
1113 // Options to update will be stored here and saved later.
1114 $update_options = [];
1115
1116 // Loop options and get values to save.
1117 foreach ( $options as $option ) {
1118 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
1119 continue;
1120 }
1121
1122 // Get posted value.
1123 if ( strstr( $option['id'], '[' ) ) {
1124 parse_str( $option['id'], $option_name_array );
1125 $field_option_name = current( array_keys( $option_name_array ) );
1126 $setting_name = key( $option_name_array[ $field_option_name ] );
1127 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
1128 } else {
1129 $field_option_name = $option['id'];
1130 $setting_name = '';
1131 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
1132 }
1133
1134 // Format the value based on option type.
1135 switch ( $option['type'] ) {
1136 case 'checkbox':
1137 $value = is_null( $raw_value ) ? '' : 'on';
1138 break;
1139 case 'wysiwyg':
1140 case 'textarea':
1141 $value = wp_kses_post( trim( $raw_value ) );
1142 break;
1143 case 'multiselect':
1144 case 'chosen':
1145 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
1146 break;
1147 default:
1148 $value = give_clean( $raw_value );
1149 break;
1150 }
1151
1152 /**
1153 * Sanitize the value of an option.
1154 *
1155 * @since 1.8
1156 */
1157 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
1158
1159 /**
1160 * Sanitize the value of an option by option name.
1161 *
1162 * @since 1.8
1163 */
1164 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
1165
1166 if ( is_null( $value ) ) {
1167 continue;
1168 }
1169
1170 // Check if option is an array and handle that differently to single values.
1171 if ( $field_option_name && $setting_name ) {
1172 if ( ! isset( $update_options[ $field_option_name ] ) ) {
1173 $update_options[ $field_option_name ] = get_option( $field_option_name, [] );
1174 }
1175 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
1176 $update_options[ $field_option_name ] = [];
1177 }
1178 $update_options[ $field_option_name ][ $setting_name ] = $value;
1179 } else {
1180 $update_options[ $field_option_name ] = $value;
1181 }
1182 }
1183
1184 // Save all options in our array or there own option name i.e. option id.
1185 if ( empty( $option_name ) ) {
1186 foreach ( $update_options as $name => $value ) {
1187 update_option( $name, $value, false );
1188
1189 /**
1190 * Trigger action.
1191 *
1192 * Note: This is dynamically fire on basis of option name.
1193 *
1194 * @since 1.8
1195 */
1196 do_action( "give_save_option_{$name}", $value, $name );
1197 }
1198 } else {
1199 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : [];
1200 $update_options = array_merge( $old_options, $update_options );
1201
1202 update_option( $option_name, $update_options, false );
1203
1204 /**
1205 * Trigger action.
1206 *
1207 * Note: This is dynamically fire on basis of setting name.
1208 *
1209 * @since 1.8
1210 */
1211 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1212 }
1213
1214 return true;
1215 }
1216
1217
1218 /**
1219 * Check if admin saving setting or not.
1220 *
1221 * @since 1.8.17
1222 *
1223 * @return bool
1224 */
1225 public static function is_saving_settings() {
1226 return self::verify_nonce();
1227 }
1228
1229 /**
1230 * Verify setting page
1231 *
1232 * @since 2.0
1233 * @access public
1234 *
1235 * @param string $tab
1236 * @param string $section
1237 *
1238 * @return bool
1239 */
1240 public static function is_setting_page( $tab = '', $section = '' ) {
1241 $is_setting_page = false;
1242
1243 // Are we accessing admin?
1244 if ( ! is_admin() ) {
1245 return $is_setting_page;
1246 }
1247
1248 // Are we accessing any give page?
1249 if (
1250 ! isset( $_GET['post_type'], $_GET['page'] )
1251 || 'give_forms' !== give_clean( $_GET['post_type'] )
1252 ) {
1253 return $is_setting_page;
1254 }
1255
1256 // Check fo setting tab.
1257 if ( ! empty( $tab ) ) {
1258 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1259 }
1260
1261 // Check fo setting section.
1262 if ( ! empty( $section ) ) {
1263 $is_setting_page = ( $section === give_get_current_setting_section() );
1264 }
1265
1266 return $is_setting_page;
1267 }
1268 }
1269
1270 endif;
1271