PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.5
GiveWP – Donation Plugin and Fundraising Platform v2.1.5
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
donors 8 years ago emails 8 years ago forms 8 years ago payments 8 years ago reports 8 years ago settings 8 years ago shortcodes 8 years ago tools 8 years ago upgrades 8 years ago views 8 years ago EDD_SL_Plugin_Updater.php 8 years ago abstract-admin-settings-page.php 8 years ago add-ons.php 8 years ago admin-actions.php 8 years ago admin-filters.php 8 years ago admin-footer.php 8 years ago admin-pages.php 8 years ago class-addon-activation-banner.php 8 years ago class-admin-settings.php 8 years ago class-api-keys-table.php 8 years ago class-blank-slate.php 8 years ago class-give-settings.php 8 years ago class-i18n-module.php 8 years ago dashboard-widgets.php 8 years ago give-metabox-functions.php 8 years ago plugins.php 8 years ago welcome.php 8 years ago
class-admin-settings.php
1065 lines
1 <?php
2 /**
3 * Give Admin Settings Class
4 *
5 * @package Give
6 * @subpackage Classes/Give_Admin_Settings
7 * @copyright Copyright (c) 2016, WordImpress
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 * Varify 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>' . __( 'Action failed. Please refresh the page and retry.', 'give' ) . '</p></div>';
107 die();
108 }
109
110 // Show error message if Akismet not configured and Admin try to save 'enabled' option.
111 if ( isset( $_POST['akismet_spam_protection'] )
112 && give_is_setting_enabled( $_POST['akismet_spam_protection'] )
113 && ! give_check_akismet_key()
114 ) {
115 self::add_error( 'give-akismet-protection', __( 'Please properly configure Akismet to enable SPAM protection.', 'give' ) );
116
117 return;
118 }
119
120 /**
121 * Trigger Action.
122 *
123 * Note: action dynamically fire on basis of setting page slug and current tab.
124 * For example: if you register a setting page with give-settings menu slug and general current tab name
125 * then action will be give-settings_save_general
126 *
127 * @since 1.8
128 */
129 do_action( self::$setting_filter_prefix . '_save_' . $current_tab );
130
131 self::add_message( 'give-setting-updated', __( 'Your settings have been saved.', 'give' ) );
132
133 /**
134 * Trigger Action.
135 *
136 * Note: action dynamically fire on basis of setting page slug.
137 * For example: if you register a setting page with give-settings menu slug
138 * then action will be give-settings_saved
139 *
140 * @since 1.8
141 */
142 do_action( self::$setting_filter_prefix . '_saved' );
143 }
144
145 /**
146 * Add a message.
147 *
148 * @since 1.8
149 *
150 * @param string $code Message code (Note: This should be unique).
151 * @param string $message Message text.
152 *
153 * @return void
154 */
155 public static function add_message( $code, $message ) {
156 self::$messages[ $code ] = $message;
157 }
158
159 /**
160 * Add an error.
161 *
162 * @since 1.8
163 *
164 * @param string $code Message code (Note: This should be unique).
165 * @param string $message Message text.
166 *
167 * @return void
168 */
169 public static function add_error( $code, $message ) {
170 self::$errors[ $code ] = $message;
171 }
172
173 /**
174 * Output messages + errors.
175 *
176 * @since 1.8
177 * @return void
178 */
179 public static function show_messages() {
180 $notice_html = '';
181 $classes = 'give-notice settings-error notice is-dismissible';
182
183 self::$errors = apply_filters( self::$setting_filter_prefix . '_error_notices', self::$errors );
184 self::$messages = apply_filters( self::$setting_filter_prefix . '_update_notices', self::$messages );
185
186 if ( 0 < count( self::$errors ) ) {
187 foreach ( self::$errors as $code => $message ) {
188 $notice_html .= sprintf(
189 '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p><strong>%3$s</strong></p></div>',
190 $code,
191 $classes,
192 $message
193 );
194 }
195 }
196
197 if ( 0 < count( self::$messages ) ) {
198 foreach ( self::$messages as $code => $message ) {
199 $notice_html .= sprintf(
200 '<div id="setting-error-%1$s" class="%2$s updated" style="display: none"><p><strong>%3$s</strong></p></div>',
201 $code,
202 $classes,
203 $message
204 );
205 }
206 }
207
208 echo $notice_html;
209 }
210
211 /**
212 * Settings page.
213 *
214 * Handles the display of the main give settings page in admin.
215 *
216 * @since 1.8
217 * @return bool
218 */
219 public static function output() {
220 // Get current setting page.
221 self::$setting_filter_prefix = give_get_current_setting_page();
222
223 // Bailout: Exit if setting page is not defined.
224 if ( empty( self::$setting_filter_prefix ) ) {
225 return false;
226 }
227
228 /**
229 * Trigger Action.
230 *
231 * Note: action dynamically fire on basis of setting page slug
232 * For example: if you register a setting page with give-settings menu slug
233 * then action will be give-settings_start
234 *
235 * @since 1.8
236 */
237 do_action( self::$setting_filter_prefix . '_start' );
238
239 $current_tab = give_get_current_setting_tab();
240
241 // Include settings pages.
242 $all_setting = self::get_settings_pages();
243
244 /* @var object $current_setting_obj */
245 $current_setting_obj = new StdClass;
246
247 foreach ( $all_setting as $setting ) {
248 if (
249 method_exists( $setting, 'get_id' ) &&
250 $current_tab === $setting->get_id()
251 ) {
252 $current_setting_obj = $setting;
253 break;
254 }
255 }
256
257 // Save settings if data has been posted.
258 if ( ! empty( $_POST ) ) {
259 self::save();
260 }
261
262 /**
263 * Filter the tabs for current setting page.
264 *
265 * Note: filter dynamically fire on basis of setting page slug.
266 * For example: if you register a setting page with give-settings menu slug and general current tab name
267 * then action will be give-settings_tabs_array
268 *
269 * @since 1.8
270 */
271 $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', array() );
272
273 include 'views/html-admin-settings.php';
274
275 return true;
276 }
277
278 /**
279 * Get a setting from the settings API.
280 *
281 * @since 1.8
282 *
283 * @param string $option_name
284 * @param string $field_id
285 * @param mixed $default
286 *
287 * @return string|bool
288 */
289 public static function get_option( $option_name = '', $field_id = '', $default = false ) {
290 // Bailout.
291 if ( empty( $option_name ) && empty( $field_id ) ) {
292 return false;
293 }
294
295 if ( ! empty( $field_id ) && ! empty( $option_name ) ) {
296 // Get field value if any.
297 $option_value = get_option( $option_name );
298
299 $option_value = ( is_array( $option_value ) && array_key_exists( $field_id, $option_value ) )
300 ? $option_value[ $field_id ]
301 : $default;
302 } else {
303 // If option name is empty but not field name then this means, setting is direct store to option table under there field name.
304 $option_name = ! $option_name ? $field_id : $option_name;
305
306 // Get option value if any.
307 $option_value = get_option( $option_name, $default );
308 }
309
310 return $option_value;
311 }
312
313 /**
314 * Output admin fields.
315 *
316 * Loops though the give options array and outputs each field.
317 *
318 * @todo : Refactor this function
319 * @since 1.8
320 *
321 * @param array $options Opens array to output
322 * @param string $option_name Opens array to output
323 *
324 * @return void
325 */
326 public static function output_fields( $options, $option_name = '' ) {
327 $current_tab = give_get_current_setting_tab();
328
329 // Field Default values.
330 $defaults = array(
331 'id' => '',
332 'class' => '',
333 'css' => '',
334 'default' => '',
335 'desc' => '',
336 'table_html' => true,
337 'repeat' => false,
338 'repeat_btn_title' => __( 'Add Field', 'give' ),
339 );
340
341 foreach ( $options as $value ) {
342 if ( ! isset( $value['type'] ) ) {
343 continue;
344 }
345
346 // Set title.
347 $defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
348
349 // Set default setting.
350 $value = wp_parse_args( $value, $defaults );
351
352 // Colorpicker field.
353 $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
354 $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
355
356
357 // Custom attribute handling.
358 $custom_attributes = array();
359
360 if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
361 foreach ( $value['attributes'] as $attribute => $attribute_value ) {
362 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
363 }
364 }
365
366 // Description handling.
367 $description = self::get_field_description( $value );
368
369 // Switch based on type.
370 switch ( $value['type'] ) {
371
372 // Section Titles
373 case 'title':
374 if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) {
375 ?>
376 <div class="give-setting-tab-header give-setting-tab-header-<?php echo $current_tab; ?>">
377 <?php if ( ! empty( $value['title'] ) ) : ?>
378 <h2><?php echo self::get_field_title( $value ); ?></h2>
379 <hr>
380 <?php endif; ?>
381
382 <?php if ( ! empty( $value['desc'] ) ) : ?>
383 <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
384 <?php endif; ?>
385 </div>
386 <?php
387 }
388
389 if ( $value['table_html'] ) {
390 echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
391 }
392
393 if ( ! empty( $value['id'] ) ) {
394
395 /**
396 * Trigger Action.
397 *
398 * Note: action dynamically fire on basis of field id.
399 *
400 * @since 1.8
401 */
402 do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
403 }
404
405 break;
406
407 // Section Ends.
408 case 'sectionend':
409 if ( ! empty( $value['id'] ) ) {
410
411 /**
412 * Trigger Action.
413 *
414 * Note: action dynamically fire on basis of field id.
415 *
416 * @since 1.8
417 */
418 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
419 }
420
421 if ( $value['table_html'] ) {
422 echo '</table>';
423 }
424
425 if ( ! empty( $value['id'] ) ) {
426
427 /**
428 * Trigger Action.
429 *
430 * Note: action dynamically fire on basis of field id.
431 *
432 * @since 1.8
433 */
434 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
435 }
436
437 break;
438
439 // Standard text inputs and subtypes like 'number'.
440 case 'colorpicker':
441 case 'hidden' :
442 $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
443 case 'text':
444 case 'email':
445 case 'number':
446 case 'password' :
447 $type = $value['type'];
448 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
449
450 // Set default value for repeater field if not any value set yet.
451 if ( $value['repeat'] && is_string( $option_value ) ) {
452 $option_value = array( $value['default'] );
453 }
454 ?>
455 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
456 <th scope="row" class="titledesc">
457 <label
458 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
459 </th>
460 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
461 <?php if ( $value['repeat'] ) : ?>
462 <?php foreach ( $option_value as $index => $field_value ) : ?>
463 <p>
464 <input
465 name="<?php echo esc_attr( $value['id'] ); ?>[]"
466 type="<?php echo esc_attr( $type ); ?>"
467 style="<?php echo esc_attr( $value['css'] ); ?>"
468 value="<?php echo esc_attr( $field_value ); ?>"
469 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
470 <?php echo implode( ' ', $custom_attributes ); ?>
471 />
472 <span class="give-remove-setting-field"
473 title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
474 </p>
475 <?php endforeach; ?>
476 <a href="#" data-id="<?php echo $value['id']; ?>"
477 class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
478 <?php else : ?>
479 <input
480 name="<?php echo esc_attr( $value['id'] ); ?>"
481 id="<?php echo esc_attr( $value['id'] ); ?>"
482 type="<?php echo esc_attr( $type ); ?>"
483 style="<?php echo esc_attr( $value['css'] ); ?>"
484 value="<?php echo esc_attr( $option_value ); ?>"
485 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
486 <?php echo implode( ' ', $custom_attributes ); ?>
487 />
488 <?php endif; ?>
489 <?php echo $description; ?>
490 </td>
491 </tr><?php
492 break;
493
494 // Textarea.
495 case 'textarea':
496
497 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
498
499 ?>
500 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
501 <th scope="row" class="titledesc">
502 <label
503 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
504 </th>
505 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
506 <textarea
507 name="<?php echo esc_attr( $value['id'] ); ?>"
508 id="<?php echo esc_attr( $value['id'] ); ?>"
509 style="<?php echo esc_attr( $value['css'] ); ?>"
510 class="<?php echo esc_attr( $value['class'] ); ?>"
511 rows="10"
512 cols="60"
513 <?php echo implode( ' ', $custom_attributes ); ?>
514 ><?php echo esc_textarea( $option_value ); ?></textarea>
515 <?php echo $description; ?>
516 </td>
517 </tr><?php
518 break;
519
520 // Select boxes.
521 case 'select' :
522 case 'multiselect' :
523 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
524
525 /**
526 * insert page in option if missing.
527 *
528 * check success_page setting in general settings.
529 */
530 if(
531 isset( $value['attributes' ] ) &&
532 false !== strpos( $value['class'], 'give-select-chosen' ) &&
533 in_array( 'data-search-type', array_keys( $value['attributes' ] ) ) &&
534 'pages' == $value['attributes' ]['data-search-type'] &&
535 ! in_array( $option_value, array_keys( $value['options'] ) )
536 ) {
537 $value['options'][$option_value] = get_the_title( $option_value );
538 }
539 ?>
540 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
541 <th scope="row" class="titledesc">
542 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
543 </th>
544 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
545 <select
546 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
547 id="<?php echo esc_attr( $value['id'] ); ?>"
548 style="<?php echo esc_attr( $value['css'] ); ?>"
549 class="<?php echo esc_attr( $value['class'] ); ?>"
550 <?php echo implode( ' ', $custom_attributes ); ?>
551 <?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
552 >
553
554 <?php
555 if ( ! empty( $value['options'] ) ) {
556 foreach ( $value['options'] as $key => $val ) {
557 ?>
558 <option value="<?php echo esc_attr( $key ); ?>" <?php
559
560 if ( is_array( $option_value ) ) {
561 selected( in_array( $key, $option_value ), true );
562 } else {
563 selected( $option_value, $key );
564 }
565
566 ?>><?php echo $val ?></option>
567 <?php
568 }
569 }
570 ?>
571
572 </select> <?php echo $description; ?>
573 </td>
574 </tr><?php
575 break;
576
577 // Radio inputs.
578 case 'radio_inline' :
579 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
580 case 'radio' :
581 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
582 ?>
583 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
584 <th scope="row" class="titledesc">
585 <label
586 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
587 </th>
588 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
589 <fieldset>
590 <ul>
591 <?php
592 foreach ( $value['options'] as $key => $val ) {
593 ?>
594 <li>
595 <label><input
596 name="<?php echo esc_attr( $value['id'] ); ?>"
597 value="<?php echo $key; ?>"
598 type="radio"
599 style="<?php echo esc_attr( $value['css'] ); ?>"
600 <?php echo implode( ' ', $custom_attributes ); ?>
601 <?php checked( $key, $option_value ); ?>
602 /> <?php echo $val ?></label>
603 </li>
604 <?php
605 }
606 ?>
607 <?php echo $description; ?>
608 </fieldset>
609 </td>
610 </tr><?php
611 break;
612
613 // Checkbox input.
614 case 'checkbox' :
615 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
616 ?>
617 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
618 <th scope="row" class="titledesc">
619 <label
620 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
621 </th>
622 <td class="give-forminp">
623 <input
624 name="<?php echo esc_attr( $value['id'] ); ?>"
625 id="<?php echo esc_attr( $value['id'] ); ?>"
626 type="checkbox"
627 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
628 value="1"
629 <?php checked( $option_value, 'on' ); ?>
630 <?php echo implode( ' ', $custom_attributes ); ?>
631 />
632 <?php echo $description; ?>
633 </td>
634 </tr>
635 <?php
636 break;
637
638 // Multi Checkbox input.
639 case 'multicheck' :
640 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
641 $option_value = is_array( $option_value ) ? $option_value : array();
642 ?>
643 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
644 <th scope="row" class="titledesc">
645 <label
646 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
647 </th>
648 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
649 <fieldset>
650 <ul>
651 <?php
652 foreach ( $value['options'] as $key => $val ) {
653 ?>
654 <li>
655 <label>
656 <input
657 name="<?php echo esc_attr( $value['id'] ); ?>[]"
658 value="<?php echo $key; ?>"
659 type="checkbox"
660 style="<?php echo esc_attr( $value['css'] ); ?>"
661 <?php echo implode( ' ', $custom_attributes ); ?>
662 <?php if ( in_array( $key, $option_value ) ) {
663 echo 'checked="checked"';
664 } ?>
665 /> <?php echo $val ?>
666 </label>
667 </li>
668 <?php
669 }
670 ?>
671 <?php echo $description; ?>
672 </fieldset>
673 </td>
674 </tr>
675 <?php
676 break;
677
678 // File input field.
679 case 'file' :
680 case 'media' :
681 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
682 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
683 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
684
685 $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
686 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
687 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
688 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
689 ?>
690 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
691 <th scope="row" class="titledesc">
692 <label
693 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
694 </th>
695 <td class="give-forminp">
696 <div class="give-field-wrap">
697 <label for="<?php echo $value['id'] ?>">
698 <input
699 name="<?php echo esc_attr( $value['id'] ); ?>"
700 id="<?php echo esc_attr( $value['id'] ); ?>"
701 type="text"
702 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
703 value="<?php echo $option_value; ?>"
704 style="<?php echo esc_attr( $value['css'] ); ?>"
705 <?php echo implode( ' ', $custom_attributes ); ?>
706 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
707 data-fvalue="<?php echo $fvalue; ?>"
708 data-field-type="<?php echo $value['type']; ?>"
709 value="<?php echo $button_label; ?>">
710 <?php echo $description ?>
711 <div
712 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
713 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
714 <img src="<?php echo $preview_image_src; ?>" alt="">
715 </div>
716 </label>
717 </div>
718 </td>
719 </tr>
720 <?php
721 break;
722
723 // WordPress Editor.
724 case 'wysiwyg' :
725 // Get option value.
726 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
727
728 // Get editor settings.
729 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
730 ?>
731 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
732 <th scope="row" class="titledesc">
733 <label
734 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
735 </th>
736 <td class="give-forminp">
737 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
738 <?php echo $description; ?>
739 </td>
740 </tr><?php
741 break;
742
743 // Custom: Default gateways setting field.
744 case 'default_gateway' :
745 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
746 ?>
747 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
748 <th scope="row" class="titledesc">
749 <label
750 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
751 </th>
752 <td class="give-forminp">
753 <?php give_default_gateway_callback( $value, $option_value ); ?>
754 <?php echo $description; ?>
755 </td>
756 </tr><?php
757 break;
758
759 // Custom: Email preview buttons field.
760 case 'email_preview_buttons' :
761 ?>
762 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
763 <th scope="row" class="titledesc">
764 <label
765 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
766 </th>
767 <td class="give-forminp">
768 <?php give_email_preview_buttons_callback( $value ); ?>
769 <?php echo $description; ?>
770 </td>
771 </tr><?php
772 break;
773
774 // Custom: API field.
775 case 'api' :
776 give_api_callback();
777 echo $description;
778 break;
779
780 // Custom: Gateway API key.
781 case 'api_key' :
782 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
783 $type = ! empty( $option_value ) ? 'password' : 'text';
784 ?>
785 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
786 <th scope="row" class="titledesc">
787 <label
788 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
789 </th>
790 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
791 <input
792 name="<?php echo esc_attr( $value['id'] ); ?>"
793 id="<?php echo esc_attr( $value['id'] ); ?>"
794 type="<?php echo esc_attr( $type ); ?>"
795 style="<?php echo esc_attr( $value['css'] ); ?>"
796 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
797 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
798 <?php echo implode( ' ', $custom_attributes ); ?>
799 /> <?php echo $description; ?>
800 </td>
801 </tr><?php
802 break;
803
804 // Custom: Log field.
805 case 'logs' :
806
807 // Get current section.
808 $current_section = $_GET['section'] = give_get_current_setting_section();
809
810 /**
811 * Fires for each tab of logs view.
812 *
813 * @since 1.0
814 */
815 do_action( "give_logs_view_{$current_section}" );
816
817 echo $description;
818 break;
819
820 // Custom: Data field.
821 case 'data' :
822
823 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
824
825 echo $description;
826 break;
827
828 // Custom: Give Docs Link field type.
829 case 'give_docs_link' :
830 ?>
831 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
832 <td class="give-docs-link" colspan="2">
833 <?php
834 echo '<p class="give-docs-link"><a href="' . esc_url( $value['url'] )
835 . '" target="_blank">'
836 . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $value['title'] )
837 . '<span class="dashicons dashicons-editor-help"></span></a></p>';
838 ?>
839 </td>
840 </tr><?php
841 break;
842
843 // Default: run an action
844 // You can add or handle your custom field action.
845 default:
846 // Get option value.
847 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
848 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
849 break;
850 }
851 }
852 }
853
854 /**
855 * Helper function to get the formatted description for a given form field.
856 * Plugins can call this when implementing their own custom settings types.
857 *
858 * @since 1.8
859 *
860 * @param array $value The form field value array
861 *
862 * @return string The HTML description of the field.
863 */
864 public static function get_field_description( $value ) {
865 $description = '';
866
867 // Support for both 'description' and 'desc' args.
868 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
869 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
870
871 if ( ! empty( $value ) ) {
872 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
873 }
874
875 return $description;
876 }
877
878
879 /**
880 * Helper function to get the formated title.
881 * Plugins can call this when implementing their own custom settings types.
882 *
883 * @since 1.8
884 *
885 * @param array $value The form field value array
886 *
887 * @return array The description and tip as a 2 element array
888 */
889 public static function get_field_title( $value ) {
890 $title = esc_html( $value['title'] );
891
892 // If html tag detected then allow them to print.
893 if ( strip_tags( $title ) ) {
894 $title = $value['title'];
895 }
896
897 return $title;
898 }
899
900 /**
901 * Save admin fields.
902 *
903 * Loops though the give options array and outputs each field.
904 *
905 * @since 1.8
906 *
907 * @param array $options Options array to output
908 * @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.
909 *
910 * @return bool
911 */
912 public static function save_fields( $options, $option_name = '' ) {
913 if ( empty( $_POST ) ) {
914 return false;
915 }
916
917 // Options to update will be stored here and saved later.
918 $update_options = array();
919
920 // Loop options and get values to save.
921 foreach ( $options as $option ) {
922 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
923 continue;
924 }
925
926 // Get posted value.
927 if ( strstr( $option['id'], '[' ) ) {
928 parse_str( $option['id'], $option_name_array );
929 $field_option_name = current( array_keys( $option_name_array ) );
930 $setting_name = key( $option_name_array[ $field_option_name ] );
931 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
932 } else {
933 $field_option_name = $option['id'];
934 $setting_name = '';
935 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
936 }
937
938 // Format the value based on option type.
939 switch ( $option['type'] ) {
940 case 'checkbox' :
941 $value = is_null( $raw_value ) ? '' : 'on';
942 break;
943 case 'wysiwyg' :
944 case 'textarea' :
945 $value = wp_kses_post( trim( $raw_value ) );
946 break;
947 case 'multiselect' :
948 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
949 break;
950 default :
951 $value = give_clean( $raw_value );
952 break;
953 }
954
955 /**
956 * Sanitize the value of an option.
957 *
958 * @since 1.8
959 */
960 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
961
962 /**
963 * Sanitize the value of an option by option name.
964 *
965 * @since 1.8
966 */
967 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
968
969 if ( is_null( $value ) ) {
970 continue;
971 }
972
973 // Check if option is an array and handle that differently to single values.
974 if ( $field_option_name && $setting_name ) {
975 if ( ! isset( $update_options[ $field_option_name ] ) ) {
976 $update_options[ $field_option_name ] = get_option( $field_option_name, array() );
977 }
978 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
979 $update_options[ $field_option_name ] = array();
980 }
981 $update_options[ $field_option_name ][ $setting_name ] = $value;
982 } else {
983 $update_options[ $field_option_name ] = $value;
984 }
985 }
986
987 // Save all options in our array or there own option name i.e. option id.
988 if ( empty( $option_name ) ) {
989 foreach ( $update_options as $name => $value ) {
990 update_option( $name, $value );
991
992 /**
993 * Trigger action.
994 *
995 * Note: This is dynamically fire on basis of option name.
996 *
997 * @since 1.8
998 */
999 do_action( "give_save_option_{$name}", $value, $name );
1000 }
1001 } else {
1002 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
1003 $update_options = array_merge( $old_options, $update_options );
1004
1005 update_option( $option_name, $update_options );
1006
1007 /**
1008 * Trigger action.
1009 *
1010 * Note: This is dynamically fire on basis of setting name.
1011 *
1012 * @since 1.8
1013 */
1014 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1015 }
1016
1017 return true;
1018 }
1019
1020
1021 /**
1022 * Check if admin saving setting or not.
1023 *
1024 * @since 1.8.17
1025 *
1026 * @return bool
1027 */
1028 public static function is_saving_settings() {
1029 return self::verify_nonce();
1030 }
1031
1032 /**
1033 * Verify setting page
1034 *
1035 * @since 2.0
1036 * @access public
1037 *
1038 * @param string $tab
1039 * @param string $section
1040 *
1041 * @return bool
1042 */
1043 public static function is_setting_page( $tab = '', $section = '' ) {
1044 $is_setting_page = false;
1045
1046 if( ! is_admin() ) {
1047 return $is_setting_page;
1048 }
1049
1050 // Check fo setting tab.
1051 if ( ! empty( $tab ) ) {
1052 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1053 }
1054
1055 // Check fo setting section.
1056 if ( ! empty( $section ) ) {
1057 $is_setting_page = ( $section === give_get_current_setting_section() );
1058 }
1059
1060 return $is_setting_page;
1061 }
1062 }
1063
1064 endif;
1065