PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.11
GiveWP – Donation Plugin and Fundraising Platform v2.5.11
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 6 years ago donors 6 years ago emails 6 years ago forms 6 years ago payments 6 years ago reports 7 years ago settings 6 years ago shortcodes 6 years ago tools 6 years ago upgrades 6 years ago views 6 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 6 years ago admin-filters.php 7 years ago admin-footer.php 6 years ago admin-pages.php 6 years ago class-addon-activation-banner.php 6 years ago class-admin-settings.php 6 years ago class-api-keys-table.php 7 years ago class-blank-slate.php 6 years ago class-give-admin.php 6 years ago class-give-html-elements.php 7 years ago class-give-welcome.php 6 years ago class-i18n-module.php 6 years ago dashboard-widgets.php 6 years ago give-metabox-functions.php 6 years ago import-functions.php 7 years ago misc-functions.php 6 years ago plugins.php 6 years ago setting-page-functions.php 6 years ago welcome.php 6 years ago
class-admin-settings.php
1231 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 = array();
32
33 /**
34 * Setting filter and action prefix.
35 *
36 * @since 1.8
37 * @var string setting fileter and action anme 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 = array();
48
49 /**
50 * Update messages.
51 *
52 * @since 1.8
53 * @var array List of messages.
54 */
55 private static $messages = array();
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', array() );
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><strong>%3$s</strong></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 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', 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 ( is_array( $groups ) && count( $groups ) > 0 ) {
337 ?>
338 <div class="give-settings-section-content">
339 <div class="give-settings-section-group-menu">
340 <ul>
341 <?php
342 if ( is_array( $groups ) && count( $groups ) > 0 ) {
343 $count = 1;
344
345 foreach ( $groups as $slug => $group ) {
346 $default_group = ( 1 === $count && empty( $_GET['group'] ) ) ? $slug : '';
347 $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $default_group;
348 $active_class = ( $slug === $current_group ) ? 'active' : '';
349
350 echo sprintf(
351 '<li><a class="%1$s" href="%2$s" data-group="%3$s">%4$s</a></li>',
352 esc_html( $active_class ),
353 esc_url( admin_url( "edit.php?post_type=give_forms&page={$current_page}&tab={$current_tab}&section={$current_section}&group={$slug}" ) ),
354 esc_html( $slug ),
355 esc_html( $group )
356 );
357 $count++;
358 }
359 }
360 ?>
361 </ul>
362 </div>
363 <div class="give-settings-section-group-content">
364 <?php
365 $count = 1;
366 foreach ( $sections as $group => $fields ) {
367 if ( ! empty( $group ) ) {
368
369 $default_group = ( 1 === $count && empty( $_GET['group'] ) ) ? $group : '';
370 $current_group = ! empty( $_GET['group'] ) ? give_clean( $_GET['group'] ) : $default_group;
371 $hide_class = $group !== $current_group ? 'give-hidden' : '';
372 ?>
373 <div id="give-settings-section-group-<?php echo esc_attr( $group ); ?>" class="give-settings-section-group <?php echo esc_html( $hide_class ); ?>">
374 <?php
375 foreach ( $fields as $value ) {
376 if ( ! isset( $value['type'] ) ) {
377 continue;
378 }
379 self::prepare_settings_field( $value, $option_name );
380 }
381 ?>
382 </div>
383 <?php
384 }
385
386 $count++;
387 }
388 ?>
389 </div>
390 </div>
391 <?php
392 } else {
393
394 // Loop through each section.
395 foreach ( $sections as $value ) {
396 if ( ! isset( $value['type'] ) ) {
397 continue;
398 }
399 self::prepare_settings_field( $value, $option_name );
400 }
401 }
402
403 }
404
405 /**
406 * This function will help you prepare the admin settings field.
407 *
408 * @since 2.5.5
409 * @access public
410 *
411 * @param array $value Settings Field Array.
412 * @param string $option_name Option Name.
413 *
414 * @return mixed
415 */
416 public static function prepare_settings_field( $value, $option_name ) {
417
418 $current_tab = give_get_current_setting_tab();
419
420 // Field Default values.
421 $defaults = array(
422 'id' => '',
423 'class' => '',
424 'css' => '',
425 'default' => '',
426 'desc' => '',
427 'table_html' => true,
428 'repeat' => false,
429 'repeat_btn_title' => __( 'Add Field', 'give' ),
430 );
431
432 // Set title.
433 $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
434
435 // Set default setting.
436 $value = wp_parse_args( $value, $defaults );
437
438 // Colorpicker field.
439 $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
440 $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
441
442
443 // Custom attribute handling.
444 $custom_attributes = array();
445
446 if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
447 foreach ( $value['attributes'] as $attribute => $attribute_value ) {
448 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
449 }
450 }
451
452 // Description handling.
453 $description = self::get_field_description( $value );
454
455 // Switch based on type.
456 switch ( $value['type'] ) {
457
458 // Section Titles.
459 case 'title':
460 if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
461 ?>
462 <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
463 <?php if ( ! empty( $value['title'] ) ) : ?>
464 <h2><?php echo self::get_field_title( $value ); ?></h2>
465 <hr>
466 <?php endif; ?>
467
468 <?php if ( ! empty( $value['desc'] ) ) : ?>
469 <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
470 <?php endif; ?>
471 </div>
472 <?php
473 }
474
475 if ( $value['table_html'] ) {
476 echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
477 }
478
479 if ( ! empty( $value['id'] ) ) {
480
481 /**
482 * Trigger Action.
483 *
484 * Note: action dynamically fire on basis of field id.
485 *
486 * @since 1.8
487 */
488 do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
489 }
490
491 break;
492
493 // Section Ends.
494 case 'sectionend':
495 if ( ! empty( $value['id'] ) ) {
496
497 /**
498 * Trigger Action.
499 *
500 * Note: action dynamically fire on basis of field id.
501 *
502 * @since 1.8
503 */
504 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
505 }
506
507 if ( $value['table_html'] ) {
508 echo '</table>';
509 }
510
511 if ( ! empty( $value['id'] ) ) {
512
513 /**
514 * Trigger Action.
515 *
516 * Note: action dynamically fire on basis of field id.
517 *
518 * @since 1.8
519 */
520 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
521 }
522
523 break;
524
525 // Standard text inputs and subtypes like 'number'.
526 case 'colorpicker':
527 case 'hidden' :
528 $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
529 case 'text':
530 case 'email':
531 case 'number':
532 case 'password' :
533 $type = $value['type'];
534 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
535
536 // Set default value for repeater field if not any value set yet.
537 if ( $value['repeat'] && is_string( $option_value ) ) {
538 $option_value = array( $value['default'] );
539 }
540 ?>
541 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
542 <th scope="row" class="titledesc">
543 <label
544 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
545 </th>
546 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
547 <?php if ( $value['repeat'] ) : ?>
548 <?php foreach ( $option_value as $index => $field_value ) : ?>
549 <p>
550 <input
551 name="<?php echo esc_attr( $value['id'] ); ?>[]"
552 type="<?php echo esc_attr( $type ); ?>"
553 style="<?php echo esc_attr( $value['css'] ); ?>"
554 value="<?php echo esc_attr( $field_value ); ?>"
555 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
556 <?php echo implode( ' ', $custom_attributes ); ?>
557 />
558 <span class="give-remove-setting-field"
559 title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
560 </p>
561 <?php endforeach; ?>
562 <a href="#" data-id="<?php echo $value['id']; ?>"
563 class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
564 <?php else : ?>
565 <input
566 name="<?php echo esc_attr( $value['id'] ); ?>"
567 id="<?php echo esc_attr( $value['id'] ); ?>"
568 type="<?php echo esc_attr( $type ); ?>"
569 style="<?php echo esc_attr( $value['css'] ); ?>"
570 value="<?php echo esc_attr( $option_value ); ?>"
571 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
572 <?php echo implode( ' ', $custom_attributes ); ?>
573 />
574 <?php endif; ?>
575 <?php echo $description; ?>
576 </td>
577 </tr><?php
578 break;
579
580 // Textarea.
581 case 'textarea':
582
583 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
584 $default_attributes = array(
585 'rows' => 10,
586 'cols' => 60
587 );
588 $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : array();
589 ?>
590 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
591 <th scope="row" class="titledesc">
592 <label
593 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
594 </th>
595 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
596 <textarea
597 name="<?php echo esc_attr( $value['id'] ); ?>"
598 id="<?php echo esc_attr( $value['id'] ); ?>"
599 style="<?php echo esc_attr( $value['css'] ); ?>"
600 class="<?php echo esc_attr( $value['class'] ); ?>"
601 <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
602 ><?php echo esc_textarea( $option_value ); ?></textarea>
603 <?php echo $description; ?>
604 </td>
605 </tr>
606 <?php
607 break;
608
609 // Select boxes.
610 case 'select' :
611 case 'multiselect' :
612 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
613
614 /**
615 * Insert page in option if missing.
616 *
617 * Check success_page setting in general settings.
618 */
619 if (
620 isset( $value['attributes'] ) &&
621 false !== strpos( $value['class'], 'give-select-chosen' ) &&
622 in_array( 'data-search-type', array_keys( $value['attributes' ] ) ) &&
623 'pages' === $value['attributes' ]['data-search-type'] &&
624 ! in_array( $option_value, array_keys( $value['options'] ) )
625 ) {
626 $value['options'][ $option_value ] = get_the_title( $option_value );
627 }
628 ?>
629 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
630 <th scope="row" class="titledesc">
631 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
632 </th>
633 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
634 <select
635 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( 'multiselect' === $value['type'] ) echo '[]'; ?>"
636 id="<?php echo esc_attr( $value['id'] ); ?>"
637 style="<?php echo esc_attr( $value['css'] ); ?>"
638 class="<?php echo esc_attr( $value['class'] ); ?>"
639 <?php echo implode( ' ', $custom_attributes ); ?>
640 <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
641 >
642
643 <?php
644 if ( ! empty( $value['options'] ) ) {
645 foreach ( $value['options'] as $key => $val ) {
646 ?>
647 <option value="<?php echo esc_attr( $key ); ?>" <?php
648
649 if ( is_array( $option_value ) ) {
650 selected( in_array( $key, $option_value ), true );
651 } else {
652 selected( $option_value, $key );
653 }
654
655 ?>><?php echo $val ?></option>
656 <?php
657 }
658 }
659 ?>
660
661 </select> <?php echo $description; ?>
662 </td>
663 </tr><?php
664 break;
665
666 // Radio inputs.
667 case 'radio_inline' :
668 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
669 case 'radio' :
670 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
671 ?>
672 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
673 <th scope="row" class="titledesc">
674 <label
675 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
676 </th>
677 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
678 <fieldset>
679 <ul>
680 <?php
681 foreach ( $value['options'] as $key => $val ) {
682 ?>
683 <li>
684 <label><input
685 name="<?php echo esc_attr( $value['id'] ); ?>"
686 value="<?php echo $key; ?>"
687 type="radio"
688 style="<?php echo esc_attr( $value['css'] ); ?>"
689 <?php echo implode( ' ', $custom_attributes ); ?>
690 <?php checked( $key, $option_value ); ?>
691 /> <?php echo $val ?></label>
692 </li>
693 <?php
694 }
695 ?>
696 <?php echo $description; ?>
697 </fieldset>
698 </td>
699 </tr><?php
700 break;
701
702 // Checkbox input.
703 case 'checkbox' :
704 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
705 ?>
706 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
707 <th scope="row" class="titledesc">
708 <label
709 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
710 </th>
711 <td class="give-forminp">
712 <input
713 name="<?php echo esc_attr( $value['id'] ); ?>"
714 id="<?php echo esc_attr( $value['id'] ); ?>"
715 type="checkbox"
716 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
717 value="1"
718 <?php checked( $option_value, 'on' ); ?>
719 <?php echo implode( ' ', $custom_attributes ); ?>
720 />
721 <?php echo $description; ?>
722 </td>
723 </tr>
724 <?php
725 break;
726
727 // Multi Checkbox input.
728 case 'multicheck' :
729 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
730 $option_value = is_array( $option_value ) ? $option_value : array();
731 ?>
732 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
733 <th scope="row" class="titledesc">
734 <label
735 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
736 </th>
737 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
738 <fieldset>
739 <ul>
740 <?php
741 foreach ( $value['options'] as $key => $val ) {
742 ?>
743 <li>
744 <label>
745 <input
746 name="<?php echo esc_attr( $value['id'] ); ?>[]"
747 value="<?php echo $key; ?>"
748 type="checkbox"
749 style="<?php echo esc_attr( $value['css'] ); ?>"
750 <?php echo implode( ' ', $custom_attributes ); ?>
751 <?php if ( in_array( $key, $option_value ) ) {
752 echo 'checked="checked"';
753 } ?>
754 /> <?php echo $val ?>
755 </label>
756 </li>
757 <?php
758 }
759 ?>
760 <?php echo $description; ?>
761 </fieldset>
762 </td>
763 </tr>
764 <?php
765 break;
766
767 // File input field.
768 case 'file' :
769 case 'media' :
770 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
771 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
772 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
773
774 $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
775 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
776 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
777 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
778 ?>
779 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
780 <th scope="row" class="titledesc">
781 <label
782 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
783 </th>
784 <td class="give-forminp">
785 <div class="give-field-wrap">
786 <label for="<?php echo $value['id'] ?>">
787 <input
788 name="<?php echo esc_attr( $value['id'] ); ?>"
789 id="<?php echo esc_attr( $value['id'] ); ?>"
790 type="text"
791 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
792 value="<?php echo $option_value; ?>"
793 style="<?php echo esc_attr( $value['css'] ); ?>"
794 <?php echo implode( ' ', $custom_attributes ); ?>
795 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
796 data-fvalue="<?php echo $fvalue; ?>"
797 data-field-type="<?php echo $value['type']; ?>"
798 value="<?php echo $button_label; ?>">
799 <?php echo $description ?>
800 <div
801 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
802 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
803 <img src="<?php echo $preview_image_src; ?>" alt="">
804 </div>
805 </label>
806 </div>
807 </td>
808 </tr>
809 <?php
810 break;
811
812 // WordPress Editor.
813 case 'wysiwyg' :
814 // Get option value.
815 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
816
817 // Get editor settings.
818 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
819 ?>
820 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
821 <th scope="row" class="titledesc">
822 <label
823 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
824 </th>
825 <td class="give-forminp">
826 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
827 <?php echo $description; ?>
828 </td>
829 </tr><?php
830 break;
831
832 // Custom: Email preview buttons field.
833 case 'email_preview_buttons' :
834 ?>
835 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
836 <th scope="row" class="titledesc">
837 <label
838 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
839 </th>
840 <td class="give-forminp">
841 <?php give_email_preview_buttons_callback( $value ); ?>
842 <?php echo $description; ?>
843 </td>
844 </tr><?php
845 break;
846
847 // Custom: API field.
848 case 'api' :
849 give_api_callback();
850 echo $description;
851 break;
852
853 // Custom: Gateway API key.
854 case 'api_key' :
855 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
856 $type = ! empty( $option_value ) ? 'password' : 'text';
857 ?>
858 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
859 <th scope="row" class="titledesc">
860 <label
861 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
862 </th>
863 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
864 <input
865 name="<?php echo esc_attr( $value['id'] ); ?>"
866 id="<?php echo esc_attr( $value['id'] ); ?>"
867 type="<?php echo esc_attr( $type ); ?>"
868 style="<?php echo esc_attr( $value['css'] ); ?>"
869 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
870 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
871 <?php echo implode( ' ', $custom_attributes ); ?>
872 /> <?php echo $description; ?>
873 </td>
874 </tr><?php
875 break;
876
877 // Note: only for internal use.
878 case 'chosen' :
879
880 // Get option value.
881 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
882 $option_value = is_array( $option_value ) ? array_fill_keys( $option_value, 'selected' ) : $option_value;
883 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
884 $type = '';
885 $allow_new_values = '';
886 $name = give_get_field_name( $value );
887
888 // Set attributes based on multiselect datatype.
889 if ( 'multiselect' === $value['data_type'] ) {
890 $type = 'multiple';
891 $allow_new_values = 'data-allows-new-values="true"';
892 $name = $name . '[]';
893 $option_value = empty( $option_value ) ? array() : $option_value;
894 }
895
896 $title_prefixes_value = ( is_array( $option_value ) && count( $option_value ) > 0 ) ?
897 array_merge( $value['options'], $option_value ) :
898 $value['options'];
899
900 ?>
901 <tr valign="top" <?php echo $wrapper_class; ?>>
902 <th scope="row" class="titledesc">
903 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
904 </th>
905 <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
906 <select
907 class="give-select-chosen give-chosen-settings"
908 style="<?php echo esc_attr( $value['style'] ); ?>"
909 name="<?php echo esc_attr( $name ); ?>"
910 id="<?php echo esc_attr( $value['id'] ); ?>"
911 <?php
912 echo "{$type} {$allow_new_values}";
913 echo implode( ' ', $custom_attributes );
914 ?>
915 >
916 <?php
917 if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) {
918 foreach ( $title_prefixes_value as $key => $item_value ) {
919 echo sprintf(
920 '<option %1$s value="%2$s">%2$s</option>',
921 ( 'selected' === $item_value ) ? 'selected="selected"' : '',
922 esc_attr( $key )
923 );
924 }
925 }
926 ?>
927 </select>
928 <?php echo wp_kses_post( $description ); ?>
929 </td>
930 </tr>
931 <?php
932 break;
933
934 // Custom: Log field.
935 case 'logs' :
936
937 // Get current section.
938 $current_section = $_GET['section'] = give_get_current_setting_section();
939
940 /**
941 * Fires for each tab of logs view.
942 *
943 * @since 1.0
944 */
945 do_action( "give_logs_view_{$current_section}" );
946
947 echo $description;
948 break;
949
950 // Custom: Data field.
951 case 'data' :
952
953 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
954
955 echo $description;
956 break;
957
958 // Custom: Give Docs Link field type.
959 case 'give_docs_link' :
960 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
961 ?>
962 <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
963 <td class="give-docs-link" colspan="2">
964 <p class="give-docs-link">
965 <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
966 <?php
967 echo sprintf(
968 /* translators: %s Title */
969 esc_html__( 'Need Help? See docs on "%s"', 'give' ),
970 esc_html( $value['title'] )
971 );
972 ?>
973 <span class="dashicons dashicons-editor-help"></span>
974 </a>
975 </p>
976 </td>
977 </tr><?php
978 break;
979
980 // Default: run an action
981 // You can add or handle your custom field action.
982 default:
983 // Get option value.
984 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
985 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
986 break;
987 }
988 }
989
990 /**
991 * Helper function to get the formatted description for a given form field.
992 * Plugins can call this when implementing their own custom settings types.
993 *
994 * @since 1.8
995 *
996 * @param array $value The form field value array
997 *
998 * @return string The HTML description of the field.
999 */
1000 public static function get_field_description( $value ) {
1001 $description = '';
1002
1003 // Support for both 'description' and 'desc' args.
1004 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
1005 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
1006
1007 if ( ! empty( $value ) ) {
1008 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
1009 }
1010
1011 return $description;
1012 }
1013
1014
1015 /**
1016 * Helper function to get the formated title.
1017 * Plugins can call this when implementing their own custom settings types.
1018 *
1019 * @since 1.8
1020 *
1021 * @param array $value The form field value array
1022 *
1023 * @return array The description and tip as a 2 element array
1024 */
1025 public static function get_field_title( $value ) {
1026 $title = esc_html( $value['title'] );
1027
1028 // If html tag detected then allow them to print.
1029 if ( strip_tags( $title ) ) {
1030 $title = $value['title'];
1031 }
1032
1033 return $title;
1034 }
1035
1036 /**
1037 * Save admin fields.
1038 *
1039 * Loops though the give options array and outputs each field.
1040 *
1041 * @since 1.8
1042 *
1043 * @param array $options Options array to output
1044 * @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.
1045 *
1046 * @return bool
1047 */
1048 public static function save_fields( $options, $option_name = '' ) {
1049
1050 // Fetch form posted super global data.
1051 $post_data = give_clean( $_POST );
1052
1053 // Bailout, if posted data doesn't exists.
1054 if ( empty( $post_data ) ) {
1055 return false;
1056 }
1057
1058 $new_options = array();
1059 $options_keys = array_keys( $options );
1060 $is_vertical_tabs = is_array( $options_keys ) && count( $options_keys ) > 0 ? ctype_alnum( $options_keys[0] ) : false;
1061
1062 if ( $is_vertical_tabs ) {
1063
1064 // Loop through each vertical tabs related field options to destructure into single array.
1065 foreach( $options as $option ) {
1066 $new_options = array_merge( $new_options, $option );
1067 }
1068
1069 // Assign new field options.
1070 $options = $new_options;
1071 }
1072
1073 // Options to update will be stored here and saved later.
1074 $update_options = array();
1075
1076 // Loop options and get values to save.
1077 foreach ( $options as $option ) {
1078 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
1079 continue;
1080 }
1081
1082 // Get posted value.
1083 if ( strstr( $option['id'], '[' ) ) {
1084 parse_str( $option['id'], $option_name_array );
1085 $field_option_name = current( array_keys( $option_name_array ) );
1086 $setting_name = key( $option_name_array[ $field_option_name ] );
1087 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
1088 } else {
1089 $field_option_name = $option['id'];
1090 $setting_name = '';
1091 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
1092 }
1093
1094 // Format the value based on option type.
1095 switch ( $option['type'] ) {
1096 case 'checkbox' :
1097 $value = is_null( $raw_value ) ? '' : 'on';
1098 break;
1099 case 'wysiwyg' :
1100 case 'textarea' :
1101 $value = wp_kses_post( trim( $raw_value ) );
1102 break;
1103 case 'multiselect' :
1104 case 'chosen' :
1105 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
1106 break;
1107 default :
1108 $value = give_clean( $raw_value );
1109 break;
1110 }
1111
1112 /**
1113 * Sanitize the value of an option.
1114 *
1115 * @since 1.8
1116 */
1117 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
1118
1119 /**
1120 * Sanitize the value of an option by option name.
1121 *
1122 * @since 1.8
1123 */
1124 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
1125
1126 if ( is_null( $value ) ) {
1127 continue;
1128 }
1129
1130 // Check if option is an array and handle that differently to single values.
1131 if ( $field_option_name && $setting_name ) {
1132 if ( ! isset( $update_options[ $field_option_name ] ) ) {
1133 $update_options[ $field_option_name ] = get_option( $field_option_name, array() );
1134 }
1135 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
1136 $update_options[ $field_option_name ] = array();
1137 }
1138 $update_options[ $field_option_name ][ $setting_name ] = $value;
1139 } else {
1140 $update_options[ $field_option_name ] = $value;
1141 }
1142 }
1143
1144 // Save all options in our array or there own option name i.e. option id.
1145 if ( empty( $option_name ) ) {
1146 foreach ( $update_options as $name => $value ) {
1147 update_option( $name, $value, false );
1148
1149 /**
1150 * Trigger action.
1151 *
1152 * Note: This is dynamically fire on basis of option name.
1153 *
1154 * @since 1.8
1155 */
1156 do_action( "give_save_option_{$name}", $value, $name );
1157 }
1158 } else {
1159 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
1160 $update_options = array_merge( $old_options, $update_options );
1161
1162 update_option( $option_name, $update_options, false );
1163
1164 /**
1165 * Trigger action.
1166 *
1167 * Note: This is dynamically fire on basis of setting name.
1168 *
1169 * @since 1.8
1170 */
1171 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1172 }
1173
1174 return true;
1175 }
1176
1177
1178 /**
1179 * Check if admin saving setting or not.
1180 *
1181 * @since 1.8.17
1182 *
1183 * @return bool
1184 */
1185 public static function is_saving_settings() {
1186 return self::verify_nonce();
1187 }
1188
1189 /**
1190 * Verify setting page
1191 *
1192 * @since 2.0
1193 * @access public
1194 *
1195 * @param string $tab
1196 * @param string $section
1197 *
1198 * @return bool
1199 */
1200 public static function is_setting_page( $tab = '', $section = '' ) {
1201 $is_setting_page = false;
1202
1203 // Are we accessing admin?
1204 if( ! is_admin() ) {
1205 return $is_setting_page;
1206 }
1207
1208 // Are we accessing any give page?
1209 if(
1210 ! isset( $_GET['post_type'], $_GET['page'] )
1211 || 'give_forms' !== give_clean( $_GET['post_type'] )
1212 ) {
1213 return $is_setting_page;
1214 }
1215
1216 // Check fo setting tab.
1217 if ( ! empty( $tab ) ) {
1218 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1219 }
1220
1221 // Check fo setting section.
1222 if ( ! empty( $section ) ) {
1223 $is_setting_page = ( $section === give_get_current_setting_section() );
1224 }
1225
1226 return $is_setting_page;
1227 }
1228 }
1229
1230 endif;
1231