Test Setup Failed
Push — issue/3872 ( 690bc7 )
by Ravinder
08:20
created

Give_Plugin_Settings::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class Give_Plugin_Settings
5
 *
6
 * Register settings Include and setup custom metaboxes and fields.
7
 *
8
 * @package    Give
9
 * @subpackage Admin
10
 * @license    https://opensource.org/licenses/gpl-license GNU Public License
11
 * @link       https://github.com/webdevstudios/Custom-Metaboxes-and-Fields-for-WordPress
12
 *
13
 * @property $key
14
 * @property $title
15
 * @property $options_page
16
 */
17
class Give_Plugin_Settings {
18
19
	/**
20
	 * Option key, and option page slug.
21
	 *
22
	 * @var string
23
	 */
24
	private $key = 'give_settings';
25
26
	/**
27
	 * Options Page title.
28
	 *
29
	 * @var string
30
	 */
31
	protected $title = '';
32
33
	/**
34
	 * Options Page hook.
35
	 *
36
	 * @var string
37
	 */
38
	protected $options_page = '';
39
40
	/**
41
	 * Give_Plugin_Settings constructor.
42
	 */
43
	public function __construct() {
44
45
		// Custom settings fields.
46
		add_action( 'cmb2_render_give_title', 'give_title_callback', 10, 5 );
47
		add_action( 'cmb2_render_give_description', 'give_description_callback', 10, 5 );
48
		add_action( 'cmb2_render_enabled_gateways', 'give_enabled_gateways_callback', 10, 5 );
49
		add_action( 'cmb2_render_default_gateway', 'give_default_gateway_callback', 10, 5 );
50
		add_action( 'cmb2_render_email_preview_buttons', 'give_email_preview_buttons_callback', 10, 5 );
51
		add_action( 'cmb2_render_system_info', 'give_system_info_callback', 10, 5 );
52
		add_action( 'cmb2_render_api', 'give_api_callback', 10, 5 );
53
		add_action( 'cmb2_render_license_key', 'give_license_key_callback', 10, 5 );
54
	}
55
56
57
	/**
58
	 * Register our setting to WP
59
	 *
60
	 * @since  1.0
61
	 */
62
	public function init() {
63
		register_setting( $this->key, $this->key );
64
65
	}
66
67
68
	/**
69
	 * Filter CMB2 URL
70
	 *
71
	 * Required for CMB2 to properly load CSS/JS.
72
	 *
73
	 * @param $url
74
	 *
75
	 * @return mixed
76
	 */
77
	public function give_update_cmb_meta_box_url( $url ) {
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
		// Path to Give's CMB
79
		return GIVE_PLUGIN_URL . '/includes/libraries/cmb2';
80
	}
81
82
83
	/**
84
	 * Retrieve settings tabs
85
	 *
86
	 * @since 1.0
87
	 * @return array $tabs
88
	 */
89
	public function give_get_settings_tabs() {
90
91
		$settings = $this->give_settings( null );
92
93
		$tabs             = array();
94
		$tabs['general']  = __( 'General', 'give' );
95
		$tabs['gateways'] = __( 'Payment Gateways', 'give' );
96
		$tabs['display']  = __( 'Display Options', 'give' );
97
		$tabs['emails']   = __( 'Emails', 'give' );
98
99
		if ( ! empty( $settings['addons']['fields'] ) ) {
100
			$tabs['addons'] = __( 'Add-ons', 'give' );
101
		}
102
103
		if ( ! empty( $settings['licenses']['fields'] ) ) {
104
			$tabs['licenses'] = __( 'Licenses', 'give' );
105
		}
106
107
		$tabs['advanced']    = __( 'Advanced', 'give' );
108
		$tabs['api']         = __( 'API', 'give' );
109
		$tabs['system_info'] = __( 'System Info', 'give' );
110
111
		return apply_filters( 'give_settings_tabs', $tabs );
112
	}
113
114
115
	/**
116
	 * Admin page markup. Mostly handled by CMB2
117
	 *
118
	 * @since  1.0
119
	 */
120
	public function admin_page_display() {
121
122
		$active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->give_get_settings_tabs() ) ? $_GET['tab'] : 'general';
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...
123
124
		?>
125
126
		<div class="wrap give_settings_page cmb2_options_page <?php echo $this->key; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
127
128
			<h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_admin_page_title'
Loading history...
129
130
			<h2 class="nav-tab-wrapper">
131
				<?php
132
				foreach ( $this->give_get_settings_tabs() as $tab_id => $tab_name ) {
133
134
					$tab_url = esc_url(
135
						add_query_arg(
136
							array(
137
								'settings-updated' => false,
138
								'tab'              => $tab_id,
139
							)
140
						)
141
					);
142
143
					$active = $active_tab == $tab_id ? ' nav-tab-active' : '';
144
145
					echo '<a href="' . esc_url( $tab_url ) . '" class="nav-tab' . $active . '" id="tab-' . $tab_id . '">' . esc_html( $tab_name ) . '</a>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$active'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$tab_id'
Loading history...
146
147
				}
148
				?>
149
			</h2>
150
151
			<?php cmb2_metabox_form( $this->give_settings( $active_tab ), $this->key ); ?>
152
153
		</div><!-- .wrap -->
154
155
		<?php
156
	}
157
158
159
	/**
160
	 *
161
	 * Modify CMB2 Default Form Output
162
	 *
163
	 * @param string @args
164
	 *
165
	 * @since 1.0
166
	 *
167
	 * @param $form_format
168
	 * @param $object_id
169
	 * @param $cmb
170
	 *
171
	 * @return string
172
	 */
173
	function give_modify_cmb2_form_output( $form_format, $object_id, $cmb ) {
0 ignored issues
show
Unused Code introduced by
The parameter $cmb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
174
175
		// only modify the give settings form
176
		if ( 'give_settings' == $object_id ) {
177
178
			return '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="give_settings_saved" value="true"><input type="hidden" name="object_id" value="%2$s">%3$s<div class="give-submit-wrap"><input type="submit" name="submit-cmb" value="' . esc_attr__( 'Save Settings', 'give' ) . '" class="button-primary"></div></form>';
179
180
		}
181
182
		return $form_format;
183
184
	}
185
186
	/**
187
	 * Define General Settings Metabox and field configurations.
188
	 *
189
	 * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
190
	 *
191
	 * @param $active_tab |string active tab settings; null returns full array
192
	 *
193
	 * @return array
194
	 */
195
	public function give_settings( $active_tab ) {
196
197
		$give_settings = array(
198
			/**
199
			 * General Settings
200
			 */
201
			'general'     => array(
202
				'id'         => 'general_settings',
203
				'give_title' => __( 'General Settings', 'give' ),
204
				'show_on'    => array(
205
					'key'   => 'options-page',
206
					'value' => array( $this->key ),
207
				),
208
				'fields'     => apply_filters(
209
					'give_settings_general', array(
210
						array(
211
							'name' => __( 'General Settings', 'give' ),
212
							'desc' => '',
213
							'type' => 'give_title',
214
							'id'   => 'give_title_general_settings_1',
215
						),
216
						array(
217
							'name'    => __( 'Success Page', 'give' ),
218
							/* translators: %s: [give_receipt] */
219
							'desc'    => sprintf( __( 'The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give' ), '<code>[give_receipt]</code>' ),
220
							'id'      => 'success_page',
221
							'type'    => 'select',
222
							'options' => give_cmb2_get_post_options(
223
								array(
224
									'post_type'   => 'page',
225
									'numberposts' => 999,
0 ignored issues
show
introduced by
Detected high pagination limit, numberposts is set to 999
Loading history...
226
								)
227
							),
228
						),
229
						array(
230
							'name'    => __( 'Failed Donation Page', 'give' ),
231
							'desc'    => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
232
							'id'      => 'failure_page',
233
							'type'    => 'select',
234
							'options' => give_cmb2_get_post_options(
235
								array(
236
									'post_type'   => 'page',
237
									'numberposts' => 999,
0 ignored issues
show
introduced by
Detected high pagination limit, numberposts is set to 999
Loading history...
238
								)
239
							),
240
						),
241
						array(
242
							'name'    => __( 'Donation History Page', 'give' ),
243
							/* translators: %s: [donation_history] */
244
							'desc'    => sprintf( __( 'The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give' ), '<code>[donation_history]</code>' ),
245
							'id'      => 'history_page',
246
							'type'    => 'select',
247
							'options' => give_cmb2_get_post_options(
248
								array(
249
									'post_type'   => 'page',
250
									'numberposts' => 999,
0 ignored issues
show
introduced by
Detected high pagination limit, numberposts is set to 999
Loading history...
251
								)
252
							),
253
						),
254
						array(
255
							'name'    => __( 'Base Country', 'give' ),
256
							'desc'    => __( 'The country your site operates from.', 'give' ),
257
							'id'      => 'base_country',
258
							'type'    => 'select',
259
							'options' => give_get_country_list(),
260
						),
261
						array(
262
							'name' => __( 'Currency Settings', 'give' ),
263
							'desc' => '',
264
							'type' => 'give_title',
265
							'id'   => 'give_title_general_settings_2',
266
						),
267
						array(
268
							'name'    => __( 'Currency', 'give' ),
269
							'desc'    => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
270
							'id'      => 'currency',
271
							'type'    => 'select',
272
							'options' => give_get_currencies(),
273
							'default' => 'USD',
274
						),
275
						array(
276
							'name'    => __( 'Currency Position', 'give' ),
277
							'desc'    => __( 'The position of the currency symbol.', 'give' ),
278
							'id'      => 'currency_position',
279
							'type'    => 'select',
280
							'options' => array(
281
								/* translators: %s: currency symbol */
282
								'before' => sprintf( __( 'Before - %s&#x200e;10', 'give' ), give_currency_symbol( give_get_currency() ) ),
283
								/* translators: %s: currency symbol */
284
								'after'  => sprintf( __( 'After - 10%s&#x200f;', 'give' ), give_currency_symbol( give_get_currency() ) ),
285
							),
286
							'default' => 'before',
287
						),
288
						array(
289
							'name'            => __( 'Thousands Separator', 'give' ),
290
							'desc'            => __( 'The symbol (usually , or .) to separate thousands.', 'give' ),
291
							'id'              => 'thousands_separator',
292
							'type'            => 'text_small',
293
							'sanitization_cb' => 'give_sanitize_thousand_separator',
294
							'default'         => ',',
295
						),
296
						array(
297
							'name'    => __( 'Decimal Separator', 'give' ),
298
							'desc'    => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
299
							'id'      => 'decimal_separator',
300
							'type'    => 'text_small',
301
							'default' => '.',
302
						),
303
						array(
304
							'name'            => __( 'Number of Decimals', 'give' ),
305
							'desc'            => __( 'The number of decimal points displayed in amounts.', 'give' ),
306
							'id'              => 'number_decimals',
307
							'type'            => 'text_small',
308
							'default'         => 2,
309
							'sanitization_cb' => 'give_sanitize_number_decimals',
310
						),
311
					)
312
				),
313
			),
314
			/**
315
			 * Payment Gateways
316
			 */
317
			'gateways'    => array(
318
				'id'         => 'payment_gateways',
319
				'give_title' => __( 'Payment Gateways', 'give' ),
320
				'show_on'    => array(
321
					'key'   => 'options-page',
322
					'value' => array( $this->key ),
323
				),
324
				'fields'     => apply_filters(
325
					'give_settings_gateways', array(
326
						array(
327
							'name' => __( 'Gateways Settings', 'give' ),
328
							'desc' => '',
329
							'id'   => 'give_title_gateway_settings_1',
330
							'type' => 'give_title',
331
						),
332
						array(
333
							'name' => __( 'Test Mode', 'give' ),
334
							'desc' => __( 'While in test mode no live donations are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ),
335
							'id'   => 'test_mode',
336
							'type' => 'checkbox',
337
						),
338
						array(
339
							'name' => __( 'Enabled Gateways', 'give' ),
340
							'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
341
							'id'   => 'gateways',
342
							'type' => 'enabled_gateways',
343
						),
344
						array(
345
							'name' => __( 'Default Gateway', 'give' ),
346
							'desc' => __( 'The gateway that will be selected by default.', 'give' ),
347
							'id'   => 'default_gateway',
348
							'type' => 'default_gateway',
349
						),
350
						array(
351
							'name' => __( 'PayPal Standard', 'give' ),
352
							'desc' => '',
353
							'type' => 'give_title',
354
							'id'   => 'give_title_gateway_settings_2',
355
						),
356
						array(
357
							'name' => __( 'PayPal Email', 'give' ),
358
							'desc' => __( 'Enter your PayPal account\'s email.', 'give' ),
359
							'id'   => 'paypal_email',
360
							'type' => 'text_email',
361
						),
362
						array(
363
							'name' => __( 'PayPal Page Style', 'give' ),
364
							'desc' => __( 'Enter the name of the page style to use, or leave blank to use the default.', 'give' ),
365
							'id'   => 'paypal_page_style',
366
							'type' => 'text',
367
						),
368
						array(
369
							'name'    => __( 'PayPal Transaction Type', 'give' ),
370
							'desc'    => __( 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give' ),
371
							'id'      => 'paypal_button_type',
372
							'type'    => 'radio_inline',
373
							'options' => array(
374
								'donation' => __( 'Donation', 'give' ),
375
								'standard' => __( 'Standard Transaction', 'give' ),
376
							),
377
							'default' => 'donation',
378
						),
379
						array(
380
							'name' => __( 'Disable PayPal IPN Verification', 'give' ),
381
							'desc' => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
382
							'id'   => 'disable_paypal_verification',
383
							'type' => 'checkbox',
384
						),
385
						array(
386
							'name' => __( 'Offline Donations', 'give' ),
387
							'desc' => '',
388
							'type' => 'give_title',
389
							'id'   => 'give_title_gateway_settings_3',
390
						),
391
						array(
392
							'name' => __( 'Collect Billing Details', 'give' ),
393
							'desc' => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
394
							'id'   => 'give_offline_donation_enable_billing_fields',
395
							'type' => 'checkbox',
396
						),
397
						array(
398
							'name'    => __( 'Offline Donation Instructions', 'give' ),
399
							'desc'    => __( 'The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give' ),
400
							'id'      => 'global_offline_donation_content',
401
							'default' => give_get_default_offline_donation_content(),
402
							'type'    => 'wysiwyg',
403
							'options' => array(
404
								'textarea_rows' => 6,
405
							),
406
						),
407
						array(
408
							'name'    => __( 'Offline Donation Email Instructions Subject', 'give' ),
409
							'desc'    => __( 'Enter the subject line for the donation receipt email.', 'give' ),
410
							'id'      => 'offline_donation_subject',
411
							'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ),
412
							'type'    => 'text',
413
						),
414
						array(
415
							'name'    => __( 'Offline Donation Email Instructions', 'give' ),
416
							'desc'    => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
417
							'id'      => 'global_offline_donation_email',
418
							'default' => give_get_default_offline_donation_email_content(),
419
							'type'    => 'wysiwyg',
420
							'options' => array(
421
								'textarea_rows' => 6,
422
							),
423
						),
424
					)
425
				),
426
			),
427
			/** Display Settings */
428
			'display'     => array(
429
				'id'         => 'display_settings',
430
				'give_title' => __( 'Display Settings', 'give' ),
431
				'show_on'    => array(
432
					'key'   => 'options-page',
433
					'value' => array( $this->key ),
434
				),
435
				'fields'     => apply_filters(
436
					'give_settings_display', array(
437
						array(
438
							'name' => __( 'Display Settings', 'give' ),
439
							'desc' => '',
440
							'id'   => 'give_title_display_settings_1',
441
							'type' => 'give_title',
442
						),
443
						array(
444
							'name' => __( 'Disable CSS', 'give' ),
445
							'desc' => __( 'Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give' ),
446
							'id'   => 'disable_css',
447
							'type' => 'checkbox',
448
						),
449
						array(
450
							'name' => __( 'Enable Floating Labels', 'give' ),
451
							/* translators: %s: http://docs.givewp.com/form-floating-labels */
452
							'desc' => sprintf(
453
								wp_kses(
454
									__( 'Enable <a href="%s" target="_blank">floating labels</a> in Give\'s donation forms. Note that if the "Disable CSS" option is enabled, you will need to style the floating labels yourself.', 'give' ), array(
455
										'a' => array(
456
											'href'   => array(),
457
											'target' => array(),
458
										),
459
									)
460
								), esc_url( 'http://docs.givewp.com/form-floating-labels' )
461
							),
462
							'id'   => 'floatlabels',
463
							'type' => 'checkbox',
464
						),
465
						array(
466
							'name' => __( 'Disable Welcome Screen', 'give' ),
467
							/* translators: %s: about page URL */
468
							'desc' => sprintf(
469
								wp_kses(
470
									__( 'Enable this option if you would like to disable the <a href="%s" target="_blank">Give Welcome screen</a> every time Give is activated and/or updated.', 'give' ), array(
471
										'a' => array(
472
											'href'   => array(),
473
											'target' => array(),
474
										),
475
									)
476
								), esc_url( admin_url( 'index.php?page=give-about' ) )
477
							),
478
							'id'   => 'disable_welcome',
479
							'type' => 'checkbox',
480
						),
481
						array(
482
							'name' => __( 'Post Types', 'give' ),
483
							'desc' => '',
484
							'id'   => 'give_title_display_settings_2',
485
							'type' => 'give_title',
486
						),
487
						array(
488
							'name' => __( 'Disable Form Single Views', 'give' ),
489
							'desc' => __( 'By default, all forms have single views enabled which create a specific URL on your website for that form. This option disables the singular and archive views from being publicly viewable. Note: you will need to embed forms using a shortcode or widget if enabled.', 'give' ),
490
							'id'   => 'disable_forms_singular',
491
							'type' => 'checkbox',
492
						),
493
						array(
494
							'name' => __( 'Disable Form Archives', 'give' ),
495
							'desc' => __( 'Archives pages list all the forms you have created. This option will disable only the form\'s archive page(s). The single form\'s view will remain in place. Note: you will need to refresh your permalinks after this option has been enabled.', 'give' ),
496
							'id'   => 'disable_forms_archives',
497
							'type' => 'checkbox',
498
						),
499
						array(
500
							'name' => __( 'Disable Form Excerpts', 'give' ),
501
							'desc' => __( 'The excerpt is an optional summary or description of a donation form; in short, a summary as to why the user should give.', 'give' ),
502
							'id'   => 'disable_forms_excerpt',
503
							'type' => 'checkbox',
504
						),
505
						array(
506
							'name'    => __( 'Featured Image Size', 'give' ),
507
							'desc'    => __( 'The Featured Image is an image that is chosen as the representative image for a donation form. Some themes may have custom featured image sizes. Please select the size you would like to display for your single donation form\'s featured image.', 'give' ),
508
							'id'      => 'featured_image_size',
509
							'type'    => 'select',
510
							'default' => 'large',
511
							'options' => give_get_featured_image_sizes(),
512
						),
513
						array(
514
							'name' => __( 'Disable Form Featured Image', 'give' ),
515
							'desc' => __( 'If you do not wish to use the featured image functionality you can disable it using this option and it will not be displayed for single donation forms.', 'give' ),
516
							'id'   => 'disable_form_featured_img',
517
							'type' => 'checkbox',
518
						),
519
						array(
520
							'name' => __( 'Disable Single Form Sidebar', 'give' ),
521
							'desc' => __( 'The sidebar allows you to add additional widget to the Give single form view. If you don\'t plan on using the sidebar you may disable it with this option.', 'give' ),
522
							'id'   => 'disable_form_sidebar',
523
							'type' => 'checkbox',
524
						),
525
						array(
526
							'name' => __( 'Taxonomies', 'give' ),
527
							'desc' => '',
528
							'id'   => 'give_title_display_settings_3',
529
							'type' => 'give_title',
530
						),
531
						array(
532
							'name' => __( 'Enable Form Categories', 'give' ),
533
							'desc' => __( 'Enables the "Category" taxonomy for all Give forms.', 'give' ),
534
							'id'   => 'categories',
535
							'type' => 'checkbox',
536
						),
537
						array(
538
							'name' => __( 'Enable Form Tags', 'give' ),
539
							'desc' => __( 'Enables the "Tag" taxonomy for all Give forms.', 'give' ),
540
							'id'   => 'tags',
541
							'type' => 'checkbox',
542
						),
543
					)
544
				),
545
546
			),
547
			/**
548
			 * Emails Options
549
			 */
550
			'emails'      => array(
551
				'id'         => 'email_settings',
552
				'give_title' => __( 'Email Settings', 'give' ),
553
				'show_on'    => array(
554
					'key'   => 'options-page',
555
					'value' => array( $this->key ),
556
				),
557
				'fields'     => apply_filters(
558
					'give_settings_emails', array(
559
						array(
560
							'name' => __( 'Email Settings', 'give' ),
561
							'desc' => '',
562
							'id'   => 'give_title_email_settings_1',
563
							'type' => 'give_title',
564
						),
565
						array(
566
							'id'      => 'email_template',
567
							'name'    => __( 'Email Template', 'give' ),
568
							'desc'    => __( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
569
							'type'    => 'select',
570
							'options' => give_get_email_templates(),
571
						),
572
						array(
573
							'id'   => 'email_logo',
574
							'name' => __( 'Logo', 'give' ),
575
							'desc' => __( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
576
							'type' => 'file',
577
						),
578
						array(
579
							'id'      => 'from_name',
580
							'name'    => __( 'From Name', 'give' ),
581
							'desc'    => __( 'The name that appears in the "From" field in donation receipt emails.', 'give' ),
582
							'default' => get_bloginfo( 'name' ),
583
							'type'    => 'text',
584
						),
585
						array(
586
							'id'      => 'from_email',
587
							'name'    => __( 'From Email', 'give' ),
588
							'desc'    => __( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
589
							'default' => get_bloginfo( 'admin_email' ),
590
							'type'    => 'text',
591
						),
592
						array(
593
							'name' => __( 'Donation Receipt', 'give' ),
594
							'desc' => '',
595
							'id'   => 'give_title_email_settings_2',
596
							'type' => 'give_title',
597
						),
598
						array(
599
							'id'      => 'donation_subject',
600
							'name'    => __( 'Donation Email Subject', 'give' ),
601
							'desc'    => __( 'Enter the subject line for the donation receipt email.', 'give' ),
602
							'default' => esc_attr__( 'Donation Receipt', 'give' ),
603
							'type'    => 'text',
604
						),
605
						array(
606
							'id'      => 'donation_receipt',
607
							'name'    => __( 'Donation Receipt', 'give' ),
608
							'desc'    => sprintf(
609
								/* translators: %s: emails tags list */
610
								__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
611
								'<br/>' . give_get_emails_tags_list()
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_emails_tags_list'
Loading history...
612
							),
613
							'type'    => 'wysiwyg',
614
							'default' => give_get_default_donation_receipt_email(),
615
						),
616
						array(
617
							'name' => __( 'New Donation Notification', 'give' ),
618
							'desc' => '',
619
							'id'   => 'give_title_email_settings_3',
620
							'type' => 'give_title',
621
						),
622
						array(
623
							'id'      => 'donation_notification_subject',
624
							'name'    => __( 'Donation Notification Subject', 'give' ),
625
							'desc'    => __( 'Enter the subject line for the donation notification email.', 'give' ),
626
							'type'    => 'text',
627
							'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' ),
628
						),
629
						array(
630
							'id'      => 'donation_notification',
631
							'name'    => __( 'Donation Notification', 'give' ),
632
							'desc'    => sprintf(
633
								/* translators: %s: emails tags list */
634
								__( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags: %s', 'give' ),
635
								'<br/>' . give_get_emails_tags_list()
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_emails_tags_list'
Loading history...
636
							),
637
							'type'    => 'wysiwyg',
638
							'default' => give_get_default_donation_notification_email(),
639
						),
640
						array(
641
							'id'      => 'admin_notice_emails',
642
							'name'    => __( 'Donation Notification Emails', 'give' ),
643
							'desc'    => __( 'Enter the email address(es) that should receive a notification anytime a donation is made, please only enter <span class="give-underline">one email address per line</span> and <strong>not separated by commas</strong>.', 'give' ),
644
							'type'    => 'textarea',
645
							'default' => get_bloginfo( 'admin_email' ),
646
						),
647
						array(
648
							'id'   => 'disable_admin_notices',
649
							'name' => __( 'Disable Admin Notifications', 'give' ),
650
							'desc' => __( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
651
							'type' => 'checkbox',
652
						),
653
					)
654
				),
655
			),
656
			/** Extension Settings */
657
			'addons'      => array(
658
				'id'         => 'addons',
659
				'give_title' => __( 'Give Add-ons Settings', 'give' ),
660
				'show_on'    => array(
661
					'key'   => 'options-page',
662
					'value' => array( $this->key ),
663
				),
664
				'fields'     => apply_filters(
665
					'give_settings_addons', array()
666
				),
667
			),
668
			/** Licenses Settings */
669
			'licenses'    => array(
670
				'id'         => 'licenses',
671
				'give_title' => __( 'Give Licenses', 'give' ),
672
				'show_on'    => array(
673
					'key'   => 'options-page',
674
					'value' => array( $this->key ),
675
				),
676
				'fields'     => apply_filters(
677
					'give_settings_licenses', array()
678
				),
679
			),
680
			/** Advanced Options */
681
			'advanced'    => array(
682
				'id'         => 'advanced_options',
683
				'give_title' => __( 'Advanced Options', 'give' ),
684
				'show_on'    => array(
685
					'key'   => 'options-page',
686
					'value' => array( $this->key ),
687
				),
688
				'fields'     => apply_filters(
689
					'give_settings_advanced', array(
690
						array(
691
							'name' => __( 'Access Control', 'give' ),
692
							'desc' => '',
693
							'id'   => 'give_title_session_control_1',
694
							'type' => 'give_title',
695
						),
696
						array(
697
							'id'      => 'session_lifetime',
698
							'name'    => __( 'Session Lifetime', 'give' ),
699
							'desc'    => __( 'The length of time a user\'s session is kept alive. Give starts a new session per user upon donation. Sessions allow donors to view their donation receipts without being logged in.', 'give' ),
700
							'type'    => 'select',
701
							'options' => array(
702
								'86400'  => __( '24 Hours', 'give' ),
703
								'172800' => __( '48 Hours', 'give' ),
704
								'259200' => __( '72 Hours', 'give' ),
705
								'604800' => __( '1 Week', 'give' ),
706
							),
707
						),
708
						array(
709
							'name' => __( 'Email Access', 'give' ),
710
							'desc' => __( 'Would you like your donors to be able to access their donation history using only email? Donors whose sessions have expired and do not have an account may still access their donation history via a temporary email access link.', 'give' ),
711
							'id'   => 'email_access',
712
							'type' => 'checkbox',
713
						),
714
						array(
715
							'id'      => 'recaptcha_key',
716
							'name'    => __( 'reCAPTCHA Site Key', 'give' ),
717
							/* translators: %s: https://www.google.com/recaptcha/ */
718
							'desc'    => sprintf( __( 'If you would like to prevent spam on the email access form navigate to <a href="%s" target="_blank">the reCAPTCHA website</a> and sign up for an API key. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), esc_url( 'https://www.google.com/recaptcha/' ) ),
719
							'default' => '',
720
							'type'    => 'text',
721
						),
722
						array(
723
							'id'      => 'recaptcha_secret',
724
							'name'    => __( 'reCAPTCHA Secret Key', 'give' ),
725
							'desc'    => __( 'Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give' ),
726
							'default' => '',
727
							'type'    => 'text',
728
						),
729
						array(
730
							'name' => __( 'Data Control', 'give' ),
731
							'desc' => '',
732
							'id'   => 'give_title_data_control_2',
733
							'type' => 'give_title',
734
						),
735
						array(
736
							'name' => __( 'Remove All Data on Uninstall?', 'give' ),
737
							'desc' => __( 'When the plugin is deleted, completely remove all Give data.', 'give' ),
738
							'id'   => 'uninstall_on_delete',
739
							'type' => 'checkbox',
740
						),
741
						array(
742
							'name' => __( 'Filter Control', 'give' ),
743
							'desc' => '',
744
							'id'   => 'give_title_filter_control',
745
							'type' => 'give_title',
746
						),
747
						array(
748
							/* translators: %s: the_content */
749
							'name' => sprintf( __( 'Disable %s filter', 'give' ), '<code>the_content</code>' ),
750
							/* translators: 1: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content 2: the_content */
751
							'desc' => sprintf( __( 'If you are seeing extra social buttons, related posts, or other unwanted elements appearing within your forms then you can disable WordPress\' content filter. <a href="%1$s" target="_blank">Learn more</a> about %2$s filter.', 'give' ), esc_url( 'https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content' ), '<code>the_content</code>' ),
752
							'id'   => 'disable_the_content_filter',
753
							'type' => 'checkbox',
754
						),
755
						array(
756
							'name' => __( 'Script Loading', 'give' ),
757
							'desc' => '',
758
							'id'   => 'give_title_script_control',
759
							'type' => 'give_title',
760
						),
761
						array(
762
							'name' => __( 'Load Scripts in Footer?', 'give' ),
763
							'desc' => __( 'Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give' ),
764
							'id'   => 'scripts_footer',
765
							'type' => 'checkbox',
766
						),
767
					)
768
				),
769
			),
770
			/** API Settings */
771
			'api'         => array(
772
				'id'         => 'api',
773
				'give_title' => __( 'API', 'give' ),
774
				'show_on'    => array(
775
					'key'   => 'options-page',
776
					'value' => array( $this->key ),
777
				),
778
				'show_names' => false, // Hide field names on the left
779
				'fields'     => apply_filters(
780
					'give_settings_system', array(
781
						array(
782
							'id'   => 'api',
783
							'name' => __( 'API', 'give' ),
784
							'type' => 'api',
785
						),
786
					)
787
				),
788
			),
789
			/** Licenses Settings */
790
			'system_info' => array(
791
				'id'         => 'system_info',
792
				'give_title' => __( 'System Info', 'give' ),
793
				'show_on'    => array(
794
					'key'   => 'options-page',
795
					'value' => array( $this->key ),
796
				),
797
				'fields'     => apply_filters(
798
					'give_settings_system', array(
799
						array(
800
							'id'   => 'system-info-textarea',
801
							'name' => __( 'System Info', 'give' ),
802
							'desc' => __( 'Please copy and paste this information in your ticket when contacting support.', 'give' ),
803
							'type' => 'system_info',
804
						),
805
					)
806
				),
807
			),
808
		);
809
810
		$give_settings = apply_filters( 'give_registered_settings', $give_settings );
811
812
		// Return all settings array if no active tab
813
		if ( empty( $active_tab ) || ! isset( $give_settings[ $active_tab ] ) ) {
814
			return $give_settings;
815
		}
816
817
		// Add other tabs and settings fields as needed
818
		return $give_settings[ $active_tab ];
819
820
	}
821
822
	/**
823
	 * Show Settings Notices
824
	 */
825
	public function settings_notices() {
826
827
		if ( ! isset( $_POST['give_settings_saved'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
828
			return;
829
		}
830
831
		add_settings_error( 'give-notices', 'global-settings-updated', __( 'Settings updated.', 'give' ), 'updated' );
832
833
	}
834
835
836
	/**
837
	 * Public getter method for retrieving protected/private variables
838
	 *
839
	 * @since  1.0
840
	 *
841
	 * @param  string $field Field to retrieve
842
	 *
843
	 * @return mixed         Field value or exception is thrown.
844
	 * @throws Exception     Throws an exception if the field is invalid.
845
	 */
846
	public function __get( $field ) {
847
848
		// Allowed fields to retrieve
849
		if ( in_array( $field, array( 'key', 'fields', 'give_title', 'options_page' ), true ) ) {
850
			return $this->{$field};
851
		}
852
853
		throw new Exception( sprintf( __( 'Invalid property: %s', 'give' ), $field ) );
854
	}
855
856
857
}
858
859
// Get it started
860
$Give_Settings = new Give_Plugin_Settings();
861
862
/**
863
 * Helps get a single option from the give_get_settings() array.
864
 *
865
 * @since  0.1.0
866
 *
867
 * @param  string      $key     Options array key
868
 * @param  string|bool $default The default option if the option isn't set
869
 *
870
 * @return mixed        Option value
871
 */
872 View Code Duplication
function give_get_option( $key = '', $default = false ) {
0 ignored issues
show
Duplication introduced by
This function 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...
873
	$give_options = give_get_settings();
874
	$value        = ! empty( $give_options[ $key ] ) ? $give_options[ $key ] : $default;
875
	$value        = apply_filters( 'give_get_option', $value, $key, $default );
876
877
	return apply_filters( "give_get_option_{$key}", $value, $key, $default );
878
}
879
880
881
/**
882
 * Update an option
883
 *
884
 * Updates an give setting value in both the db and the global variable.
885
 * Warning: Passing in an empty, false or null string value will remove
886
 *          the key from the give_options array.
887
 *
888
 * @since 1.0
889
 *
890
 * @param string          $key   The Key to update
891
 * @param string|bool|int $value The value to set the key to
892
 *
893
 * @return boolean True if updated, false if not.
894
 */
895
function give_update_option( $key = '', $value = false ) {
896
897
	// If no key, exit
898
	if ( empty( $key ) ) {
899
		return false;
900
	}
901
902
	if ( empty( $value ) ) {
903
		$remove_option = give_delete_option( $key );
904
905
		return $remove_option;
906
	}
907
908
	// First let's grab the current settings
909
	$options = get_option( 'give_settings' );
910
911
	// Let's let devs alter that value coming in
912
	$value = apply_filters( 'give_update_option', $value, $key );
913
914
	// Next let's try to update the value
915
	$options[ $key ] = $value;
916
	$did_update      = update_option( 'give_settings', $options, false );
917
918
	// If it updated, let's update the global variable
919
	if ( $did_update ) {
920
		global $give_options;
921
		$give_options[ $key ] = $value;
922
	}
923
924
	return $did_update;
925
}
926
927
/**
928
 * Remove an option
929
 *
930
 * Removes an give setting value in both the db and the global variable.
931
 *
932
 * @since 1.0
933
 *
934
 * @global       $give_options
935
 *
936
 * @param string $key The Key to delete
937
 *
938
 * @return boolean True if updated, false if not.
939
 */
940
function give_delete_option( $key = '' ) {
941
942
	// If no key, exit
943
	if ( empty( $key ) ) {
944
		return false;
945
	}
946
947
	// First let's grab the current settings
948
	$options = get_option( 'give_settings' );
949
950
	// Next let's try to update the value
951
	if ( isset( $options[ $key ] ) ) {
952
		unset( $options[ $key ] );
953
	}
954
955
	$did_update = update_option( 'give_settings', $options, false );
956
957
	// If it updated, let's update the global variable
958
	if ( $did_update ) {
959
		global $give_options;
960
		$give_options = $options;
961
	}
962
963
	return $did_update;
964
}
965
966
967
/**
968
 * Get Settings
969
 *
970
 * Retrieves all Give plugin settings
971
 *
972
 * @since 1.0
973
 * @return array Give settings
974
 */
975
function give_get_settings() {
976
	$settings = Give_Cache_Setting::get_settings();
977
978
	return (array) apply_filters( 'give_get_settings', $settings );
979
980
}
981
982
983
/**
984
 * Give Settings Array Insert.
985
 *
986
 * Allows other Add-ons and plugins to insert Give settings at a desired position.
987
 *
988
 * @since      1.3.5
989
 *
990
 * @param $array
991
 * @param $position |int|string Expects an array key or 'id' of the settings field to appear after
992
 * @param $insert   |array a valid array of options to insert
993
 *
994
 * @return array
995
 */
996
function give_settings_array_insert( $array, $position, $insert ) {
997
	if ( is_int( $position ) ) {
998
		array_splice( $array, $position, 0, $insert );
999
	} else {
1000
1001
		foreach ( $array as $index => $subarray ) {
1002
			if ( isset( $subarray['id'] ) && $subarray['id'] == $position ) {
1003
				$pos = $index;
1004
			}
1005
		}
1006
1007
		if ( ! isset( $pos ) ) {
1008
			return $array;
1009
		}
1010
1011
		$array = array_merge(
1012
			array_slice( $array, 0, $pos ),
1013
			$insert,
1014
			array_slice( $array, $pos )
1015
		);
1016
	}
1017
1018
	return $array;
1019
}
1020
1021
1022
/**
1023
 * Gateways Callback
1024
 *
1025
 * Renders gateways fields.
1026
 *
1027
 * @since 1.0
1028
 *
1029
 * @param array $field_arr
1030
 * @param array $saved_values
1031
 *
1032
 * @return void
1033
 */
1034
function give_enabled_gateways_callback( $field_arr, $saved_values = array() ) {
1035
	$saved_values = __give_validate_active_gateways( $saved_values );
1036
	$id           = $field_arr['id'];
1037
	$gateways     = give_get_ordered_payment_gateways( give_get_payment_gateways() );
1038
1039
	echo '<ul class="give-checklist-fields give-payment-gatways-list">';
1040
1041
	foreach ( $gateways as $key => $option ) :
1042
1043
		if ( is_array( $saved_values ) && array_key_exists( $key, $saved_values ) ) {
1044
			$enabled = '1';
1045
		} else {
1046
			$enabled = null;
1047
		}
1048
1049
		echo '<li><span class="give-drag-handle"><span class="dashicons dashicons-menu"></span></span><input name="' . $id . '[' . $key . ']" id="' . $id . '[' . $key . ']" type="checkbox" value="1" ' . checked( '1', $enabled, false ) . '/>&nbsp;';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
1050
		echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$option'
Loading history...
1051
1052
	endforeach;
1053
1054
	echo '</ul>';
1055
}
1056
1057
/**
1058
 * Gateways Callback (drop down)
1059
 *
1060
 * Renders gateways select menu
1061
 *
1062
 * @since  1.0
1063
 *
1064
 * @param  array $field_arr
1065
 * @param  array $saved_value
1066
 *
1067
 * @return void
1068
 */
1069
function give_default_gateway_callback( $field_arr, $saved_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $saved_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1070
	$id          = $field_arr['id'];
1071
	$gateways    = give_get_enabled_payment_gateways();
1072
	$saved_value = give_get_default_gateway( null );
1073
1074
	echo '<select class="give-select" name="' . $id . '" id="' . $id . '">';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
1075
1076
	foreach ( $gateways as $key => $option ) :
1077
		$selected = isset( $saved_value ) ? selected( $key, $saved_value, false ) : '';
1078
		echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$selected'
Loading history...
1079
	endforeach;
1080
1081
	echo '</select>';
1082
1083
}
1084
1085
/**
1086
 * Give Title
1087
 *
1088
 * Renders custom section titles output; Really only an  because CMB2's output is a bit funky
1089
 *
1090
 * @since 1.0
1091
 *
1092
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1093
 *
1094
 * @return void
1095
 */
1096 View Code Duplication
function give_title_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $escaped_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function 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...
1097
1098
	$id                = $field_type_object->field->args['id'];
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1099
	$title             = $field_type_object->field->args['name'];
0 ignored issues
show
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1100
	$field_description = $field_type_object->field->args['desc'];
1101
1102
	echo '<hr>' . $field_description;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field_description'
Loading history...
1103
1104
}
1105
1106
/**
1107
 * Give Description
1108
 *
1109
 * Renders custom description text which any plugin can use to output content, html, php, etc.
1110
 *
1111
 * @since      1.3.5
1112
 *
1113
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1114
 *
1115
 * @return void
1116
 */
1117 View Code Duplication
function give_description_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $escaped_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function 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...
1118
1119
	$id                = $field_type_object->field->args['id'];
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1120
	$title             = $field_type_object->field->args['name'];
0 ignored issues
show
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1121
	$field_description = $field_type_object->field->args['desc'];
1122
1123
	echo $field_description;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field_description'
Loading history...
1124
1125
}
1126
1127
/**
1128
 * Gets a number of posts and displays them as options
1129
 *
1130
 * @param  array $query_args Optional. Overrides defaults.
1131
 * @param  bool  $force      Force the pages to be loaded even if not on settings
1132
 *
1133
 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
1134
 * @return array An array of options that matches the CMB2 options array
1135
 */
1136
function give_cmb2_get_post_options( $query_args, $force = false ) {
1137
1138
	$post_options = array( '' => '' ); // Blank option
1139
1140
	if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
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...
1141
		return $post_options;
1142
	}
1143
1144
	$args = wp_parse_args(
1145
		$query_args, array(
1146
			'post_type'   => 'page',
1147
			'numberposts' => 10,
1148
		)
1149
	);
1150
1151
	$posts = get_posts( $args );
1152
1153
	if ( $posts ) {
1154
		foreach ( $posts as $post ) {
1155
1156
			$post_options[ $post->ID ] = $post->post_title;
1157
1158
		}
1159
	}
1160
1161
	return $post_options;
1162
}
1163
1164
1165
/**
1166
 * Featured Image Sizes
1167
 *
1168
 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
1169
 *
1170
 * @since 1.4
1171
 *
1172
 * @global $_wp_additional_image_sizes
1173
 *
1174
 * @return array $sizes
1175
 */
1176
function give_get_featured_image_sizes() {
1177
	global $_wp_additional_image_sizes;
1178
1179
	$sizes            = array();
1180
	$get_sizes        = get_intermediate_image_sizes();
1181
	$core_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
1182
1183
	// This will help us to filter special characters from a string
1184
	$filter_slug_items = array( '_', '-' );
1185
1186
	foreach ( $get_sizes as $_size ) {
1187
1188
		// Converting image size slug to title case
1189
		$sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
1190
1191
		if ( in_array( $_size, $core_image_sizes ) ) {
1192
			$sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
1193
		} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1194
			$sizes[ $_size ] .= " ({$_wp_additional_image_sizes[ $_size ]['width']} x {$_wp_additional_image_sizes[ $_size ]['height']}";
1195
		}
1196
1197
		// Based on the above image height check, label the respective resolution as responsive
1198
		if ( ( array_key_exists( $_size, $_wp_additional_image_sizes ) && ! $_wp_additional_image_sizes[ $_size ]['crop'] ) || ( in_array( $_size, $core_image_sizes ) && ! get_option( "{$_size}_crop" ) ) ) {
1199
			$sizes[ $_size ] .= ' - responsive';
1200
		}
1201
1202
		$sizes[ $_size ] .= ')';
1203
1204
	}
1205
1206
	return apply_filters( 'give_get_featured_image_sizes', $sizes );
1207
}
1208
1209
1210
/**
1211
 *  Slug to Title
1212
 *
1213
 *  Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
1214
 *
1215
 * @since 1.8.8
1216
 *
1217
 * @params $string text
1218
 * @params $filter array
1219
 *
1220
 * @return text $string
1221
 */
1222
function give_slug_to_title( $string, $filters = array() ) {
1223
1224
	foreach ( $filters as $filter_item ) {
1225
		$string = str_replace( $filter_item, ' ', $string );
1226
	}
1227
1228
	// Return updated string after converting it to title case
1229
	return ucwords( $string );
1230
1231
}
1232
1233
1234
/**
1235
 * Give License Key Callback
1236
 *
1237
 * Registers the license field callback for EDD's Software Licensing.
1238
 *
1239
 * @since       1.0
1240
 *
1241
 * @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1242
 *
1243
 * @return void
1244
 */
1245
function give_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1246
	/* @var CMB2_Types $field_type_object */
1247
1248
	$id                 = $field_type_object->field->args['id'];
1249
	$field_description  = $field_type_object->field->args['desc'];
1250
	$license            = $field_type_object->field->args['options']['license'];
1251
	$license_key        = $escaped_value;
1252
	$is_license_key     = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1253
	$is_valid_license   = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1254
	$shortname          = $field_type_object->field->args['options']['shortname'];
1255
	$field_classes      = 'regular-text give-license-field';
1256
	$type               = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1257
	$custom_html        = '';
1258
	$messages           = array();
1259
	$class              = '';
0 ignored issues
show
Unused Code introduced by
$class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1260
	$account_page_link  = $field_type_object->field->args['options']['account_url'];
1261
	$checkout_page_link = $field_type_object->field->args['options']['checkout_url'];
1262
	$addon_name         = $field_type_object->field->args['options']['item_name'];
1263
	$license_status     = null;
0 ignored issues
show
Unused Code introduced by
$license_status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1264
	$is_in_subscription = null;
1265
1266
	// By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1267
	// To combat that check if status is set to error or not, if yes then set $is_license_key to false.
1268
	if ( $is_license_key && property_exists( $license, 'status' ) && 'error' === $license->status ) {
1269
		$is_license_key = false;
1270
	}
1271
1272
	// Check if current license is part of subscription or not.
1273
	$subscriptions = get_option( 'give_subscriptions' );
1274
1275
	if ( $is_license_key && $subscriptions ) {
1276
		foreach ( $subscriptions as $subscription ) {
1277
			if ( in_array( $license_key, $subscription['licenses'] ) ) {
1278
				$is_in_subscription = $subscription['id'];
1279
				break;
1280
			}
1281
		}
1282
	}
1283
1284
	if ( $is_license_key ) {
1285
1286
		if ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1287
1288
			// activate_license 'invalid' on anything other than valid, so if there was an error capture it
1289
			switch ( $license->error ) {
1290
				case 'expired':
1291
					$class          = $license->error;
1292
					$messages[]     = sprintf(
1293
						__( 'Your license key expired on %1$s. Please <a href="%2$s" target="_blank" title="Renew your license key">renew your license key</a>.', 'give' ),
1294
						date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1295
						$checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$license_key'
Loading history...
1296
					);
1297
					$license_status = 'license-' . $class;
1298
					break;
1299
1300 View Code Duplication
				case 'missing':
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...
1301
					$class          = $license->error;
1302
					$messages[]     = sprintf(
1303
						__( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1304
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1305
					);
1306
					$license_status = 'license-' . $class;
1307
					break;
1308
1309 View Code Duplication
				case 'invalid':
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...
1310
					$class          = $license->error;
1311
					$messages[]     = sprintf(
1312
						__( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1313
						$addon_name,
1314
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1315
					);
1316
					$license_status = 'license-' . $class;
1317
					break;
1318
1319 View Code Duplication
				case 'site_inactive':
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...
1320
					$class          = $license->error;
1321
					$messages[]     = sprintf(
1322
						__( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1323
						$addon_name,
1324
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1325
					);
1326
					$license_status = 'license-' . $class;
1327
					break;
1328
1329 View Code Duplication
				case 'item_name_mismatch':
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...
1330
					$class          = $license->error;
1331
					$messages[]     = sprintf( __( 'This license %1$s does not belong to %2$s.', 'give' ), $license_key, $addon_name );
1332
					$license_status = 'license-' . $class;
1333
					break;
1334
1335 View Code Duplication
				case 'no_activations_left':
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...
1336
					$class          = $license->error;
1337
					$messages[]     = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1338
					$license_status = 'license-' . $class;
1339
					break;
1340
1341 View Code Duplication
				default:
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...
1342
					$class          = $license->error;
0 ignored issues
show
Unused Code introduced by
$class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1343
					$messages[]     = sprintf(
1344
						__( 'Your license is not activated. Please <a href="%3$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs. %2$sError Code: %1$s.', 'give' ),
1345
						$license->error,
1346
						'<br/>',
1347
						"{$account_page_link}?utm_campaign=admin&utm_source=licenses&utm_medium={$license->error}"
1348
					);
1349
					$license_status = 'license-error';
1350
					break;
1351
			}
1352
		} elseif ( $is_in_subscription ) {
1353
1354
			$subscription_expires = strtotime( $subscriptions[ $is_in_subscription ]['expires'] );
1355
			$subscription_status  = __( 'renew', 'give' );
1356
1357
			if ( ( 'active' !== $subscriptions[ $is_in_subscription ]['status'] ) ) {
1358
				$subscription_status = __( 'expire', 'give' );
1359
			}
1360
1361
			if ( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1362
				$messages[]     = sprintf(
1363
					__( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) expired. Please <a href="%3$s" target="_blank" title="Renew your license key">renew your license key</a>', 'give' ),
1364
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1365
					$subscriptions[ $is_in_subscription ]['payment_id'],
1366
					$checkout_page_link . '?edd_license_key=' . $subscriptions[ $is_in_subscription ]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$subscriptions'
Loading history...
1367
				);
1368
				$license_status = 'license-expired';
1369
			} elseif ( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1370
				$messages[]     = sprintf(
1371
					__( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s in %4$s.', 'give' ),
1372
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1373
					$subscriptions[ $is_in_subscription ]['payment_id'],
1374
					$subscription_status,
1375
					human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[ $is_in_subscription ]['expires'] ) )
1376
				);
1377
				$license_status = 'license-expires-soon';
1378
			} else {
1379
				$messages[]     = sprintf(
1380
					__( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s on %4$s.', 'give' ),
1381
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1382
					$subscriptions[ $is_in_subscription ]['payment_id'],
1383
					$subscription_status,
1384
					date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[ $is_in_subscription ]['expires'], current_time( 'timestamp' ) ) )
1385
				);
1386
				$license_status = 'license-expiration-date';
1387
			}
1388
		} elseif ( empty( $license->success ) ) {
1389
			$class          = 'invalid';
1390
			$messages[]     = sprintf(
1391
				__( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'give' ),
1392
				$addon_name,
1393
				$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1394
			);
1395
			$license_status = 'license-' . $class;
1396
1397
		} else {
1398
			switch ( $license->license ) {
1399
				case 'valid':
1400
				default:
1401
					$class      = 'valid';
0 ignored issues
show
Unused Code introduced by
$class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1402
					$now        = current_time( 'timestamp' );
1403
					$expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1404
1405
					if ( 'lifetime' === $license->expires ) {
1406
						$messages[]     = __( 'License key never expires.', 'give' );
1407
						$license_status = 'license-lifetime-notice';
1408
					} elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1409
						$messages[]     = sprintf(
1410
							__( 'Your license key expires soon! It expires on %1$s. <a href="%2$s" target="_blank" title="Renew license">Renew your license key</a>.', 'give' ),
1411
							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1412
							$checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$license_key'
Loading history...
1413
						);
1414
						$license_status = 'license-expires-soon';
1415
					} else {
1416
						$messages[]     = sprintf(
1417
							__( 'Your license key expires on %s.', 'give' ),
1418
							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1419
						);
1420
						$license_status = 'license-expiration-date';
1421
					}
1422
					break;
1423
			}
1424
		}
1425
	} else {
1426
		$messages[]     = sprintf(
1427
			__( 'To receive updates, please enter your valid %s license key.', 'give' ),
1428
			$addon_name
1429
		);
1430
		$license_status = 'inactive';
1431
	}
1432
1433
	// Add class for input field if license is active.
1434
	if ( $is_valid_license ) {
1435
		$field_classes .= ' give-license-active';
1436
	}
1437
1438
	// Get input field html.
1439
	$input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\">";
1440
1441
	// If license is active so show deactivate button.
1442
	if ( $is_valid_license ) {
1443
		// Get input field html.
1444
		$input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\" readonly=\"readonly\">";
1445
1446
		$custom_html = '<input type="submit" class="button button-small give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1447
1448
	}
1449
1450
	// Field description.
1451
	$custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1452
1453
	// If no messages found then inform user that to get updated in future register yourself.
1454
	if ( empty( $messages ) ) {
1455
		$messages[] = apply_filters( "{$shortname}_default_addon_notice", __( 'To receive updates, please enter your valid license key.', 'give' ) );
1456
	}
1457
1458
	foreach ( $messages as $message ) {
1459
		$custom_html .= '<div class="give-license-status-notice give-' . $license_status . '">';
1460
		$custom_html .= '<p>' . $message . '</p>';
1461
		$custom_html .= '</div>';
1462
	}
1463
1464
	// Field html.
1465
	$custom_html = apply_filters( 'give_license_key_field_html', $input_field_html . $custom_html, $field_type_object );
1466
1467
	// Nonce.
1468
	wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1469
1470
	// Print field html.
1471
	echo "<div class=\"give-license-key\"><label for=\"{$id}\">{$addon_name }</label></div><div class=\"give-license-block\">{$custom_html}</div>";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"<div class=\"give-license-key\"><label for=\"{$id}\">{$addon_name }</label></div><div class=\"give-license-block\">{$custom_html}</div>"'
Loading history...
1472
}
1473
1474
1475
/**
1476
 * Display the API Keys
1477
 *
1478
 * @since       1.0
1479
 * @return      void
1480
 */
1481
function give_api_callback() {
1482
1483
	if ( ! current_user_can( 'manage_give_settings' ) ) {
1484
		return;
1485
	}
1486
1487
	/**
1488
	 * Fires before displaying API keys.
1489
	 *
1490
	 * @since 1.0
1491
	 */
1492
	do_action( 'give_tools_api_keys_before' );
1493
1494
	require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
1495
1496
	$api_keys_table = new Give_API_Keys_Table();
1497
	$api_keys_table->prepare_items();
1498
	$api_keys_table->display();
1499
	?>
1500
	<span class="cmb2-metabox-description api-description">
1501
		<?php
1502
		echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
1503
			/* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
1504
			__( 'You can create API keys for individual users within their profile edit screen. API keys allow users to use the <a href="%1$s" target="_blank">Give REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%2$s" target="_blank">Zapier</a>.', 'give' ),
1505
			esc_url( 'http://docs.givewp.com/api' ),
1506
			esc_url( 'http://docs.givewp.com/addon-zapier' )
1507
		);
1508
		?>
1509
	</span>
1510
	<?php
1511
1512
	/**
1513
	 * Fires after displaying API keys.
1514
	 *
1515
	 * @since 1.0
1516
	 */
1517
	do_action( 'give_tools_api_keys_after' );
1518
}
1519
1520
add_action( 'give_settings_tab_api_keys', 'give_api_callback' );
1521
1522
/**
1523
 * Hook Callback
1524
 *
1525
 * Adds a do_action() hook in place of the field.
1526
 *
1527
 * @since 1.0
1528
 *
1529
 * @param array $args Arguments passed by the setting
1530
 *
1531
 * @return void
1532
 */
1533
function give_hook_callback( $args ) {
1534
1535
	$id = $args['id'];
1536
1537
	/**
1538
	 * Fires in give field.
1539
	 *
1540
	 * @since 1.0
1541
	 */
1542
	do_action( "give_{$id}" );
1543
1544
}
1545
1546
1547
/**
1548
 * Check if radio(enabled/disabled) and checkbox(on) is active or not.
1549
 *
1550
 * @since  1.8
1551
 *
1552
 * @param  mixed  $value
1553
 * @param  string $compare_with
1554
 *
1555
 * @return bool
1556
 */
1557
function give_is_setting_enabled( $value, $compare_with = null ) {
1558
	if ( ! is_null( $compare_with ) ) {
1559
1560
		if ( is_array( $compare_with ) ) {
1561
			// Output.
1562
			return in_array( $value, $compare_with );
1563
		}
1564
1565
		// Output.
1566
		return ( $value === $compare_with );
1567
	}
1568
1569
	// Backward compatibility: From version 1.8 most of setting is modified to enabled/disabled
1570
	// Output.
1571
	return ( in_array( $value, array( 'enabled', 'on', 'yes' ) ) ? true : false );
1572
}
1573