PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.2
GiveWP – Donation Plugin and Fundraising Platform v2.2.2
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 7 years ago emails 7 years ago forms 7 years ago payments 7 years ago reports 7 years ago settings 7 years ago shortcodes 7 years ago tools 7 years ago upgrades 7 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 7 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 7 years ago class-admin-settings.php 7 years ago class-api-keys-table.php 8 years ago class-blank-slate.php 8 years ago class-give-settings.php 7 years ago class-i18n-module.php 8 years ago dashboard-widgets.php 8 years ago give-metabox-functions.php 7 years ago plugins.php 7 years ago welcome.php 8 years ago
class-admin-settings.php
1123 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 * Verify admin setting nonce
82 *
83 * @since 1.8.14
84 * @access public
85 *
86 * @return bool
87 */
88 public static function verify_nonce() {
89 if ( empty( $_REQUEST['_give-save-settings'] ) || ! wp_verify_nonce( $_REQUEST['_give-save-settings'], 'give-save-settings' ) ) {
90 return false;
91 }
92
93 return true;
94 }
95
96 /**
97 * Save the settings.
98 *
99 * @since 1.8
100 * @return void
101 */
102 public static function save() {
103 $current_tab = give_get_current_setting_tab();
104
105 if ( ! self::verify_nonce() ) {
106 echo '<div class="notice error"><p>' . esc_attr__( 'Action failed. Please refresh the page and retry.', 'give' ) . '</p></div>';
107 die();
108 }
109
110 /**
111 * Trigger Action.
112 *
113 * Note: action dynamically fire on basis of setting page slug and current tab.
114 * For example: if you register a setting page with give-settings menu slug and general current tab name
115 * then action will be give-settings_save_general
116 *
117 * @since 1.8
118 */
119 do_action( self::$setting_filter_prefix . '_save_' . $current_tab );
120
121 self::add_message( 'give-setting-updated', __( 'Your settings have been saved.', 'give' ) );
122
123 /**
124 * Trigger Action.
125 *
126 * Note: action dynamically fire on basis of setting page slug.
127 * For example: if you register a setting page with give-settings menu slug
128 * then action will be give-settings_saved
129 *
130 * @since 1.8
131 */
132 do_action( self::$setting_filter_prefix . '_saved' );
133 }
134
135 /**
136 * Add a message.
137 *
138 * @since 1.8
139 *
140 * @param string $code Message code (Note: This should be unique).
141 * @param string $message Message text.
142 *
143 * @return void
144 */
145 public static function add_message( $code, $message ) {
146 self::$messages[ $code ] = $message;
147 }
148
149 /**
150 * Add an error.
151 *
152 * @since 1.8
153 *
154 * @param string $code Message code (Note: This should be unique).
155 * @param string $message Message text.
156 *
157 * @return void
158 */
159 public static function add_error( $code, $message ) {
160 self::$errors[ $code ] = $message;
161 }
162
163 /**
164 * Output messages + errors.
165 *
166 * @since 1.8
167 * @return void
168 */
169 public static function show_messages() {
170 $notice_html = '';
171 $classes = 'give-notice settings-error notice is-dismissible';
172
173 self::$errors = apply_filters( self::$setting_filter_prefix . '_error_notices', self::$errors );
174 self::$messages = apply_filters( self::$setting_filter_prefix . '_update_notices', self::$messages );
175
176 if ( 0 < count( self::$errors ) ) {
177 foreach ( self::$errors as $code => $message ) {
178 $notice_html .= sprintf(
179 '<div id="setting-error-%1$s" class="%2$s error" style="display: none"><p><strong>%3$s</strong></p></div>',
180 $code,
181 $classes,
182 $message
183 );
184 }
185 }
186
187 if ( 0 < count( self::$messages ) ) {
188 foreach ( self::$messages as $code => $message ) {
189 $notice_html .= sprintf(
190 '<div id="setting-error-%1$s" class="%2$s updated" style="display: none"><p><strong>%3$s</strong></p></div>',
191 $code,
192 $classes,
193 $message
194 );
195 }
196 }
197
198 echo $notice_html;
199 }
200
201 /**
202 * Settings page.
203 *
204 * Handles the display of the main give settings page in admin.
205 *
206 * @since 1.8
207 * @return bool
208 */
209 public static function output() {
210 // Get current setting page.
211 self::$setting_filter_prefix = give_get_current_setting_page();
212
213 // Bailout: Exit if setting page is not defined.
214 if ( empty( self::$setting_filter_prefix ) ) {
215 return false;
216 }
217
218 /**
219 * Trigger Action.
220 *
221 * Note: action dynamically fire on basis of setting page slug
222 * For example: if you register a setting page with give-settings menu slug
223 * then action will be give-settings_start
224 *
225 * @since 1.8
226 */
227 do_action( self::$setting_filter_prefix . '_start' );
228
229 $current_tab = give_get_current_setting_tab();
230
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 ( isset( $_POST['_give-save-settings'] ) ) {
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 Option Name.
274 * @param string $field_id Field ID.
275 * @param mixed $default 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 $default_attributes = array(
489 'rows' => 10,
490 'cols' => 60
491 );
492 $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : array();
493 ?>
494 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
495 <th scope="row" class="titledesc">
496 <label
497 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
498 </th>
499 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
500 <textarea
501 name="<?php echo esc_attr( $value['id'] ); ?>"
502 id="<?php echo esc_attr( $value['id'] ); ?>"
503 style="<?php echo esc_attr( $value['css'] ); ?>"
504 class="<?php echo esc_attr( $value['class'] ); ?>"
505 <?php echo give_get_attribute_str( $textarea_attributes, $default_attributes ); ?>
506 ><?php echo esc_textarea( $option_value ); ?></textarea>
507 <?php echo $description; ?>
508 </td>
509 </tr>
510 <?php
511 break;
512
513 // Select boxes.
514 case 'select' :
515 case 'multiselect' :
516 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
517
518 /**
519 * Insert page in option if missing.
520 *
521 * Check success_page setting in general settings.
522 */
523 if (
524 isset( $value['attributes'] ) &&
525 false !== strpos( $value['class'], 'give-select-chosen' ) &&
526 in_array( 'data-search-type', array_keys( $value['attributes' ] ) ) &&
527 'pages' === $value['attributes' ]['data-search-type'] &&
528 ! in_array( $option_value, array_keys( $value['options'] ) )
529 ) {
530 $value['options'][ $option_value ] = get_the_title( $option_value );
531 }
532 ?>
533 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
534 <th scope="row" class="titledesc">
535 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
536 </th>
537 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
538 <select
539 name="<?php echo esc_attr( $value['id'] ); ?><?php if ( 'multiselect' === $value['type'] ) echo '[]'; ?>"
540 id="<?php echo esc_attr( $value['id'] ); ?>"
541 style="<?php echo esc_attr( $value['css'] ); ?>"
542 class="<?php echo esc_attr( $value['class'] ); ?>"
543 <?php echo implode( ' ', $custom_attributes ); ?>
544 <?php echo ( 'multiselect' === $value['type'] ) ? 'multiple="multiple"' : ''; ?>
545 >
546
547 <?php
548 if ( ! empty( $value['options'] ) ) {
549 foreach ( $value['options'] as $key => $val ) {
550 ?>
551 <option value="<?php echo esc_attr( $key ); ?>" <?php
552
553 if ( is_array( $option_value ) ) {
554 selected( in_array( $key, $option_value ), true );
555 } else {
556 selected( $option_value, $key );
557 }
558
559 ?>><?php echo $val ?></option>
560 <?php
561 }
562 }
563 ?>
564
565 </select> <?php echo $description; ?>
566 </td>
567 </tr><?php
568 break;
569
570 // Radio inputs.
571 case 'radio_inline' :
572 $value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
573 case 'radio' :
574 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
575 ?>
576 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
577 <th scope="row" class="titledesc">
578 <label
579 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
580 </th>
581 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
582 <fieldset>
583 <ul>
584 <?php
585 foreach ( $value['options'] as $key => $val ) {
586 ?>
587 <li>
588 <label><input
589 name="<?php echo esc_attr( $value['id'] ); ?>"
590 value="<?php echo $key; ?>"
591 type="radio"
592 style="<?php echo esc_attr( $value['css'] ); ?>"
593 <?php echo implode( ' ', $custom_attributes ); ?>
594 <?php checked( $key, $option_value ); ?>
595 /> <?php echo $val ?></label>
596 </li>
597 <?php
598 }
599 ?>
600 <?php echo $description; ?>
601 </fieldset>
602 </td>
603 </tr><?php
604 break;
605
606 // Checkbox input.
607 case 'checkbox' :
608 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
609 ?>
610 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
611 <th scope="row" class="titledesc">
612 <label
613 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
614 </th>
615 <td class="give-forminp">
616 <input
617 name="<?php echo esc_attr( $value['id'] ); ?>"
618 id="<?php echo esc_attr( $value['id'] ); ?>"
619 type="checkbox"
620 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
621 value="1"
622 <?php checked( $option_value, 'on' ); ?>
623 <?php echo implode( ' ', $custom_attributes ); ?>
624 />
625 <?php echo $description; ?>
626 </td>
627 </tr>
628 <?php
629 break;
630
631 // Multi Checkbox input.
632 case 'multicheck' :
633 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
634 $option_value = is_array( $option_value ) ? $option_value : array();
635 ?>
636 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
637 <th scope="row" class="titledesc">
638 <label
639 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
640 </th>
641 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
642 <fieldset>
643 <ul>
644 <?php
645 foreach ( $value['options'] as $key => $val ) {
646 ?>
647 <li>
648 <label>
649 <input
650 name="<?php echo esc_attr( $value['id'] ); ?>[]"
651 value="<?php echo $key; ?>"
652 type="checkbox"
653 style="<?php echo esc_attr( $value['css'] ); ?>"
654 <?php echo implode( ' ', $custom_attributes ); ?>
655 <?php if ( in_array( $key, $option_value ) ) {
656 echo 'checked="checked"';
657 } ?>
658 /> <?php echo $val ?>
659 </label>
660 </li>
661 <?php
662 }
663 ?>
664 <?php echo $description; ?>
665 </fieldset>
666 </td>
667 </tr>
668 <?php
669 break;
670
671 // File input field.
672 case 'file' :
673 case 'media' :
674 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
675 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $value['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
676 $fvalue = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
677
678 $allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
679 $preview_image_src = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '';
680 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
681 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
682 ?>
683 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
684 <th scope="row" class="titledesc">
685 <label
686 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
687 </th>
688 <td class="give-forminp">
689 <div class="give-field-wrap">
690 <label for="<?php echo $value['id'] ?>">
691 <input
692 name="<?php echo esc_attr( $value['id'] ); ?>"
693 id="<?php echo esc_attr( $value['id'] ); ?>"
694 type="text"
695 class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
696 value="<?php echo $option_value; ?>"
697 style="<?php echo esc_attr( $value['css'] ); ?>"
698 <?php echo implode( ' ', $custom_attributes ); ?>
699 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button"
700 data-fvalue="<?php echo $fvalue; ?>"
701 data-field-type="<?php echo $value['type']; ?>"
702 value="<?php echo $button_label; ?>">
703 <?php echo $description ?>
704 <div
705 class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
706 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
707 <img src="<?php echo $preview_image_src; ?>" alt="">
708 </div>
709 </label>
710 </div>
711 </td>
712 </tr>
713 <?php
714 break;
715
716 // WordPress Editor.
717 case 'wysiwyg' :
718 // Get option value.
719 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
720
721 // Get editor settings.
722 $editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
723 ?>
724 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
725 <th scope="row" class="titledesc">
726 <label
727 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
728 </th>
729 <td class="give-forminp">
730 <?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
731 <?php echo $description; ?>
732 </td>
733 </tr><?php
734 break;
735
736 // Custom: Default gateways setting field.
737 case 'default_gateway' :
738 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
739 ?>
740 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
741 <th scope="row" class="titledesc">
742 <label
743 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_default_gateway_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
758 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
759 </th>
760 <td class="give-forminp">
761 <?php give_email_preview_buttons_callback( $value ); ?>
762 <?php echo $description; ?>
763 </td>
764 </tr><?php
765 break;
766
767 // Custom: API field.
768 case 'api' :
769 give_api_callback();
770 echo $description;
771 break;
772
773 // Custom: Gateway API key.
774 case 'api_key' :
775 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
776 $type = ! empty( $option_value ) ? 'password' : 'text';
777 ?>
778 <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
779 <th scope="row" class="titledesc">
780 <label
781 for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
782 </th>
783 <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
784 <input
785 name="<?php echo esc_attr( $value['id'] ); ?>"
786 id="<?php echo esc_attr( $value['id'] ); ?>"
787 type="<?php echo esc_attr( $type ); ?>"
788 style="<?php echo esc_attr( $value['css'] ); ?>"
789 value="<?php echo esc_attr( trim( $option_value ) ); ?>"
790 class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
791 <?php echo implode( ' ', $custom_attributes ); ?>
792 /> <?php echo $description; ?>
793 </td>
794 </tr><?php
795 break;
796
797 // Note: only for internal use.
798 case 'chosen' :
799
800 // Get option value.
801 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
802 $option_value = is_array( $option_value ) ? array_fill_keys( $option_value, 'selected' ) : $option_value;
803 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
804 $type = '';
805 $allow_new_values = '';
806 $name = give_get_field_name( $value );
807
808 // Set attributes based on multiselect datatype.
809 if ( 'multiselect' === $value['data_type'] ) {
810 $type = 'multiple';
811 $allow_new_values = 'data-allows-new-values="true"';
812 $name = $name . '[]';
813 $option_value = empty( $option_value ) ? array() : $option_value;
814 }
815
816 $title_prefixes_value = ( is_array( $option_value ) && count( $option_value ) > 0 ) ?
817 array_merge( $value['options'], $option_value ) :
818 $value['options'];
819
820 ?>
821 <tr valign="top" <?php echo $wrapper_class; ?>>
822 <th scope="row" class="titledesc">
823 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_attr( self::get_field_title( $value ) ); ?></label>
824 </th>
825 <td class="give-forminp give-forminp-<?php echo esc_attr( $value['type'] ); ?>">
826 <select
827 class="give-select-chosen give-chosen-settings"
828 style="<?php echo esc_attr( $value['style'] ); ?>"
829 name="<?php echo esc_attr( $name ); ?>"
830 id="<?php echo esc_attr( $value['id'] ); ?>"
831 <?php
832 echo "{$type} {$allow_new_values}";
833 echo implode( ' ', $custom_attributes );
834 ?>
835 >
836 <?php
837 if ( is_array( $title_prefixes_value ) && count( $title_prefixes_value ) > 0 ) {
838 foreach ( $title_prefixes_value as $key => $item_value ) {
839 echo sprintf(
840 '<option %1$s value="%2$s">%2$s</option>',
841 ( 'selected' === $item_value ) ? 'selected="selected"' : '',
842 esc_attr( $key )
843 );
844 }
845 }
846 ?>
847 </select>
848 <?php echo wp_kses_post( $description ); ?>
849 </td>
850 </tr>
851 <?php
852 break;
853
854 // Custom: Log field.
855 case 'logs' :
856
857 // Get current section.
858 $current_section = $_GET['section'] = give_get_current_setting_section();
859
860 /**
861 * Fires for each tab of logs view.
862 *
863 * @since 1.0
864 */
865 do_action( "give_logs_view_{$current_section}" );
866
867 echo $description;
868 break;
869
870 // Custom: Data field.
871 case 'data' :
872
873 include GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
874
875 echo $description;
876 break;
877
878 // Custom: Give Docs Link field type.
879 case 'give_docs_link' :
880 $wrapper_class = ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '';
881 ?>
882 <tr valign="top" <?php echo esc_html( $wrapper_class ); ?>>
883 <td class="give-docs-link" colspan="2">
884 <p class="give-docs-link">
885 <a href="<?php echo esc_url( $value['url'] ); ?>" target="_blank">
886 <?php
887 echo sprintf(
888 /* translators: %s Title */
889 esc_html__( 'Need Help? See docs on "%s"', 'give' ),
890 esc_html( $value['title'] )
891 );
892 ?>
893 <span class="dashicons dashicons-editor-help"></span>
894 </a>
895 </p>
896 </td>
897 </tr><?php
898 break;
899
900 // Default: run an action
901 // You can add or handle your custom field action.
902 default:
903 // Get option value.
904 $option_value = self::get_option( $option_name, $value['id'], $value['default'] );
905 do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
906 break;
907 }
908 }
909 }
910
911 /**
912 * Helper function to get the formatted description for a given form field.
913 * Plugins can call this when implementing their own custom settings types.
914 *
915 * @since 1.8
916 *
917 * @param array $value The form field value array
918 *
919 * @return string The HTML description of the field.
920 */
921 public static function get_field_description( $value ) {
922 $description = '';
923
924 // Support for both 'description' and 'desc' args.
925 $description_key = isset( $value['description'] ) ? 'description' : 'desc';
926 $value = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
927
928 if ( ! empty( $value ) ) {
929 $description = '<div class="give-field-description">' . wp_kses_post( $value ) . '</div>';
930 }
931
932 return $description;
933 }
934
935
936 /**
937 * Helper function to get the formated title.
938 * Plugins can call this when implementing their own custom settings types.
939 *
940 * @since 1.8
941 *
942 * @param array $value The form field value array
943 *
944 * @return array The description and tip as a 2 element array
945 */
946 public static function get_field_title( $value ) {
947 $title = esc_html( $value['title'] );
948
949 // If html tag detected then allow them to print.
950 if ( strip_tags( $title ) ) {
951 $title = $value['title'];
952 }
953
954 return $title;
955 }
956
957 /**
958 * Save admin fields.
959 *
960 * Loops though the give options array and outputs each field.
961 *
962 * @since 1.8
963 *
964 * @param array $options Options array to output
965 * @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.
966 *
967 * @return bool
968 */
969 public static function save_fields( $options, $option_name = '' ) {
970 if ( empty( $_POST ) ) {
971 return false;
972 }
973
974 // Options to update will be stored here and saved later.
975 $update_options = array();
976
977 // Loop options and get values to save.
978 foreach ( $options as $option ) {
979 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
980 continue;
981 }
982
983 // Get posted value.
984 if ( strstr( $option['id'], '[' ) ) {
985 parse_str( $option['id'], $option_name_array );
986 $field_option_name = current( array_keys( $option_name_array ) );
987 $setting_name = key( $option_name_array[ $field_option_name ] );
988 $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
989 } else {
990 $field_option_name = $option['id'];
991 $setting_name = '';
992 $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
993 }
994
995 // Format the value based on option type.
996 switch ( $option['type'] ) {
997 case 'checkbox' :
998 $value = is_null( $raw_value ) ? '' : 'on';
999 break;
1000 case 'wysiwyg' :
1001 case 'textarea' :
1002 $value = wp_kses_post( trim( $raw_value ) );
1003 break;
1004 case 'multiselect' :
1005 case 'chosen' :
1006 $value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
1007 break;
1008 default :
1009 $value = give_clean( $raw_value );
1010 break;
1011 }
1012
1013 /**
1014 * Sanitize the value of an option.
1015 *
1016 * @since 1.8
1017 */
1018 $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
1019
1020 /**
1021 * Sanitize the value of an option by option name.
1022 *
1023 * @since 1.8
1024 */
1025 $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
1026
1027 if ( is_null( $value ) ) {
1028 continue;
1029 }
1030
1031 // Check if option is an array and handle that differently to single values.
1032 if ( $field_option_name && $setting_name ) {
1033 if ( ! isset( $update_options[ $field_option_name ] ) ) {
1034 $update_options[ $field_option_name ] = get_option( $field_option_name, array() );
1035 }
1036 if ( ! is_array( $update_options[ $field_option_name ] ) ) {
1037 $update_options[ $field_option_name ] = array();
1038 }
1039 $update_options[ $field_option_name ][ $setting_name ] = $value;
1040 } else {
1041 $update_options[ $field_option_name ] = $value;
1042 }
1043 }
1044
1045 // Save all options in our array or there own option name i.e. option id.
1046 if ( empty( $option_name ) ) {
1047 foreach ( $update_options as $name => $value ) {
1048 update_option( $name, $value, false );
1049
1050 /**
1051 * Trigger action.
1052 *
1053 * Note: This is dynamically fire on basis of option name.
1054 *
1055 * @since 1.8
1056 */
1057 do_action( "give_save_option_{$name}", $value, $name );
1058 }
1059 } else {
1060 $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
1061 $update_options = array_merge( $old_options, $update_options );
1062
1063 update_option( $option_name, $update_options, false );
1064
1065 /**
1066 * Trigger action.
1067 *
1068 * Note: This is dynamically fire on basis of setting name.
1069 *
1070 * @since 1.8
1071 */
1072 do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options );
1073 }
1074
1075 return true;
1076 }
1077
1078
1079 /**
1080 * Check if admin saving setting or not.
1081 *
1082 * @since 1.8.17
1083 *
1084 * @return bool
1085 */
1086 public static function is_saving_settings() {
1087 return self::verify_nonce();
1088 }
1089
1090 /**
1091 * Verify setting page
1092 *
1093 * @since 2.0
1094 * @access public
1095 *
1096 * @param string $tab
1097 * @param string $section
1098 *
1099 * @return bool
1100 */
1101 public static function is_setting_page( $tab = '', $section = '' ) {
1102 $is_setting_page = false;
1103
1104 if( ! is_admin() ) {
1105 return $is_setting_page;
1106 }
1107
1108 // Check fo setting tab.
1109 if ( ! empty( $tab ) ) {
1110 $is_setting_page = ( $tab === give_get_current_setting_tab() );
1111 }
1112
1113 // Check fo setting section.
1114 if ( ! empty( $section ) ) {
1115 $is_setting_page = ( $section === give_get_current_setting_section() );
1116 }
1117
1118 return $is_setting_page;
1119 }
1120 }
1121
1122 endif;
1123