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