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