Test Failed
Pull Request — master (#2199)
by Ravinder
04:54
created

Give_Admin_Settings::verify_nonce()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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' ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
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()  ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
106
				echo '<div class="notice error"><p>' . __( 'Action failed. Please refresh the page and retry.', 'give' ) . '</p></div>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
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'] )
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
112
			     && give_is_setting_enabled( $_POST['akismet_spam_protection'] )
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
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 View Code Duplication
			if ( 0 < count( self::$errors ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
			if ( 0 < count( self::$messages ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$notice_html'
Loading history...
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 void|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
			self::get_settings_pages();
233
234
			// Save settings if data has been posted.
235
			if ( ! empty( $_POST ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
236
				self::save();
237
			}
238
239
			/**
240
			 * Filter the tabs for current setting page.
241
			 *
242
			 * Note: filter dynamically fire on basis of setting page slug.
243
			 * For example: if you register a setting page with give-settings menu slug and general current tab name
244
			 *              then action will be give-settings_tabs_array
245
			 *
246
			 * @since 1.8
247
			 */
248
			$tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', array() );
249
250
			include 'views/html-admin-settings.php';
251
252
			return true;
253
		}
254
255
		/**
256
		 * Get a setting from the settings API.
257
		 *
258
		 * @since  1.8
259
		 *
260
		 * @param  string $option_name
261
		 * @param  string $field_id
262
		 * @param  mixed  $default
263
		 *
264
		 * @return string|bool
265
		 */
266
		public static function get_option( $option_name = '', $field_id = '', $default = false ) {
267
			// Bailout.
268
			if ( empty( $option_name ) && empty( $field_id ) ) {
269
				return false;
270
			}
271
272
			if ( ! empty( $field_id ) && ! empty( $option_name ) ) {
273
				// Get field value if any.
274
				$option_value = get_option( $option_name );
275
276
				$option_value = ( is_array( $option_value ) && array_key_exists( $field_id, $option_value ) )
277
					? $option_value[ $field_id ]
278
					: $default;
279
			} else {
280
				// If option name is empty but not field name then this means, setting is direct store to option table under there field name.
281
				$option_name = ! $option_name ? $field_id : $option_name;
282
283
				// Get option value if any.
284
				$option_value = get_option( $option_name, $default );
285
			}
286
287
			return $option_value;
288
		}
289
290
		/**
291
		 * Output admin fields.
292
		 *
293
		 * Loops though the give options array and outputs each field.
294
		 *
295
		 * @since  1.8
296
		 *
297
		 * @param  array  $options     Opens array to output
298
		 * @param  string $option_name Opens array to output
299
		 *
300
		 * @return void
301
		 */
302
		public static function output_fields( $options, $option_name = '' ) {
303
			$current_tab = give_get_current_setting_tab();
304
305
			// Field Default values.
306
			$defaults = array(
307
				'id'         => '',
308
				'class'      => '',
309
				'css'        => '',
310
				'default'    => '',
311
				'desc'       => '',
312
				'table_html' => true,
313
			);
314
315
			foreach ( $options as $value ) {
316
				if ( ! isset( $value['type'] ) ) {
317
					continue;
318
				}
319
320
				// Set title.
321
				$defaults['title'] = isset( $value['name'] ) ? $value['name'] : '';
322
323
				// Set default setting.
324
				$value = wp_parse_args( $value, $defaults );
325
326
				// Colorpicker field.
327
				$value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] );
328
				$value['type']  = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] );
329
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
330
331
				// Custom attribute handling.
332
				$custom_attributes = array();
333
334 View Code Duplication
				if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
335
					foreach ( $value['attributes'] as $attribute => $attribute_value ) {
336
						$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
337
					}
338
				}
339
340
				// Description handling.
341
				$description          = self::get_field_description( $value );
342
343
				// Switch based on type.
344
				switch ( $value['type'] ) {
345
346
					// Section Titles
347
					case 'title':
348
						if ( ! empty( $value['title'] ) ) {
349
							echo '<div class="give-setting-tab-header give-setting-tab-header-' . $current_tab . '"><h2>' . self::get_field_title( $value ) . '</h2><hr></div>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$current_tab'
Loading history...
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
350
						}
351
352
						if ( ! empty( $value['desc'] ) ) {
353
							echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'wpautop'
Loading history...
354
						}
355
356
						if ( $value['table_html'] ) {
357
							echo '<table class="form-table give-setting-tab-body give-setting-tab-body-' . $current_tab . '">' . "\n\n";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$current_tab'
Loading history...
358
						}
359
360
						if ( ! empty( $value['id'] ) ) {
361
362
							/**
363
							 * Trigger Action.
364
							 *
365
							 * Note: action dynamically fire on basis of field id.
366
							 *
367
							 * @since 1.8
368
							 */
369
							do_action( 'give_settings_' . sanitize_title( $value['id'] ) );
370
						}
371
372
						break;
373
374
					// Section Ends.
375
					case 'sectionend':
376 View Code Duplication
						if ( ! empty( $value['id'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
378
							/**
379
							 * Trigger Action.
380
							 *
381
							 * Note: action dynamically fire on basis of field id.
382
							 *
383
							 * @since 1.8
384
							 */
385
							do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' );
386
						}
387
388
						if ( $value['table_html'] ) {
389
							echo '</table>';
390
						}
391
392 View Code Duplication
						if ( ! empty( $value['id'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
393
394
							/**
395
							 * Trigger Action.
396
							 *
397
							 * Note: action dynamically fire on basis of field id.
398
							 *
399
							 * @since 1.8
400
							 */
401
							do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' );
402
						}
403
404
						break;
405
406
					// Standard text inputs and subtypes like 'number'.
407
					case 'colorpicker':
408
					case 'hidden' :
409
						$value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden';
410
					case 'text':
411
					case 'email':
412
					case 'number':
413 View Code Duplication
					case 'password' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
414
						$type = $value['type'];
415
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
416
						?>
417
						<tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
418
							<th scope="row" class="titledesc">
419
								<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
420
							</th>
421
							<td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
422
								<input
423
										name="<?php echo esc_attr( $value['id'] ); ?>"
424
										id="<?php echo esc_attr( $value['id'] ); ?>"
425
										type="<?php echo esc_attr( $type ); ?>"
426
										style="<?php echo esc_attr( $value['css'] ); ?>"
427
										value="<?php echo esc_attr( $option_value ); ?>"
428
										class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
429
									<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
430
								/> <?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
431
							</td>
432
						</tr>
433
						<?php
434
						break;
435
436
					// Textarea.
437
					case 'textarea':
438
439
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
440
441
						?>
442
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
443
                        <th scope="row" class="titledesc">
444
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
445
                        </th>
446
                        <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
447
								<textarea
448
                                        name="<?php echo esc_attr( $value['id'] ); ?>"
449
                                        id="<?php echo esc_attr( $value['id'] ); ?>"
450
                                        style="<?php echo esc_attr( $value['css'] ); ?>"
451
                                        class="<?php echo esc_attr( $value['class'] ); ?>"
452
                                        rows="10"
453
                                        cols="60"
454
									<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
455
                                ><?php echo esc_textarea( $option_value ); ?></textarea>
456
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
457
                        </td>
458
                        </tr><?php
459
						break;
460
461
					// Select boxes.
462
					case 'select' :
463
					case 'multiselect' :
464
465
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
466
467
						?>
468
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
469
                        <th scope="row" class="titledesc">
470
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
471
                        </th>
472
                        <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
473
                            <select
474
                                    name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
475
										echo '[]';
476
									} ?>"
477
                                    id="<?php echo esc_attr( $value['id'] ); ?>"
478
                                    style="<?php echo esc_attr( $value['css'] ); ?>"
479
                                    class="<?php echo esc_attr( $value['class'] ); ?>"
480
								<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
481
								<?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
482
                            >
483
484
								<?php
485
								if ( ! empty( $value['options'] ) ) {
486
									foreach ( $value['options'] as $key => $val ) {
487
										?>
488
                                        <option value="<?php echo esc_attr( $key ); ?>" <?php
489
490
										if ( is_array( $option_value ) ) {
491
											selected( in_array( $key, $option_value ), true );
492
										} else {
493
											selected( $option_value, $key );
494
										}
495
496
										?>><?php echo $val ?></option>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$val'
Loading history...
497
										<?php
498
									}
499
								}
500
								?>
501
502
                            </select> <?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
503
                        </td>
504
                        </tr><?php
505
						break;
506
507
					// Radio inputs.
508
					case 'radio_inline' :
509
						$value['class'] = empty( $value['class'] ) ? 'give-radio-inline' : $value['class'] . ' give-radio-inline';
510
					case 'radio' :
511
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
512
						?>
513
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
514
                        <th scope="row" class="titledesc">
515
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
516
                        </th>
517
                        <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
518
                            <fieldset>
519
                                <ul>
520
									<?php
521 View Code Duplication
									foreach ( $value['options'] as $key => $val ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
522
										?>
523
                                        <li>
524
                                            <label><input
525
                                                        name="<?php echo esc_attr( $value['id'] ); ?>"
526
                                                        value="<?php echo $key; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
527
                                                        type="radio"
528
                                                        style="<?php echo esc_attr( $value['css'] ); ?>"
529
													<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
530
													<?php checked( $key, $option_value ); ?>
531
                                                /> <?php echo $val ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$val'
Loading history...
532
                                        </li>
533
										<?php
534
									}
535
									?>
536
									<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
537
                            </fieldset>
538
                        </td>
539
                        </tr><?php
540
						break;
541
542
					// Checkbox input.
543
					case 'checkbox' :
544
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
545
						?>
546
                        <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
547
                            <th scope="row" class="titledesc">
548
                                <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
549
                            </th>
550
                            <td class="give-forminp">
551
                                <input
552
                                        name="<?php echo esc_attr( $value['id'] ); ?>"
553
                                        id="<?php echo esc_attr( $value['id'] ); ?>"
554
                                        type="checkbox"
555
                                        class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
556
                                        value="1"
557
									<?php checked( $option_value, 'on' ); ?>
558
									<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
559
                                />
560
								<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
561
                            </td>
562
                        </tr>
563
						<?php
564
						break;
565
566
					// Multi Checkbox input.
567
					case 'multicheck' :
568
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
569
						$option_value = is_array( $option_value ) ? $option_value : array();
570
						?>
571
                        <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
572
                            <th scope="row" class="titledesc">
573
                                <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
574
                            </th>
575
                            <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo( ! empty( $value['class'] ) ? $value['class'] : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
576
                                <fieldset>
577
                                    <ul>
578
										<?php
579 View Code Duplication
										foreach ( $value['options'] as $key => $val ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
580
											?>
581
                                            <li>
582
                                                <label>
583
                                                    <input
584
                                                            name="<?php echo esc_attr( $value['id'] ); ?>[]"
585
                                                            value="<?php echo $key; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
586
                                                            type="checkbox"
587
                                                            style="<?php echo esc_attr( $value['css'] ); ?>"
588
														<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
589
														<?php if ( in_array( $key, $option_value ) ) {
590
															echo 'checked="checked"';
591
														} ?>
592
                                                    /> <?php echo $val ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$val'
Loading history...
593
                                                </label>
594
                                            </li>
595
											<?php
596
										}
597
										?>
598
										<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
599
                                </fieldset>
600
                            </td>
601
                        </tr>
602
						<?php
603
						break;
604
605
					// File input field.
606
					case 'file' :
607
					case 'media' :
608
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
609
						$button_label = esc_html__( sprintf( 'Add or Upload %s', ( 'file' === $value['type'] ? 'File' : 'Image' ) ), 'give' );
610
						$fvalue       = empty( $value['fvalue'] ) ? 'url' : $value['fvalue'];
611
612
						$allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
613
						$preview_image_src        = $option_value ? ( 'id' === $fvalue ? wp_get_attachment_url( $option_value ) : $option_value ) : '#';
614
						$preview_image_extension  = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
615
						$is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
616
						?>
617
						<tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
618
							<th scope="row" class="titledesc">
619
								<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
620
							</th>
621
							<td class="give-forminp">
622
								<div class="give-field-wrap">
623
									<label for="<?php echo $value['id'] ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
624
										<input
625
												name="<?php echo esc_attr( $value['id'] ); ?>"
626
												id="<?php echo esc_attr( $value['id'] ); ?>"
627
												type="text"
628
												class="give-input-field<?php echo esc_attr( isset( $value['class'] ) ? ' ' . $value['class'] : '' ); ?>"
629
												value="<?php echo $option_value; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$option_value'
Loading history...
630
												style="<?php echo esc_attr( $value['css'] ); ?>"
631
											<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
632
										/>&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; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$fvalue'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$button_label'
Loading history...
633
										<?php echo $description ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
634
										<div class="give-image-thumb<?php echo ! $option_value || ! $is_show_preview ? ' give-hidden' : ''; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
635
											<span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
636
											<img src="<?php echo $preview_image_src ; ?>" alt="">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$preview_image_src'
Loading history...
637
										</div>
638
									</label>
639
								</div>
640
							</td>
641
							</tr>
642
						<?php
643
						break;
644
645
					// WordPress Editor.
646
					case 'wysiwyg' :
647
						// Get option value.
648
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
649
650
						// Get editor settings.
651
						$editor_settings = ! empty( $value['options'] ) ? $value['options'] : array();
652
						?>
653
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
654
                        <th scope="row" class="titledesc">
655
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
656
                        </th>
657
                        <td class="give-forminp">
658
							<?php wp_editor( $option_value, $value['id'], $editor_settings ); ?>
659
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
660
                        </td>
661
                        </tr><?php
662
						break;
663
664
					// Custom: System setting field.
665 View Code Duplication
					case 'system_info' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
666
						?>
667
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
668
                        <th scope="row" class="titledesc">
669
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
670
                        </th>
671
                        <td class="give-forminp">
672
							<?php give_system_info_callback(); ?>
673
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
674
                        </td>
675
                        </tr><?php
676
						break;
677
678
					// Custom: Default gateways setting field.
679 View Code Duplication
					case 'default_gateway' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
680
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
681
						?>
682
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
683
                        <th scope="row" class="titledesc">
684
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
685
                        </th>
686
                        <td class="give-forminp">
687
							<?php give_default_gateway_callback( $value, $option_value ); ?>
0 ignored issues
show
Documentation introduced by
$option_value is of type string|boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
688
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
689
                        </td>
690
                        </tr><?php
691
						break;
692
693
					// Custom: Enable gateways setting field.
694 View Code Duplication
					case 'enabled_gateways' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
695
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
696
						?>
697
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
698
                        <th scope="row" class="titledesc">
699
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
700
                        </th>
701
                        <td class="give-forminp">
702
							<?php give_enabled_gateways_callback( $value, $option_value ); ?>
0 ignored issues
show
Documentation introduced by
$option_value is of type string|boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
703
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
704
                        </td>
705
                        </tr><?php
706
						break;
707
708
					// Custom: Email preview buttons field.
709 View Code Duplication
					case 'email_preview_buttons' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
710
						?>
711
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
712
                        <th scope="row" class="titledesc">
713
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
714
                        </th>
715
                        <td class="give-forminp">
716
							<?php give_email_preview_buttons_callback(); ?>
717
							<?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
718
                        </td>
719
                        </tr><?php
720
						break;
721
722
					// Custom: API field.
723
					case 'api' :
724
						give_api_callback();
725
						echo $description;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
726
						break;
727
728
					// Custom: Gateway API key.
729 View Code Duplication
					case 'api_key' :
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
730
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
731
						$type         = ! empty( $option_value ) ? 'password' : 'text';
732
						?>
733
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
734
                        <th scope="row" class="titledesc">
735
                            <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo self::get_field_title( $value ); ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
736
                        </th>
737
                        <td class="give-forminp give-forminp-<?php echo sanitize_title( $value['type'] ) ?>">
738
                            <input
739
                                    name="<?php echo esc_attr( $value['id'] ); ?>"
740
                                    id="<?php echo esc_attr( $value['id'] ); ?>"
741
                                    type="<?php echo esc_attr( $type ); ?>"
742
                                    style="<?php echo esc_attr( $value['css'] ); ?>"
743
                                    value="<?php echo esc_attr( trim( $option_value ) ); ?>"
744
                                    class="give-input-field<?php echo( empty( $value['class'] ) ? '' : ' ' . esc_attr( $value['class'] ) ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
745
								<?php echo implode( ' ', $custom_attributes ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
746
                            /> <?php echo $description; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
747
                        </td>
748
                        </tr><?php
749
						break;
750
751
					// Custom: Log field.
752
					case 'logs' :
753
754
						// Get current section.
755
						$current_section = $_GET['section'] = give_get_current_setting_section();
756
757
						/**
758
						 * Fires for each tab of logs view.
759
						 *
760
						 * @since 1.0
761
						 */
762
						do_action( "give_logs_view_{$current_section}" );
763
764
						echo $description;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
765
						break;
766
767
					// Custom: Data field.
768
					case 'data' :
769
770
						include  GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-data.php';
771
772
						echo $description;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$description'
Loading history...
773
						break;
774
775
					// Custom: Give Docs Link field type.
776
					case 'give_docs_link' :
777
						?>
778
                    <tr valign="top" <?php echo ! empty( $value['wrapper_class'] ) ? 'class="' . $value['wrapper_class'] . '"' : '' ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
779
                        <td class="give-docs-link" colspan="2">
780
							<?php
781
							echo '<p class="give-docs-link"><a href="' . esc_url( $value['url'] )
782
							     . '" target="_blank">'
783
							     . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $value['title'] )
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
784
							     . '<span class="dashicons dashicons-editor-help"></span></a></p>';
785
							?>
786
                        </td>
787
                        </tr><?php
788
						break;
789
790
					// Default: run an action
791
					// You can add or handle your custom field action.
792
					default:
793
						// Get option value.
794
						$option_value = self::get_option( $option_name, $value['id'], $value['default'] );
795
						do_action( 'give_admin_field_' . $value['type'], $value, $option_value );
796
						break;
797
				}
798
			}
799
		}
800
801
		/**
802
		 * Helper function to get the formatted description for a given form field.
803
		 * Plugins can call this when implementing their own custom settings types.
804
		 *
805
		 * @since  1.8
806
		 *
807
		 * @param  array $value The form field value array
808
		 *
809
		 * @return string The HTML description of the field.
810
		 */
811
		public static function get_field_description( $value ) {
812
			$description = '';
813
814
			// Support for both 'description' and 'desc' args.
815
			$description_key = isset( $value['description'] ) ? 'description' : 'desc';
816
			$value           = ( isset( $value[ $description_key ] ) && ! empty( $value[ $description_key ] ) ) ? $value[ $description_key ] : '';
817
818
			if ( ! empty( $value ) ) {
819
				$description = '<p class="give-field-description">' . wp_kses_post( $value ) . '</p>';
820
			}
821
822
			return $description;
823
		}
824
825
826
		/**
827
		 * Helper function to get the formated title.
828
		 * Plugins can call this when implementing their own custom settings types.
829
		 *
830
		 * @since  1.8
831
		 *
832
		 * @param  array $value The form field value array
833
		 *
834
		 * @return array The description and tip as a 2 element array
835
		 */
836
		public static function get_field_title( $value ) {
837
			$title = esc_html( $value['title'] );
838
839
			// If html tag detected then allow them to print.
840
			if ( strip_tags( $title ) ) {
841
				$title = $value['title'];
842
			}
843
844
			return $title;
845
		}
846
847
		/**
848
		 * Save admin fields.
849
		 *
850
		 * Loops though the give options array and outputs each field.
851
		 *
852
		 * @since  1.8
853
		 *
854
		 * @param  array  $options     Options array to output
855
		 * @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.
856
		 *
857
		 * @return bool
858
		 */
859
		public static function save_fields( $options, $option_name = '' ) {
860
			if ( empty( $_POST ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
861
				return false;
862
			}
863
864
			// Options to update will be stored here and saved later.
865
			$update_options = array();
866
867
			// Loop options and get values to save.
868
			foreach ( $options as $option ) {
869
				if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
870
					continue;
871
				}
872
873
				// Get posted value.
874
				if ( strstr( $option['id'], '[' ) ) {
875
					parse_str( $option['id'], $option_name_array );
876
					$field_option_name = current( array_keys( $option_name_array ) );
877
					$setting_name      = key( $option_name_array[ $field_option_name ] );
878
					$raw_value         = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
879
				} else {
880
					$field_option_name = $option['id'];
881
					$setting_name      = '';
882
					$raw_value         = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
883
				}
884
885
				// Format the value based on option type.
886
				switch ( $option['type'] ) {
887
					case 'checkbox' :
888
						$value = is_null( $raw_value ) ? '' : 'on';
889
						break;
890
					case 'wysiwyg'  :
891
					case 'textarea' :
892
						$value = wp_kses_post( trim( $raw_value ) );
893
						break;
894
					case 'multiselect' :
895
						$value = array_filter( array_map( 'give_clean', (array) $raw_value ) );
896
						break;
897
					default :
898
						$value = give_clean( $raw_value );
899
						break;
900
				}
901
902
				/**
903
				 * Sanitize the value of an option.
904
				 *
905
				 * @since 1.8
906
				 */
907
				$value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value );
908
909
				/**
910
				 * Sanitize the value of an option by option name.
911
				 *
912
				 * @since 1.8
913
				 */
914
				$value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value );
915
916
				if ( is_null( $value ) ) {
917
					continue;
918
				}
919
920
				// Check if option is an array and handle that differently to single values.
921
				if ( $field_option_name && $setting_name ) {
922
					if ( ! isset( $update_options[ $field_option_name ] ) ) {
923
						$update_options[ $field_option_name ] = get_option( $field_option_name, array() );
924
					}
925
					if ( ! is_array( $update_options[ $field_option_name ] ) ) {
926
						$update_options[ $field_option_name ] = array();
927
					}
928
					$update_options[ $field_option_name ][ $setting_name ] = $value;
929
				} else {
930
					$update_options[ $field_option_name ] = $value;
931
				}
932
			}
933
934
			// Save all options in our array or there own option name i.e. option id.
935
			if ( empty( $option_name ) ) {
936
				foreach ( $update_options as $name => $value ) {
937
					update_option( $name, $value );
938
939
					/**
940
					 * Trigger action.
941
					 *
942
					 * Note: This is dynamically fire on basis of option name.
943
					 *
944
					 * @since 1.8
945
					 */
946
					do_action( "give_save_option_{$name}", $value, $name );
947
				}
948
			} else {
949
				$old_options    = ( $old_options = get_option( $option_name ) ) ? $old_options : array();
950
				$update_options = array_merge( $old_options, $update_options );
951
952
				update_option( $option_name, $update_options );
953
954
				/**
955
				 * Trigger action.
956
				 *
957
				 * Note: This is dynamically fire on basis of setting name.
958
				 *
959
				 * @since 1.8
960
				 */
961
				do_action( "give_save_settings_{$option_name}", $update_options, $option_name );
962
			}
963
964
			return true;
965
		}
966
	}
967
968
endif;
969