Test Failed
Pull Request — master (#2054)
by Devin
05:04
created

Give_MetaBox_Form_Data::output()   D

Complexity

Conditions 22
Paths 145

Size

Total Lines 79
Code Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 68
nc 145
nop 0
dl 0
loc 79
rs 4.7204
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Donation Form Data
4
 *
5
 * Displays the form data box, tabbed, with several panels.
6
 *
7
 * @package     Give
8
 * @subpackage  Classes/Give_MetaBox_Form_Data
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
11
 * @since       1.8
12
 */
13
14
/**
15
 * Give_Meta_Box_Form_Data Class.
16
 */
17
class Give_MetaBox_Form_Data {
18
19
	/**
20
	 * Meta box settings.
21
	 *
22
	 * @since 1.8
23
	 * @var   array
24
	 */
25
	private $settings = array();
26
27
	/**
28
	 * Metabox ID.
29
	 *
30
	 * @since 1.8
31
	 * @var   string
32
	 */
33
	private $metabox_id;
34
35
	/**
36
	 * Metabox Label.
37
	 *
38
	 * @since 1.8
39
	 * @var   string
40
	 */
41
	private $metabox_label;
42
43
44
	/**
45
	 * Give_MetaBox_Form_Data constructor.
46
	 */
47
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
		$this->metabox_id    = 'give-metabox-form-data';
49
		$this->metabox_label = __( 'Donation Form Options', 'give' );
50
51
		// Setup.
52
		add_action( 'admin_init', array( $this, 'setup' ) );
53
54
		// Add metabox.
55
		add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10 );
56
57
		// Save form meta.
58
		add_action( 'save_post_give_forms', array( $this, 'save' ), 10, 2 );
59
60
		// cmb2 old setting loaders.
61
		// add_filter( 'give_metabox_form_data_settings', array( $this, 'cmb2_metabox_settings' ) );
62
		// Add offline donations options.
63
		add_filter( 'give_metabox_form_data_settings', array( $this, 'add_offline_donations_setting_tab' ), 0, 1 );
64
65
		// Maintain active tab query parameter after save.
66
		add_filter( 'redirect_post_location', array( $this, 'maintain_active_tab' ), 10, 2 );
67
	}
68
69
	/**
70
	 * Setup metabox related data.
71
	 *
72
	 * @since  1.8
73
	 * @return void
74
	 */
75
	function setup() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
76
		$this->settings = $this->get_settings();
77
	}
78
79
80
	/**
81
	 * Get metabox settings
82
	 *
83
	 * @since  1.8
84
	 * @return array
85
	 */
86
	function get_settings() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
87
		$post_id               = give_get_admin_post_id();
88
		$price                 = give_get_form_price( $post_id );
89
		$custom_amount_minimum = give_get_form_minimum_price( $post_id );
90
		$goal                  = give_format_amount( give_get_form_goal( $post_id ), array( 'sanitize' => false ) );
0 ignored issues
show
Documentation introduced by
give_get_form_goal($post_id) is of type false|double, but the function expects a string.

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...
91
		$price_placeholder     = give_format_decimal( '1.00', false, false );
92
93
		// No empty prices - min. 1.00 for new forms
94
		if ( empty( $price ) && is_null( $post_id ) ) {
95
			$price = '1.00';
96
		}
97
98
		// Min. $1.00 for new forms
99
		if ( empty( $custom_amount_minimum ) ) {
100
			$custom_amount_minimum = '1.00';
101
		}
102
103
		// Format amounts.
104
		$price                 = give_format_amount( $price, array( 'sanitize' => false ) );
105
		$custom_amount_minimum = give_format_amount( $custom_amount_minimum, array( 'sanitize' => false ) );
106
107
		// Start with an underscore to hide fields from custom fields list
108
		$prefix = '_give_';
109
110
		$settings = array(
111
			/**
112
			 * Repeatable Field Groups
113
			 */
114
			'form_field_options'    => apply_filters( 'give_forms_field_options', array(
115
				'id'        => 'form_field_options',
116
				'title'     => __( 'Donation Options', 'give' ),
117
				'icon-html' => '<span class="give-icon give-icon-heart"></span>',
118
				'fields'    => apply_filters( 'give_forms_donation_form_metabox_fields', array(
119
					// Donation Option
120
					array(
121
						'name'        => __( 'Donation Option', 'give' ),
122
						'description' => __( 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give' ),
123
						'id'          => $prefix . 'price_option',
124
						'type'        => 'radio_inline',
125
						'default'     => 'set',
126
						'options'     => apply_filters( 'give_forms_price_options', array(
127
							'set'   => __( 'Set Donation', 'give' ),
128
							'multi' => __( 'Multi-level Donation', 'give' ),
129
						) ),
130
					),
131
					array(
132
						'name'        => __( 'Set Donation', 'give' ),
133
						'description' => __( 'This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', 'give' ),
134
						'id'          => $prefix . 'set_price',
135
						'type'        => 'text_small',
136
						'data_type'   => 'price',
137
						'attributes'  => array(
138
							'placeholder' => $price_placeholder,
139
							'value'       => $price,
140
							'class'       => 'give-money-field',
141
						),
142
					),
143
					// Display Style
144
					array(
145
						'name'          => __( 'Display Style', 'give' ),
146
						'description'   => __( 'Set how the donations levels will display on the form.', 'give' ),
147
						'id'            => $prefix . 'display_style',
148
						'type'          => 'radio_inline',
149
						'default'       => 'buttons',
150
						'options'       => array(
151
							'buttons'  => __( 'Buttons', 'give' ),
152
							'radios'   => __( 'Radios', 'give' ),
153
							'dropdown' => __( 'Dropdown', 'give' ),
154
						),
155
						'wrapper_class' => 'give-hidden',
156
					),
157
					// Custom Amount
158
					array(
159
						'name'        => __( 'Custom Amount', 'give' ),
160
						'description' => __( 'Do you want the user to be able to input their own donation amount?', 'give' ),
161
						'id'          => $prefix . 'custom_amount',
162
						'type'        => 'radio_inline',
163
						'default'     => 'disabled',
164
						'options'     => array(
165
							'enabled'  => __( 'Enabled', 'give' ),
166
							'disabled' => __( 'Disabled', 'give' ),
167
						),
168
					),
169
					array(
170
						'name'          => __( 'Minimum Amount', 'give' ),
171
						'description'   => __( 'Enter the minimum custom donation amount.', 'give' ),
172
						'id'            => $prefix . 'custom_amount_minimum',
173
						'type'          => 'text_small',
174
						'data_type'     => 'price',
175
						'attributes'    => array(
176
							'placeholder' => $price_placeholder,
177
							'value'       => $custom_amount_minimum,
178
							'class'       => 'give-money-field',
179
						),
180
						'wrapper_class' => 'give-hidden',
181
					),
182
					array(
183
						'name'          => __( 'Custom Amount Text', 'give' ),
184
						'description'   => __( 'This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as it\'s own level (ie button, radio, or select option).', 'give' ),
185
						'id'            => $prefix . 'custom_amount_text',
186
						'type'          => 'text_medium',
187
						'attributes'    => array(
188
							'rows'        => 3,
189
							'placeholder' => esc_attr__( 'Give a Custom Amount', 'give' ),
190
						),
191
						'wrapper_class' => 'give-hidden',
192
					),
193
					// Donation Levels: Repeatable CMB2 Group
194
					array(
195
						'id'            => $prefix . 'donation_levels',
196
						'type'          => 'group',
197
						'options'       => array(
198
							'add_button'    => __( 'Add Level', 'give' ),
199
							'header_title'  => __( 'Donation Level', 'give' ),
200
							'remove_button' => '<span class="dashicons dashicons-no"></span>',
201
						),
202
						'wrapper_class' => 'give-hidden',
203
						// Fields array works the same, except id's only need to be unique for this group.
204
						// Prefix is not needed.
205
						'fields'        => apply_filters( 'give_donation_levels_table_row', array(
206
							array(
207
								'name' => __( 'ID', 'give' ),
208
								'id'   => $prefix . 'id',
209
								'type' => 'levels_id',
210
							),
211
							array(
212
								'name'       => __( 'Amount', 'give' ),
213
								'id'         => $prefix . 'amount',
214
								'type'       => 'text_small',
215
								'data_type'  => 'price',
216
								'attributes' => array(
217
									'placeholder' => $price_placeholder,
218
									'class'       => 'give-money-field',
219
								),
220
							),
221
							array(
222
								'name'       => __( 'Text', 'give' ),
223
								'id'         => $prefix . 'text',
224
								'type'       => 'text',
225
								'attributes' => array(
226
									'placeholder' => __( 'Donation Level', 'give' ),
227
									'class'       => 'give-multilevel-text-field',
228
								),
229
							),
230
							array(
231
								'name' => __( 'Default', 'give' ),
232
								'id'   => $prefix . 'default',
233
								'type' => 'give_default_radio_inline',
234
							),
235
						) ),
236
					),
237
					array(
238
						'name'  => 'donation_options_docs',
239
						'type'  => 'docs_link',
240
						'url'   => 'http://docs.givewp.com/form-donation-options',
241
						'title' => __( 'Donation Options', 'give' ),
242
					),
243
				),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 16.
Loading history...
244
					$post_id
245
				),
246
			) ),
247
248
			/**
249
			 * Display Options
250
			 */
251
			'form_display_options'  => apply_filters( 'give_form_display_options', array(
252
					'id'        => 'form_display_options',
253
					'title'     => __( 'Form Display', 'give' ),
254
					'icon-html' => '<span class="give-icon give-icon-display"></span>',
255
					'fields'    => apply_filters( 'give_forms_display_options_metabox_fields', array(
256
						array(
257
							'name'    => __( 'Display Options', 'give' ),
258
							'desc'    => sprintf( __( 'How would you like to display donation information for this form?', 'give' ), '#' ),
259
							'id'      => $prefix . 'payment_display',
260
							'type'    => 'radio_inline',
261
							'options' => array(
262
								'onpage' => __( 'All Fields', 'give' ),
263
								'modal'  => __( 'Modal', 'give' ),
264
								'reveal' => __( 'Reveal', 'give' ),
265
								'button' => __( 'Button', 'give' ),
266
							),
267
							'default' => 'onpage',
268
						),
269
						array(
270
							'id'            => $prefix . 'reveal_label',
271
							'name'          => __( 'Continue Button', 'give' ),
272
							'desc'          => __( 'The button label for displaying the additional payment fields.', 'give' ),
273
							'type'          => 'text_small',
274
							'attributes'    => array(
275
								'placeholder' => esc_attr__( 'Donate Now', 'give' ),
276
							),
277
							'wrapper_class' => 'give-hidden',
278
						),
279
						array(
280
							'id'         => $prefix . 'checkout_label',
281
							'name'       => __( 'Submit Button', 'give' ),
282
							'desc'       => __( 'The button label for completing a donation.', 'give' ),
283
							'type'       => 'text_small',
284
							'attributes' => array(
285
								'placeholder' => __( 'Donate Now', 'give' ),
286
							),
287
						),
288
						array(
289
							'name' => __( 'Default Gateway', 'give' ),
290
							'desc' => __( 'By default, the gateway for this form will inherit the global default gateway (set under Give > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give' ),
291
							'id'   => $prefix . 'default_gateway',
292
							'type' => 'default_gateway',
293
						),
294
						array(
295
							'name'    => __( 'Guest Donations', 'give' ),
296
							'desc'    => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ),
297
							'id'      => $prefix . 'logged_in_only',
298
							'type'    => 'radio_inline',
299
							'default' => 'enabled',
300
							'options' => array(
301
								'enabled'  => __( 'Enabled', 'give' ),
302
								'disabled' => __( 'Disabled', 'give' ),
303
							),
304
						),
305
						array(
306
							'name'    => __( 'Registration', 'give' ),
307
							'desc'    => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ),
308
							'id'      => $prefix . 'show_register_form',
309
							'type'    => 'radio',
310
							'options' => array(
311
								'none'         => __( 'None', 'give' ),
312
								'registration' => __( 'Registration', 'give' ),
313
								'login'        => __( 'Login', 'give' ),
314
								'both'         => __( 'Registration + Login', 'give' ),
315
							),
316
							'default' => 'none',
317
						),
318
						array(
319
							'name'    => __( 'Floating Labels', 'give' ),
320
							/* translators: %s: forms http://docs.givewp.com/form-floating-labels */
321
							'desc'    => sprintf( __( 'Select the <a href="%s" target="_blank">floating labels</a> setting for this Give form. Be aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give' ), esc_url( 'http://docs.givewp.com/form-floating-labels' ) ),
322
							'id'      => $prefix . 'form_floating_labels',
323
							'type'    => 'radio_inline',
324
							'options' => array(
325
								'global'   => __( 'Global Option', 'give' ),
326
								'enabled'  => __( 'Enabled', 'give' ),
327
								'disabled' => __( 'Disabled', 'give' ),
328
							),
329
							'default' => 'global',
330
						),
331
						array(
332
							'name'  => 'form_display_docs',
333
							'type'  => 'docs_link',
334
							'url'   => 'http://docs.givewp.com/form-display-options',
335
							'title' => __( 'Form Display', 'give' ),
336
						),
337
					),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 20.
Loading history...
338
						$post_id
339
					),
340
				)
341
			),
342
343
			/**
344
			 * Donation Goals
345
			 */
346
			'donation_goal_options' => apply_filters( 'give_donation_goal_options', array(
347
				'id'        => 'donation_goal_options',
348
				'title'     => __( 'Donation Goal', 'give' ),
349
				'icon-html' => '<span class="give-icon give-icon-target"></span>',
350
				'fields'    => apply_filters( 'give_forms_donation_goal_metabox_fields', array(
351
					// Goals
352
					array(
353
						'name'        => __( 'Donation Goal', 'give' ),
354
						'description' => __( 'Do you want to set a donation goal for this form?', 'give' ),
355
						'id'          => $prefix . 'goal_option',
356
						'type'        => 'radio_inline',
357
						'default'     => 'disabled',
358
						'options'     => array(
359
							'enabled'  => __( 'Enabled', 'give' ),
360
							'disabled' => __( 'Disabled', 'give' ),
361
						),
362
					),
363
					array(
364
						'name'          => __( 'Goal Amount', 'give' ),
365
						'description'   => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ),
366
						'id'            => $prefix . 'set_goal',
367
						'type'          => 'text_small',
368
						'data_type'     => 'price',
369
						'attributes'    => array(
370
							'placeholder' => give_format_decimal( '0.00', false, false ),
371
							'value'       => $goal,
372
							'class'       => 'give-money-field',
373
						),
374
						'wrapper_class' => 'give-hidden',
375
					),
376
377
					array(
378
						'name'          => __( 'Goal Format', 'give' ),
379
						'description'   => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded".', 'give' ),
380
						'id'            => $prefix . 'goal_format',
381
						'type'          => 'radio_inline',
382
						'default'       => 'amount',
383
						'options'       => array(
384
							'amount'     => __( 'Amount', 'give' ),
385
							'percentage' => __( 'Percentage', 'give' ),
386
						),
387
						'wrapper_class' => 'give-hidden',
388
					),
389
					array(
390
						'name'          => __( 'Progress Bar Color', 'give' ),
391
						'desc'          => __( 'Customize the color of the goal progress bar.', 'give' ),
392
						'id'            => $prefix . 'goal_color',
393
						'type'          => 'colorpicker',
394
						'default'       => '#2bc253',
395
						'wrapper_class' => 'give-hidden',
396
					),
397
398
					array(
399
						'name'          => __( 'Close Form', 'give' ),
400
						'desc'          => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ),
401
						'id'            => $prefix . 'close_form_when_goal_achieved',
402
						'type'          => 'radio_inline',
403
						'default'       => 'disabled',
404
						'options'       => array(
405
							'enabled'  => __( 'Enabled', 'give' ),
406
							'disabled' => __( 'Disabled', 'give' ),
407
						),
408
						'wrapper_class' => 'give-hidden',
409
					),
410
					array(
411
						'name'          => __( 'Goal Achieved Message', 'give' ),
412
						'desc'          => __( 'Do you want to display a custom message when the goal is closed?', 'give' ),
413
						'id'            => $prefix . 'form_goal_achieved_message',
414
						'type'          => 'wysiwyg',
415
						'default'       => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ),
416
						'wrapper_class' => 'give-hidden',
417
					),
418
					array(
419
						'name'  => 'donation_goal_docs',
420
						'type'  => 'docs_link',
421
						'url'   => 'http://docs.givewp.com/form-donation-goal',
422
						'title' => __( 'Donation Goal', 'give' ),
423
					),
424
				),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 16.
Loading history...
425
					$post_id
426
				),
427
			) ),
428
429
			/**
430
			 * Content Field
431
			 */
432
			'form_content_options'  => apply_filters( 'give_forms_content_options', array(
433
				'id'        => 'form_content_options',
434
				'title'     => __( 'Form Content', 'give' ),
435
				'icon-html' => '<span class="give-icon give-icon-edit"></span>',
436
				'fields'    => apply_filters( 'give_forms_content_options_metabox_fields', array(
437
438
					// Donation content.
439
					array(
440
						'name'        => __( 'Display Content', 'give' ),
441
						'description' => __( 'Do you want to add custom content to this form?', 'give' ),
442
						'id'          => $prefix . 'display_content',
443
						'type'        => 'radio_inline',
444
						'options'     => array(
445
							'enabled'  => __( 'Enabled', 'give' ),
446
							'disabled' => __( 'Disabled', 'give' ),
447
						),
448
						'default'     => 'disabled',
449
					),
450
451
					// Content placement.
452
					array(
453
						'name'          => __( 'Content Placement', 'give' ),
454
						'description'   => __( 'This option controls where the content appears within the donation form.', 'give' ),
455
						'id'            => $prefix . 'content_placement',
456
						'type'          => 'radio_inline',
457
						'options'       => apply_filters( 'give_forms_content_options_select', array(
458
								'give_pre_form'  => __( 'Above fields', 'give' ),
459
								'give_post_form' => __( 'Below fields', 'give' ),
460
							)
461
						),
462
						'default'       => 'give_pre_form',
463
						'wrapper_class' => 'give-hidden',
464
					),
465
					array(
466
						'name'          => __( 'Content', 'give' ),
467
						'description'   => __( 'This content will display on the single give form page.', 'give' ),
468
						'id'            => $prefix . 'form_content',
469
						'type'          => 'wysiwyg',
470
						'wrapper_class' => 'give-hidden',
471
					),
472
					array(
473
						'name'  => 'form_content_docs',
474
						'type'  => 'docs_link',
475
						'url'   => 'http://docs.givewp.com/form-content',
476
						'title' => __( 'Form Content', 'give' ),
477
					),
478
				),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 16.
Loading history...
479
					$post_id
480
				),
481
			) ),
482
483
			/**
484
			 * Terms & Conditions
485
			 */
486
			'form_terms_options'    => apply_filters( 'give_forms_terms_options', array(
487
				'id'        => 'form_terms_options',
488
				'title'     => __( 'Terms & Conditions', 'give' ),
489
				'icon-html' => '<span class="give-icon give-icon-checklist"></span>',
490
				'fields'    => apply_filters( 'give_forms_terms_options_metabox_fields', array(
491
					// Donation Option
492
					array(
493
						'name'        => __( 'Terms and Conditions', 'give' ),
494
						'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ),
495
						'id'          => $prefix . 'terms_option',
496
						'type'        => 'radio_inline',
497
						'options'     => apply_filters( 'give_forms_content_options_select', array(
498
								'global'   => __( 'Global Option', 'give' ),
499
								'enabled'  => __( 'Customize', 'give' ),
500
								'disabled' => __( 'Disable', 'give' ),
501
							)
502
						),
503
						'default'     => 'global',
504
					),
505
					array(
506
						'id'            => $prefix . 'agree_label',
507
						'name'          => __( 'Agreement Label', 'give' ),
508
						'desc'          => __( 'The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give' ),
509
						'type'          => 'text',
510
						'size'          => 'regular',
511
						'attributes'    => array(
512
							'placeholder' => esc_attr__( 'Agree to Terms?', 'give' ),
513
						),
514
						'wrapper_class' => 'give-hidden',
515
					),
516
					array(
517
						'id'            => $prefix . 'agree_text',
518
						'name'          => __( 'Agreement Text', 'give' ),
519
						'desc'          => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ),
520
						'default'       => give_get_option( 'agreement_text' ),
521
						'type'          => 'wysiwyg',
522
						'wrapper_class' => 'give-hidden',
523
					),
524
					array(
525
						'name'  => 'terms_docs',
526
						'type'  => 'docs_link',
527
						'url'   => 'http://docs.givewp.com/form-terms',
528
						'title' => __( 'Terms and Conditions', 'give' ),
529
					),
530
				),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 16.
Loading history...
531
					$post_id
532
				),
533
			) ),
534
		);
535
536
		/**
537
		 * Filter the metabox tabbed panel settings.
538
		 */
539
		$settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id );
540
541
		// Output.
542
		return $settings;
543
	}
544
545
	/**
546
	 * Add metabox.
547
	 *
548
	 * @since  1.8
549
	 * @return void
550
	 */
551
	public function add_meta_box() {
552
		add_meta_box(
553
			$this->get_metabox_ID(),
554
			$this->get_metabox_label(),
555
			array( $this, 'output' ),
556
			array( 'give_forms' ),
557
			'normal',
558
			'high'
559
		);
560
	}
561
562
563
	/**
564
	 * Enqueue scripts.
565
	 *
566
	 * @since  1.8
567
	 * @return void
568
	 */
569
	function enqueue_script() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
570
		global $post;
571
572
		if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
573
574
		}
575
	}
576
577
	/**
578
	 * Get metabox id.
579
	 *
580
	 * @since  1.8
581
	 * @return string
582
	 */
583
	function get_metabox_ID() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
The function name get_metabox_ID is in camel caps, but expected get_metabox_i_d instead as per the coding standard.
Loading history...
584
		return $this->metabox_id;
585
	}
586
587
	/**
588
	 * Get metabox label.
589
	 *
590
	 * @since  1.8
591
	 * @return string
592
	 */
593
	function get_metabox_label() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
594
		return $this->metabox_label;
595
	}
596
597
598
	/**
599
	 * Get metabox tabs.
600
	 *
601
	 * @since  1.8
602
	 * @return array
603
	 */
604
	public function get_tabs() {
605
		$tabs = array();
606
607
		if ( ! empty( $this->settings ) ) {
608
			foreach ( $this->settings as $setting ) {
609
				if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) {
610
					continue;
611
				}
612
				$tab = array(
613
					'id'        => $setting['id'],
614
					'label'     => $setting['title'],
615
					'icon-html' => ( ! empty( $setting['icon-html'] ) ? $setting['icon-html'] : '' ),
616
				);
617
618
				if ( $this->has_sub_tab( $setting ) ) {
619
					if ( empty( $setting['sub-fields'] ) ) {
620
						$tab = array();
621
					} else {
622
						foreach ( $setting['sub-fields'] as $sub_fields ) {
623
							$tab['sub-fields'][] = array(
624
								'id'        => $sub_fields['id'],
625
								'label'     => $sub_fields['title'],
626
								'icon-html' => ( ! empty( $sub_fields['icon-html'] ) ? $sub_fields['icon-html'] : '' ),
627
							);
628
						}
629
					}
630
				}
631
632
				if ( ! empty( $tab ) ) {
633
					$tabs[] = $tab;
634
				}
635
			}
636
		}
637
638
		return $tabs;
639
	}
640
641
	/**
642
	 * Output metabox settings.
643
	 *
644
	 * @since  1.8
645
	 * @return void
646
	 */
647
	public function output() {
648
		// Bailout.
649
		if ( $form_data_tabs = $this->get_tabs() ) :
650
			$active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_field_options';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
651
			wp_nonce_field( 'give_save_form_meta', 'give_form_meta_nonce' );
652
			?>
653
			<input id="give_form_active_tab" type="hidden" name="give_form_active_tab">
654
			<div class="give-metabox-panel-wrap">
655
				<ul class="give-form-data-tabs give-metabox-tabs">
656
					<?php foreach ( $form_data_tabs as $index => $form_data_tab ) : ?>
657
						<?php
658
						// Determine if current tab is active.
659
						$is_active = $active_tab === $form_data_tab['id'] ? true : false;
660
						?>
661
						<li class="<?php echo "{$form_data_tab['id']}_tab" . ( $is_active ? ' active' : '' ) . ( $this->has_sub_tab( $form_data_tab ) ? ' has-sub-fields' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"{$form_data_tab['id']}_tab"'
Loading history...
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
662
							<a href="#<?php echo $form_data_tab['id']; ?>" data-tab-id="<?php echo $form_data_tab['id']; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_data_tab'
Loading history...
663
								<?php if ( ! empty( $form_data_tab['icon-html'] ) ) : ?>
664
									<?php echo $form_data_tab['icon-html']; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_data_tab'
Loading history...
665
								<?php else : ?>
666
									<span class="give-icon give-icon-default"></span>
667
								<?php endif; ?>
668
								<span class="give-label"><?php echo $form_data_tab['label']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_data_tab'
Loading history...
669
							</a>
670
							<?php if ( $this->has_sub_tab( $form_data_tab ) ) : ?>
671
								<ul class="give-metabox-sub-tabs give-hidden">
672
									<?php foreach ( $form_data_tab['sub-fields'] as $sub_tab ) : ?>
673
										<li class="<?php echo "{$sub_tab['id']}_tab"; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"{$sub_tab['id']}_tab"'
Loading history...
674
											<a href="#<?php echo $sub_tab['id']; ?>" data-tab-id="<?php echo $sub_tab['id']; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$sub_tab'
Loading history...
675
												<?php if ( ! empty( $sub_tab['icon-html'] ) ) : ?>
676
													<?php echo $sub_tab['icon-html']; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$sub_tab'
Loading history...
677
												<?php else : ?>
678
													<span class="give-icon give-icon-default"></span>
679
												<?php endif; ?>
680
												<span class="give-label"><?php echo $sub_tab['label']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$sub_tab'
Loading history...
681
											</a>
682
										</li>
683
									<?php endforeach; ?>
684
								</ul>
685
							<?php endif; ?>
686
						</li>
687
					<?php endforeach; ?>
688
				</ul>
689
690
				<?php foreach ( $this->settings as $setting ) : ?>
691
					<?php if ( ! $this->has_sub_tab( $setting ) ) : ?>
692
						<?php do_action( "give_before_{$setting['id']}_settings" ); ?>
693
						<?php
694
						// Determine if current panel is active.
695
						$is_active = $active_tab === $setting['id'] ? true : false;
696
						?>
697
						<div id="<?php echo $setting['id']; ?>" class="panel give_options_panel<?php echo( $is_active ? ' active' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$setting'
Loading history...
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
698
							<?php if ( ! empty( $setting['fields'] ) ) : ?>
699
								<?php foreach ( $setting['fields'] as $field ) : ?>
700
									<?php give_render_field( $field ); ?>
701
								<?php endforeach; ?>
702
							<?php endif; ?>
703
						</div>
704
705
						<?php do_action( "give_after_{$setting['id']}_settings" ); ?>
706
					<?php else : ?>
707
						<?php if ( $this->has_sub_tab( $setting ) ) : ?>
708
							<?php if ( ! empty( $setting['sub-fields'] ) ) : ?>
709
								<?php foreach ( $setting['sub-fields'] as $index => $sub_fields ) : ?>
710
									<div id="<?php echo $sub_fields['id']; ?>" class="panel give_options_panel give-hidden">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$sub_fields'
Loading history...
711
										<?php if ( ! empty( $sub_fields['fields'] ) ) : ?>
712
											<?php foreach ( $sub_fields['fields'] as $sub_field ) : ?>
713
												<?php give_render_field( $sub_field ); ?>
714
											<?php endforeach; ?>
715
										<?php endif; ?>
716
									</div>
717
								<?php endforeach; ?>
718
							<?php endif; ?>
719
						<?php endif; ?>
720
					<?php endif; ?>
721
				<?php endforeach; ?>
722
			</div>
723
			<?php
724
		endif; // End if().
725
	}
726
727
728
	/**
729
	 * Check if setting field has sub tabs/fields
730
	 *
731
	 * @since 1.8
732
	 *
733
	 * @param $field_setting
734
	 *
735
	 * @return bool
736
	 */
737
	private function has_sub_tab( $field_setting ) {
738
		$has_sub_tab = false;
739
		if ( array_key_exists( 'sub-fields', $field_setting ) ) {
740
			$has_sub_tab = true;
741
		}
742
743
		return $has_sub_tab;
744
	}
745
746
	/**
747
	 * CMB2 settings loader.
748
	 *
749
	 * @since  1.8
750
	 * @return array
751
	 */
752
	function cmb2_metabox_settings() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
753
		$all_cmb2_settings   = apply_filters( 'cmb2_meta_boxes', array() );
754
		$give_forms_settings = $all_cmb2_settings;
755
756
		// Filter settings: Use only give forms related settings.
757
		foreach ( $all_cmb2_settings as $index => $setting ) {
758
			if ( ! in_array( 'give_forms', $setting['object_types'] ) ) {
759
				unset( $give_forms_settings[ $index ] );
760
			}
761
		}
762
763
		return $give_forms_settings;
764
765
	}
766
767
	/**
768
	 * Check if we're saving, the trigger an action based on the post type.
769
	 *
770
	 * @since  1.8
771
	 *
772
	 * @param  int    $post_id
773
	 * @param  object $post
774
	 *
775
	 * @return void
776
	 */
777
	public function save( $post_id, $post ) {
778
779
		// $post_id and $post are required.
780
		if ( empty( $post_id ) || empty( $post ) ) {
781
			return;
782
		}
783
784
		// Don't save meta boxes for revisions or autosaves.
785
		if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
786
			return;
787
		}
788
789
		// Check the nonce.
790
		if ( empty( $_POST['give_form_meta_nonce'] ) || ! wp_verify_nonce( $_POST['give_form_meta_nonce'], 'give_save_form_meta' ) ) {
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...
791
			return;
792
		}
793
794
		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
795
		if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
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...
796
			return;
797
		}
798
799
		// Check user has permission to edit.
800
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
801
			return;
802
		}
803
804
		// Fire action before saving form meta.
805
		do_action( 'give_pre_process_give_forms_meta', $post_id, $post );
806
807
		/**
808
		 * Filter the meta key to save.
809
		 * Third party addon developer can remove there meta keys from this array to handle saving data on there own.
810
		 */
811
		$form_meta_keys = apply_filters( 'give_process_form_meta_keys', $this->get_meta_keys_from_settings() );
812
813
		// Save form meta data.
814
		if ( ! empty( $form_meta_keys ) ) {
815
			foreach ( $form_meta_keys as $form_meta_key ) {
816
817
				// Set default value for checkbox fields.
818
				if (
819
					! isset( $_POST[ $form_meta_key ] )
820
					&& ( 'checkbox' === $this->get_field_type( $form_meta_key ) )
821
				) {
822
					$_POST[ $form_meta_key ] = '';
823
				}
824
825
				if ( isset( $_POST[ $form_meta_key ] ) ) {
826
					$setting_field = $this->get_setting_field( $form_meta_key );
827
					if ( ! empty( $setting_field['type'] ) ) {
828
						switch ( $setting_field['type'] ) {
829
							case 'textarea':
830
							case 'wysiwyg':
831
								$form_meta_value = wp_kses_post( $_POST[ $form_meta_key ] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
832
								break;
833
834
							case 'group':
835
								$form_meta_value = array();
836
837
								foreach ( $_POST[ $form_meta_key ] as $index => $group ) {
0 ignored issues
show
Bug introduced by
The expression $_POST[$form_meta_key] of type string is not traversable.
Loading history...
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...
838
839
									// Do not save template input field values.
840
									if ( '{{row-count-placeholder}}' === $index ) {
841
										continue;
842
									}
843
844
									$group_meta_value = array();
845
									foreach ( $group as $field_id => $field_value ) {
846
										switch ( $this->get_field_type( $field_id, $form_meta_key ) ) {
847
											case 'wysiwyg':
848
												$group_meta_value[ $field_id ] = wp_kses_post( $field_value );
849
												break;
850
851
											default:
852
												$group_meta_value[ $field_id ] = give_clean( $field_value );
853
										}
854
									}
855
856
									if ( ! empty( $group_meta_value ) ) {
857
										$form_meta_value[ $index ] = $group_meta_value;
858
									}
859
								}
860
861
								// Arrange repeater field keys in order.
862
								$form_meta_value = array_values( $form_meta_value );
863
								break;
864
865
							default:
866
								$form_meta_value = give_clean( $_POST[ $form_meta_key ] );
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...
867
						}// End switch().
868
869
						/**
870
						 * Filter the form meta value before saving
871
						 *
872
						 * @since 1.8.9
873
						 */
874
						$form_meta_value = apply_filters(
875
							'give_pre_save_form_meta_value',
876
							$this->sanitize_form_meta( $form_meta_value, $setting_field ),
877
							$form_meta_key,
878
							$this,
879
							$post_id
880
						);
881
882
						// Save data.
883
						give_update_meta( $post_id, $form_meta_key, $form_meta_value );
884
885
						// Fire after saving form meta key.
886
						do_action( "give_save_{$form_meta_key}", $form_meta_key, $form_meta_value, $post_id, $post );
887
					}// End if().
888
				}// End if().
889
			}// End foreach().
890
		}// End if().
891
892
		// Fire action after saving form meta.
893
		do_action( 'give_post_process_give_forms_meta', $post_id, $post );
894
	}
895
896
897
	/**
898
	 * Get field ID.
899
	 *
900
	 * @since 1.8
901
	 *
902
	 * @param array $field
903
	 *
904
	 * @return string
905
	 */
906
	private function get_field_id( $field ) {
907
		$field_id = '';
908
909
		if ( array_key_exists( 'id', $field ) ) {
910
			$field_id = $field['id'];
911
912
		}
913
914
		return $field_id;
915
	}
916
917
	/**
918
	 * Get fields ID.
919
	 *
920
	 * @since 1.8
921
	 *
922
	 * @param $setting
923
	 *
924
	 * @return array
925
	 */
926 View Code Duplication
	private function get_fields_id( $setting ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
927
		$meta_keys = array();
928
929
		if ( ! empty( $setting ) ) {
930
			foreach ( $setting['fields'] as $field ) {
931
				if ( $field_id = $this->get_field_id( $field ) ) {
932
					$meta_keys[] = $field_id;
933
				}
934
			}
935
		}
936
937
		return $meta_keys;
938
	}
939
940
	/**
941
	 * Get sub fields ID.
942
	 *
943
	 * @since 1.8
944
	 *
945
	 * @param $setting
946
	 *
947
	 * @return array
948
	 */
949
	private function get_sub_fields_id( $setting ) {
950
		$meta_keys = array();
951
952
		if ( $this->has_sub_tab( $setting ) && ! empty( $setting['sub-fields'] ) ) {
953
			foreach ( $setting['sub-fields'] as $fields ) {
954
				if ( ! empty( $fields['fields'] ) ) {
955
					foreach ( $fields['fields'] as $field ) {
956
						if ( $field_id = $this->get_field_id( $field ) ) {
957
							$meta_keys[] = $field_id;
958
						}
959
					}
960
				}
961
			}
962
		}
963
964
		return $meta_keys;
965
	}
966
967
968
	/**
969
	 * Get all setting field ids.
970
	 *
971
	 * @since  1.8
972
	 * @return array
973
	 */
974
	private function get_meta_keys_from_settings() {
975
		$meta_keys = array();
976
977
		foreach ( $this->settings as $setting ) {
978
			if ( $this->has_sub_tab( $setting ) ) {
979
				$meta_key = $this->get_sub_fields_id( $setting );
980
			} else {
981
				$meta_key = $this->get_fields_id( $setting );
982
			}
983
984
			$meta_keys = array_merge( $meta_keys, $meta_key );
985
		}
986
987
		return $meta_keys;
988
	}
989
990
991
	/**
992
	 * Get field type.
993
	 *
994
	 * @since  1.8
995
	 *
996
	 * @param  string $field_id
997
	 * @param  string $group_id
998
	 *
999
	 * @return string
1000
	 */
1001
	function get_field_type( $field_id, $group_id = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1002
		$field = $this->get_setting_field( $field_id, $group_id );
1003
1004
		$type = array_key_exists( 'type', $field )
1005
			? $field['type']
1006
			: '';
1007
1008
		return $type;
1009
	}
1010
1011
1012
	/**
1013
	 * Get Field
1014
	 *
1015
	 * @since 1.8
1016
	 *
1017
	 * @param array  $setting
1018
	 * @param string $field_id
1019
	 *
1020
	 * @return array
1021
	 */
1022
	private function get_field( $setting, $field_id ) {
1023
		$setting_field = array();
1024
1025 View Code Duplication
		if ( ! empty( $setting['fields'] ) ) {
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...
1026
			foreach ( $setting['fields'] as $field ) {
1027
				if ( array_key_exists( 'id', $field ) && $field['id'] === $field_id ) {
1028
					$setting_field = $field;
1029
					break;
1030
				}
1031
			}
1032
		}
1033
1034
		return $setting_field;
1035
	}
1036
1037
	/**
1038
	 * Get Sub Field
1039
	 *
1040
	 * @since 1.8
1041
	 *
1042
	 * @param array  $setting
1043
	 * @param string $field_id
1044
	 *
1045
	 * @return array
1046
	 */
1047 View Code Duplication
	private function get_sub_field( $setting, $field_id ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1048
		$setting_field = array();
1049
1050
		if ( ! empty( $setting['sub-fields'] ) ) {
1051
			foreach ( $setting['sub-fields'] as $fields ) {
1052
				if ( $field = $this->get_field( $fields, $field_id ) ) {
1053
					$setting_field = $field;
1054
					break;
1055
				}
1056
			}
1057
		}
1058
1059
		return $setting_field;
1060
	}
1061
1062
	/**
1063
	 * Get setting field.
1064
	 *
1065
	 * @since  1.8
1066
	 *
1067
	 * @param  string $field_id
1068
	 * @param  string $group_id Get sub field from group.
1069
	 *
1070
	 * @return array
1071
	 */
1072
	function get_setting_field( $field_id, $group_id = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1073
		$setting_field = array();
1074
1075
		$_field_id = $field_id;
1076
		$field_id  = empty( $group_id ) ? $field_id : $group_id;
1077
1078
		if ( ! empty( $this->settings ) ) {
1079
			foreach ( $this->settings as $setting ) {
1080
				if (
1081
					( $this->has_sub_tab( $setting ) && ( $setting_field = $this->get_sub_field( $setting, $field_id ) ) )
1082
					|| ( $setting_field = $this->get_field( $setting, $field_id ) )
1083
				) {
1084
					break;
1085
				}
1086
			}
1087
		}
1088
1089
		// Get field from group.
1090 View Code Duplication
		if ( ! empty( $group_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...
1091
			foreach ( $setting_field['fields'] as $field ) {
1092
				if ( array_key_exists( 'id', $field ) && $field['id'] === $_field_id ) {
1093
					$setting_field = $field;
1094
				}
1095
			}
1096
		}
1097
1098
		return $setting_field;
1099
	}
1100
1101
1102
	/**
1103
	 * Add offline donations setting tab to donation form options metabox.
1104
	 *
1105
	 * @since  1.8
1106
	 *
1107
	 * @param  array $settings List of form settings.
1108
	 *
1109
	 * @return mixed
1110
	 */
1111
	function add_offline_donations_setting_tab( $settings ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1112
		if ( give_is_gateway_active( 'offline' ) ) {
1113
			$settings['offline_donations_options'] = apply_filters( 'give_forms_offline_donations_options', array(
1114
				'id'        => 'offline_donations_options',
1115
				'title'     => __( 'Offline Donations', 'give' ),
1116
				'icon-html' => '<span class="give-icon give-icon-purse"></span>',
1117
				'fields'    => apply_filters( 'give_forms_offline_donations_metabox_fields', array() ),
1118
			) );
1119
		}
1120
1121
		return $settings;
1122
	}
1123
1124
1125
	/**
1126
	 * Sanitize form meta values before saving.
1127
	 *
1128
	 * @since  1.8.9
1129
	 * @access public
1130
	 *
1131
	 * @param mixed $meta_value
1132
	 * @param array $setting_field
1133
	 *
1134
	 * @return mixed
1135
	 */
1136
	function sanitize_form_meta( $meta_value, $setting_field ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1137
		switch ( $setting_field['type'] ) {
1138
			case 'group':
1139
				if ( ! empty( $setting_field['fields'] ) ) {
1140
					foreach ( $setting_field['fields'] as $field ) {
1141
						if ( empty( $field['data_type'] ) || 'price' !== $field['data_type'] ) {
1142
							continue;
1143
						}
1144
1145
						foreach ( $meta_value as $index => $meta_data ) {
1146
							if ( ! isset( $meta_value[ $index ][ $field['id'] ] ) ) {
1147
								continue;
1148
							}
1149
1150
							$meta_value[ $index ][ $field['id'] ] = ! empty( $meta_value[ $index ][ $field['id'] ] )
1151
								? give_sanitize_amount_for_db( $meta_value[ $index ][ $field['id'] ] )
1152
								: 0;
1153
						}
1154
					}
1155
				}
1156
				break;
1157
1158
			default:
1159
				if ( ! empty( $setting_field['data_type'] ) && 'price' === $setting_field['data_type'] ) {
1160
					$meta_value = $meta_value ? give_sanitize_amount_for_db( $meta_value ) : 0;
1161
				}
1162
		}
1163
1164
		return $meta_value;
1165
	}
1166
1167
	/**
1168
	 * Maintain the active tab after save.
1169
	 *
1170
	 * @since  1.8.13
1171
	 * @access public
1172
	 *
1173
	 * @param string $location The destination URL.
1174
	 * @param int    $post_id  The post ID.
1175
	 *
1176
	 * @return string The URL after redirect.
1177
	 */
1178
	public function maintain_active_tab( $location, $post_id ) {
1179
		if (
1180
			'give_forms' === get_post_type( $post_id ) &&
1181
			! empty( $_POST['give_form_active_tab'] )
1182
		) {
1183
			$location = add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location );
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...
1184
		}
1185
1186
		return $location;
1187
	}
1188
}
1189
1190
new Give_MetaBox_Form_Data();
1191
1192