PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.0
GiveWP – Donation Plugin and Fundraising Platform v2.1.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-admin-settings.php
give / includes / admin Last commit date
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
1051 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>
369 <hr>
370 <?php endif; ?>
371
372 <?php if ( ! empty( $value['desc'] ) ) : ?>
373 <?php echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); ?>
374 <?php endif; ?>
375 </div>
376 <?php
377 }
378
379 if ( $value['table_html'] ) {
380 echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
381 }
382
383 if ( ! empty( $value['id'] ) ) {
384
385 /**
386 * Trigger Action.
387 *
388 * Note: action dynamically fire on basis of field id.
389 *
390 * @since 1.8
391 */
392 do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
393 }
394
395 break;
396
397 // Section Ends.
398 case 'sectionend':
399 if ( ! empty( $value['id'] ) ) {
400
401 /**
402 * Trigger Action.
403 *
404 * Note: action dynamically fire on basis of field id.
405 *
406 * @since 1.8
407 */
408 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
409 }
410
411 if ( $value['table_html'] ) {
412 echo '</table>';
413 }
414
415 if ( ! empty( $value['id'] ) ) {
416
417 /**
418 * Trigger Action.
419 *
420 * Note: action dynamically fire on basis of field id.
421 *
422 * @since 1.8
423 */
424 do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
425 }
426
427 break;
428
429 // Standard text inputs and subtypes like 'number'.
430 case 'colorpicker':
431 case 'hidden' :
432 $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
433 case 'text':
434 case 'email':
435 case 'number':
436 case 'password' :
437 $type = $value['type'];
438 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
439
440 // Set default value for repeater field if not any value set yet.
441 if ( $value['repeat'] && is_string( $option_value ) ) {
442 $option_value = array( $value['default'] );
443 }
444 ?>
445 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
446 <th scope="row" class="titledesc">
447 <label
448 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
449 </th>
450 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
451 <?php if ( $value['repeat'] ) : ?>
452 <?php foreach ( $option_value as $index => $field_value ) : ?>
453 <p>
454 <input
455 name="<?php echo esc_attr( $value['id'] ); ?>[]"
456 type="<?php echo esc_attr( $type ); ?>"
457 style="<?php echo esc_attr( $value['css'] ); ?>"
458 value="<?php echo esc_attr( $field_value ); ?>"
459 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?> <?php echo esc_attr( $value['id'] ); ?>"
460 <?php echo implode( ' ', $custom_attributes ); ?>
461 />
462 <span class="give-remove-setting-field"
463 title="<?php esc_html_e( 'Remove setting field', 'give' ); ?>">-</span>
464 </p>
465 <?php endforeach; ?>
466 <a href="#" data-id="<?php echo $value['id']; ?>"
467 class="give-repeat-setting-field button-secondary"><?php echo $value['repeat_btn_title']; ?></a>
468 <?php else : ?>
469 <input
470 name="<?php echo esc_attr( $value['id'] ); ?>"
471 id="<?php echo esc_attr( $value['id'] ); ?>"
472 type="<?php echo esc_attr( $type ); ?>"
473 style="<?php echo esc_attr( $value['css'] ); ?>"
474 value="<?php echo esc_attr( $option_value ); ?>"
475 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
476 <?php echo implode( ' ', $custom_attributes ); ?>
477 />
478 <?php endif; ?>
479 <?php echo $description; ?>
480 </td>
481 </tr><?php
482 break;
483
484 // Textarea.
485 case 'textarea':
486
487 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
488
489 ?>
490 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
491 <th scope="row" class="titledesc">
492 <label
493 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
494 </th>
495 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
496 <textarea
497 name="<?php echo esc_attr( $value['id'] ); ?>"
498 id="<?php echo esc_attr( $value['id'] ); ?>"
499 style="<?php echo esc_attr( $value['css'] ); ?>"
500 class="<?php echo esc_attr( $value['class'] ); ?>"
501 rows="10"
502 cols="60"
503 <?php echo implode( ' ', $custom_attributes ); ?>
504 ><?php echo esc_textarea( $option_value ); ?></textarea>
505 <?php echo $description; ?>
506 </td>
507 </tr><?php
508 break;
509
510 // Select boxes.
511 case 'select' :
512 case 'multiselect' :
513 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
514
515 /**
516 * insert page in option if missing.
517 *
518 * check success_page setting in general settings.
519 */
520 if(
521 isset( $value['attributes' ] ) &&
522 false !== strpos( $value['class'], 'give-select-chosen' ) &&
523 in_array( 'data-search-type', array_keys( $value['attributes' ] ) ) &&
524 'pages' == $value['attributes' ]['data-search-type'] &&
525 ! in_array( $option_value, array_keys( $value['options'] ) )
526 ) {
527 $value['options'][$option_value] = get_the_title( $option_value );
528 }
529 ?>
530 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
531 <th scope="row" class="titledesc">
532 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
533 </th>
534 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
535 <select
536 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
537 id="<?php echo esc_attr( $value['id'] ); ?>"
538 style="<?php echo esc_attr( $value['css'] ); ?>"
539 class="<?php echo esc_attr( $value['class'] ); ?>"
540 <?php echo implode( ' ', $custom_attributes ); ?>
541 <?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
542 >
543
544 <?php
545 if ( ! empty( $value['options'] ) ) {
546 foreach ( $value['options'] as $key => $val ) {
547 ?>
548 <option value="<?php echo esc_attr( $key ); ?>" <?php
549
550 if ( is_array( $option_value ) ) {
551 selected( in_array( $key, $option_value ), true );
552 } else {
553 selected( $option_value, $key );
554 }
555
556 ?>><?php echo $val ?></option>
557 <?php
558 }
559 }
560 ?>
561
562 </select> <?php echo $description; ?>
563 </td>
564 </tr><?php
565 break;
566
567 // Radio inputs.
568 case 'radio_inline' :
569 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
570 case 'radio' :
571 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
572 ?>
573 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
574 <th scope="row" class="titledesc">
575 <label
576 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
577 </th>
578 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
579 <fieldset>
580 <ul>
581 <?php
582 foreach ( $value['options'] as $key => $val ) {
583 ?>
584 <li>
585 <label><input
586 name="<?php echo esc_attr( $value['id'] ); ?>"
587 value="<?php echo $key; ?>"
588 type="radio"
589 style="<?php echo esc_attr( $value['css'] ); ?>"
590 <?php echo implode( ' ', $custom_attributes ); ?>
591 <?php checked( $key, $option_value ); ?>
592 /> <?php echo $val ?></label>
593 </li>
594 <?php
595 }
596 ?>
597 <?php echo $description; ?>
598 </fieldset>
599 </td>
600 </tr><?php
601 break;
602
603 // Checkbox input.
604 case 'checkbox' :
605 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
606 ?>
607 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
608 <th scope="row" class="titledesc">
609 <label
610 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
611 </th>
612 <td class="give-forminp">
613 <input
614 name="<?php echo esc_attr( $value['id'] ); ?>"
615 id="<?php echo esc_attr( $value['id'] ); ?>"
616 type="checkbox"
617 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
618 value="1"
619 <?php checked( $option_value, 'on' ); ?>
620 <?php echo implode( ' ', $custom_attributes ); ?>
621 />
622 <?php echo $description; ?>
623 </td>
624 </tr>
625 <?php
626 break;
627
628 // Multi Checkbox input.
629 case 'multicheck' :
630 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
631 $option_value = is_array( $option_value ) ? $option_value : array();
632 ?>
633 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
634 <th scope="row" class="titledesc">
635 <label
636 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
637 </th>
638 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
639 <fieldset>
640 <ul>
641 <?php
642 foreach ( $value['options'] as $key => $val ) {
643 ?>
644 <li>
645 <label>
646 <input
647 name="<?php echo esc_attr( $value['id'] ); ?>[]"
648 value="<?php echo $key; ?>"
649 type="checkbox"
650 style="<?php echo esc_attr( $value['css'] ); ?>"
651 <?php echo implode( ' ', $custom_attributes ); ?>
652 <?php if ( in_array( $key, $option_value ) ) {
653 echo 'checked="checked"';
654 } ?>
655 /> <?php echo $val ?>
656 </label>
657 </li>
658 <?php
659 }
660 ?>
661 <?php echo $description; ?>
662 </fieldset>
663 </td>
664 </tr>
665 <?php
666 break;
667
668 // File input field.
669 case 'file' :
670 case 'media' :
671 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
672 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
673 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
674
675 $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
676 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
677 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
678 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
679 ?>
680 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
681 <th scope="row" class="titledesc">
682 <label
683 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
684 </th>
685 <td class="give-forminp">
686 <div class="give-field-wrap">
687 <label for="<?php echo $value['id'] ?>">
688 <input
689 name="<?php echo esc_attr( $value['id'] ); ?>"
690 id="<?php echo esc_attr( $value['id'] ); ?>"
691 type="text"
692 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
693 value="<?php echo $option_value; ?>"
694 style="<?php echo esc_attr( $value['css'] ); ?>"
695 <?php echo implode( ' ', $custom_attributes ); ?>
696 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
697 data-fvalue="<?php echo $fvalue; ?>"
698 data-field-type="<?php echo $value['type']; ?>"
699 value="<?php echo $button_label; ?>">
700 <?php echo $description ?>
701 <div
702 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
703 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
704 <img src="<?php echo $preview_image_src; ?>" alt="">
705 </div>
706 </label>
707 </div>
708 </td>
709 </tr>
710 <?php
711 break;
712
713 // WordPress Editor.
714 case 'wysiwyg' :
715 // Get option value.
716 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
717
718 // Get editor settings.
719 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
720 ?>
721 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
722 <th scope="row" class="titledesc">
723 <label
724 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
725 </th>
726 <td class="give-forminp">
727 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
728 <?php echo $description; ?>
729 </td>
730 </tr><?php
731 break;
732
733 // Custom: Default gateways setting field.
734 case 'default_gateway' :
735 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
736 ?>
737 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
738 <th scope="row" class="titledesc">
739 <label
740 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
741 </th>
742 <td class="give-forminp">
743 <?php give_default_gateway_callback( $value, $option_value ); ?>
744 <?php echo $description; ?>
745 </td>
746 </tr><?php
747 break;
748
749 // Custom: Email preview buttons field.
750 case 'email_preview_buttons' :
751 ?>
752 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
753 <th scope="row" class="titledesc">
754 <label
755 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
756 </th>
757 <td class="give-forminp">
758 <?php give_email_preview_buttons_callback( $value ); ?>
759 <?php echo $description; ?>
760 </td>
761 </tr><?php
762 break;
763
764 // Custom: API field.
765 case 'api' :
766 give_api_callback();
767 echo $description;
768 break;
769
770 // Custom: Gateway API key.
771 case 'api_key' :
772 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
773 $type = ! empty( $option_value ) ? 'password' : 'text';
774 ?>
775 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
776 <th scope="row" class="titledesc">
777 <label
778 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
779 </th>
780 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
781 <input
782 name="<?php echo esc_attr( $value['id'] ); ?>"
783 id="<?php echo esc_attr( $value['id'] ); ?>"
784 type="<?php echo esc_attr( $type ); ?>"
785 style="<?php echo esc_attr( $value['css'] ); ?>"
786 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
787 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
788 <?php echo implode( ' ', $custom_attributes ); ?>
789 /> <?php echo $description; ?>
790 </td>
791 </tr><?php
792 break;
793
794 // Custom: Log field.
795 case 'logs' :
796
797 // Get current section.
798 $current_section = $_GET['section'] = give_get_current_setting_section();
799
800 /**
801 * Fires for each tab of logs view.
802 *
803 * @since 1.0
804 */
805 do_action( "give_logs_view_{$current_section}" );
806
807 echo $description;
808 break;
809
810 // Custom: Data field.
811 case 'data' :
812
813 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
814
815 echo $description;
816 break;
817
818 // Custom: Give Docs Link field type.
819 case 'give_docs_link' :
820 ?>
821 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
822 <td class="give-docs-link" colspan="2">
823 <?php
824 echo '<p class="give-docs-link"><a href="' . esc_url( $value['url'] )
825 . '" target="_blank">'
826 . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $value['title'] )
827 . '<span class="dashicons dashicons-editor-help"></span></a></p>';
828 ?>
829 </td>
830 </tr><?php
831 break;
832
833 // Default: run an action
834 // You can add or handle your custom field action.
835 default:
836 // Get option value.
837 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
838 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
839 break;
840 }
841 }
842 }
843
844 /**
845 * Helper function to get the formatted description for a given form field.
846 * Plugins can call this when implementing their own custom settings types.
847 *
848 * @since 1.8
849 *
850 * @param array $value The form field value array
851 *
852 * @return string The HTML description of the field.
853 */
854 public static function get_field_description( $value ) {
855 $description = '';
856
857 // Support for both 'description' and 'desc' args.
858 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
859 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
860
861 if ( ! empty( $value ) ) {
862 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
863 }
864
865 return $description;
866 }
867
868
869 /**
870 * Helper function to get the formated title.
871 * Plugins can call this when implementing their own custom settings types.
872 *
873 * @since 1.8
874 *
875 * @param array $value The form field value array
876 *
877 * @return array The description and tip as a 2 element array
878 */
879 public static function get_field_title( $value ) {
880 $title = esc_html( $value['title'] );
881
882 // If html tag detected then allow them to print.
883 if ( strip_tags( $title ) ) {
884 $title = $value['title'];
885 }
886
887 return $title;
888 }
889
890 /**
891 * Save admin fields.
892 *
893 * Loops though the give options array and outputs each field.
894 *
895 * @since 1.8
896 *
897 * @param array $options Options array to output
898 * @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.
899 *
900 * @return bool
901 */
902 public static function save_fields( $options, $option_name = '' ) {
903 if ( empty( $_POST ) ) {
904 return false;
905 }
906
907 // Options to update will be stored here and saved later.
908 $update_options = array();
909
910 // Loop options and get values to save.
911 foreach ( $options as $option ) {
912 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
913 continue;
914 }
915
916 // Get posted value.
917 if ( strstr( $option['id'], '[' ) ) {
918 parse_str( $option['id'], $option_name_array );
919 $field_option_name = current( array_keys( $option_name_array ) );
920 $setting_name = key( $option_name_array[ $field_option_name ] );
921 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
922 } else {
923 $field_option_name = $option['id'];
924 $setting_name = '';
925 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
926 }
927
928 // Format the value based on option type.
929 switch ( $option['type'] ) {
930 case 'checkbox' :
931 $value = is_null( $raw_value ) ? '' : 'on';
932 break;
933 case 'wysiwyg' :
934 case 'textarea' :
935 $value = wp_kses_post( trim( $raw_value ) );
936 break;
937 case 'multiselect' :
938 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
939 break;
940 default :
941 $value = give_clean( $raw_value );
942 break;
943 }
944
945 /**
946 * Sanitize the value of an option.
947 *
948 * @since 1.8
949 */
950 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
951
952 /**
953 * Sanitize the value of an option by option name.
954 *
955 * @since 1.8
956 */
957 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
958
959 if ( is_null( $value ) ) {
960 continue;
961 }
962
963 // Check if option is an array and handle that differently to single values.
964 if ( $field_option_name && $setting_name ) {
965 if ( ! isset( $update_options[ $field_option_name ] ) ) {
966 $update_options[ $field_option_name ] = get_option( $field_option_name, array() );
967 }
968 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
969 $update_options[ $field_option_name ] = array();
970 }
971 $update_options[ $field_option_name ][ $setting_name ] = $value;
972 } else {
973 $update_options[ $field_option_name ] = $value;
974 }
975 }
976
977 // Save all options in our array or there own option name i.e. option id.
978 if ( empty( $option_name ) ) {
979 foreach ( $update_options as $name => $value ) {
980 update_option( $name, $value );
981
982 /**
983 * Trigger action.
984 *
985 * Note: This is dynamically fire on basis of option name.
986 *
987 * @since 1.8
988 */
989 do_action( "give_save_option_{$name}", $value, $name );
990 }
991 } else {
992 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
993 $update_options = array_merge( $old_options, $update_options );
994
995 update_option( $option_name, $update_options );
996
997 /**
998 * Trigger action.
999 *
1000 * Note: This is dynamically fire on basis of setting name.
1001 *
1002 * @since 1.8
1003 */
1004 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1005 }
1006
1007 return true;
1008 }
1009
1010
1011 /**
1012 * Check if admin saving setting or not.
1013 *
1014 * @since 1.8.17
1015 *
1016 * @return bool
1017 */
1018 public static function is_saving_settings() {
1019 return self::verify_nonce();
1020 }
1021
1022 /**
1023 * Verify setting page
1024 *
1025 * @since 2.0
1026 * @access public
1027 *
1028 * @param string $tab
1029 * @param string $section
1030 *
1031 * @return bool
1032 */
1033 public static function is_setting_page( $tab = '', $section = '' ) {
1034 $is_setting_page = false;
1035
1036 // Check fo setting tab.
1037 if ( ! empty( $tab ) ) {
1038 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1039 }
1040
1041 // Check fo setting section.
1042 if ( ! empty( $section ) ) {
1043 $is_setting_page = ( $section === give_get_current_setting_section() );
1044 }
1045
1046 return $is_setting_page;
1047 }
1048 }
1049
1050 endif;
1051