Completed
Pull Request — master (#664)
by Devin
19:01
created

Give_Plugin_Settings::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 1 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 8
b 1
f 0
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 826.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 *
5
 * Register Settings
6
 *
7
 * Include and setup custom metaboxes and fields.
8
 *
9
 * @package    Give
10
 * @subpackage Admin
11
 * @license    http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
12
 * @link       https://github.com/webdevstudios/Custom-Metaboxes-and-Fields-for-WordPress
13
 */
14
class Give_Plugin_Settings {
15
16
	/**
17
	 * Option key, and option page slug
18
	 * @var string
19
	 */
20
	private $key = 'give_settings';
21
22
	/**
23
	 * Array of metaboxes/fields
24
	 * @var array
25
	 */
26
	protected $option_metabox = array();
27
28
	/**
29
	 * Array of active tabs
30
	 * @var array
31
	 */
32
	protected $registered_tabs = array();
33
34
	/**
35
	 * Options Page title
36
	 * @var string
37
	 */
38
	protected $title = '';
39
40
	/**
41
	 * Options Page hook
42
	 * @var string
43
	 */
44
	protected $options_page = '';
45
46
	/**
47
	 * Constructor
48
	 * @since 1.0
49
	 */
50
	public function __construct() {
51
52
		add_action( 'admin_init', array( $this, 'init' ) );
53
54
		//Customize CMB2 URL
55
		add_filter( 'cmb2_meta_box_url', array( $this, 'give_update_cmb_meta_box_url' ) );
56
57
		//Custom CMB2 Settings Fields
58
		add_action( 'cmb2_render_give_title', 'give_title_callback', 10, 5 );
59
		add_action( 'cmb2_render_give_description', 'give_description_callback', 10, 5 );
60
		add_action( 'cmb2_render_enabled_gateways', 'give_enabled_gateways_callback', 10, 5 );
61
		add_action( 'cmb2_render_default_gateway', 'give_default_gateway_callback', 10, 5 );
62
		add_action( 'cmb2_render_email_preview_buttons', 'give_email_preview_buttons_callback', 10, 5 );
63
		add_action( 'cmb2_render_system_info', 'give_system_info_callback', 10, 5 );
64
		add_action( 'cmb2_render_api', 'give_api_callback', 10, 5 );
65
		add_action( 'cmb2_render_license_key', 'give_license_key_callback', 10, 5 );
66
		add_action( 'admin_notices', array( $this, 'settings_notices' ) );
67
68
		// Include CMB CSS in the head to avoid FOUC
69
		add_action( 'admin_print_styles-give_forms_page_give-settings', array( 'CMB2_hookup', 'enqueue_cmb_css' ) );
70
71
		add_filter( 'cmb2_get_metabox_form_format', array( $this, 'give_modify_cmb2_form_output' ), 10, 3 );
72
73
	}
74
75
76
	/**
77
	 * Register our setting to WP
78
	 * @since  1.0
79
	 */
80
	public function init() {
81
		register_setting( $this->key, $this->key );
82
83
	}
84
85
86
	/**
87
	 * Filter CMB2 URL
88
	 *
89
	 * @description: Required for CMB2 to properly load CSS/JS
90
	 *
91
	 * @param $url
92
	 *
93
	 * @return mixed
94
	 */
95
	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...
96
		//Path to Give's CMB
97
		return GIVE_PLUGIN_URL . '/includes/libraries/cmb2';
98
	}
99
100
101
	/**
102
	 * Retrieve settings tabs
103
	 *
104
	 * @since 1.0
105
	 * @return array $tabs
106
	 */
107
	public function give_get_settings_tabs() {
108
109
		$settings = $this->give_settings( null );
110
111
		$tabs             = array();
112
		$tabs['general']  = __( 'General', 'give' );
113
		$tabs['gateways'] = __( 'Payment Gateways', 'give' );
114
		$tabs['display']  = __( 'Display Options', 'give' );
115
		$tabs['emails']   = __( 'Emails', 'give' );
116
117
		if ( ! empty( $settings['addons']['fields'] ) ) {
118
			$tabs['addons'] = __( 'Add-ons', 'give' );
119
		}
120
121
		if ( ! empty( $settings['licenses']['fields'] ) ) {
122
			$tabs['licenses'] = __( 'Licenses', 'give' );
123
		}
124
125
		$tabs['advanced']    = __( 'Advanced', 'give' );
126
		$tabs['api']         = __( 'API', 'give' );
127
		$tabs['system_info'] = __( 'System Info', 'give' );
128
129
		return apply_filters( 'give_settings_tabs', $tabs );
130
	}
131
132
133
	/**
134
	 * Admin page markup. Mostly handled by CMB2
135
	 * @since  1.0
136
	 */
137
	public function admin_page_display() {
138
139
		$active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->give_get_settings_tabs() ) ? $_GET['tab'] : 'general';
140
141
		?>
142
143
		<div class="wrap give_settings_page cmb2_options_page <?php echo $this->key; ?>">
144
145
			<h1 class="nav-tab-wrapper">
146
				<?php
147
				foreach ( $this->give_get_settings_tabs() as $tab_id => $tab_name ) {
148
149
					//Support legacy tab creation conditions based off $_GET parameter
150
					//We pass the $_GET['tab'] to conditions executed later
151
					$_GET['tab'] = $tab_id;
152
153
					$tab_url = esc_url( add_query_arg( array(
154
						'settings-updated' => false,
155
						'tab'              => $tab_id
156
					) ) );
157
158
					$active       = $active_tab == $tab_id ? ' nav-tab-active' : '';
159
160
					echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '" id="tab-' . $tab_id . '">' . esc_html( $tab_name ) . '</a>';
161
162
				}
163
				?>
164
			</h1>
165
166
			<?php
167
			//Loop through and output settings
168
			foreach ( $this->give_get_settings_tabs() as $tab_id => $tab_name ) {
169
170
				//Support legacy tab creation conditions based off $_GET parameter
171
				//We 'trick' the conditions into thinking this is the tab
172
				$_GET['tab'] = $tab_id;
173
174
				$tab_settings = $this->give_settings( $tab_id );
175
176
				//Pass active tab within $tab_settings so we can hide with CSS via PHP
177
				if ( $active_tab == $tab_id ) {
178
					$tab_settings['active_tab'] = true;
179
				}
180
181
				cmb2_metabox_form( $tab_settings, $this->key );
182
183
			} ?>
184
185
		</div><!-- .wrap -->
186
187
		<?php
188
	}
189
190
191
	/**
192
	 * Modify CMB2 Default Form Output
193
	 *
194
	 * @param string @args
195
	 *
196
	 * @since 1.5 Modified to CSS hide non-active tabs
197
	 * @since 1.0
198
	 */
199
	function give_modify_cmb2_form_output( $form_format, $object_id, $cmb ) {
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...
200
201
202
		$pagenow = isset( $_GET['page'] ) ? $_GET['page'] : '';
203
204
		//only modify the give settings form
205
		if ( 'give_settings' == $object_id && $pagenow == 'give-settings' ) {
206
207
			$style = '';
208
			if ( ! isset( $cmb->meta_box['active_tab'] ) ) {
209
				$style = 'style="display:none;"';
210
			}
211
212
			//Set ID based off tab name - protects backwards compatibility
213
			$tab_id = isset( $_GET['tab'] ) ? $_GET['tab'] : $cmb->meta_box['id'];
214
215
			$save_button = apply_filters( 'give_save_button_markup', '<div class="give-submit-wrap"><input type="submit" name="submit-cmb" value="' . __( 'Save Settings', 'give' ) . '" class="button-primary"></div>' );
216
217
			//Filter so some tabs won't have save settings
218
			$no_save_button = apply_filters( 'give_settings_no_save_output', array(
219
				'system_info'
220
			) );
221
222
			if ( in_array( $tab_id, $no_save_button ) ) {
223
				$save_button = '';
224
			}
225
226
			$form_format = '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data" ' . $style . ' data-tab="' . $tab_id . '"><input type="hidden" name="give_settings_saved" value="true"><input type="hidden" name="object_id" value="%2$s">%3$s' . $save_button . '</form>';
227
228
		}
229
230
		return $form_format;
231
232
	}
233
234
	/**
235
	 * Define General Settings Metabox and field configurations.
236
	 *
237
	 * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
238
	 *
239
	 * @param $active_tab |string active tab settings; null returns full array
240
	 *
241
	 * @return array
242
	 */
243
	public function give_settings( $active_tab ) {
244
245
		$give_settings = array(
246
			/**
247
			 * General Settings
248
			 */
249
			'general'     => array(
250
				'id'         => 'general_settings',
251
				'give_title' => __( 'General Settings', 'give' ),
252
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
253
				'fields'     => apply_filters( 'give_settings_general', array(
254
						array(
255
							'name' => __( 'General Settings', 'give' ),
256
							'desc' => '',
257
							'type' => 'give_title',
258
							'id'   => 'give_title_general_settings_1'
259
						),
260
						array(
261
							'name'    => __( 'Success Page', 'give' ),
262
							'desc'    => sprintf( __( 'This is the page donors are sent to after completing their donations. The %1$s[give_receipt]%2$s shortcode should be on this page.', 'give' ), '<code>', '</code>' ),
263
							'id'      => 'success_page',
264
							'type'    => 'select',
265
							'options' => give_cmb2_get_post_options( array(
266
								'post_type'   => 'page',
267
								'numberposts' => - 1
268
							) ),
269
						),
270
						array(
271
							'name'    => __( 'Failed Transaction Page', 'give' ),
272
							'desc'    => __( 'This is the page donors are sent to if their transaction is cancelled or fails.', 'give' ),
273
							'id'      => 'failure_page',
274
							'type'    => 'select',
275
							'options' => give_cmb2_get_post_options( array(
276
								'post_type'   => 'page',
277
								'numberposts' => - 1
278
							) ),
279
						),
280
						array(
281
							'name'    => __( 'Donation History Page', 'give' ),
282
							'desc'    => sprintf( __( 'This page shows a complete donation history for the current user. The %1$s[donation_history]%2$s shortcode should be on this page.', 'give' ), '<code>', '</code>' ),
283
							'id'      => 'history_page',
284
							'type'    => 'select',
285
							'options' => give_cmb2_get_post_options( array(
286
								'post_type'   => 'page',
287
								'numberposts' => - 1
288
							) ),
289
						),
290
						array(
291
							'name'    => __( 'Base Country', 'give' ),
292
							'desc'    => __( 'Where does your site operate from?', 'give' ),
293
							'id'      => 'base_country',
294
							'type'    => 'select',
295
							'options' => give_get_country_list(),
296
						),
297
						array(
298
							'name' => __( 'Currency Settings', 'give' ),
299
							'desc' => '',
300
							'type' => 'give_title',
301
							'id'   => 'give_title_general_settings_2'
302
						),
303
						array(
304
							'name'    => __( 'Currency', 'give' ),
305
							'desc'    => 'Choose your currency. Note that some payment gateways have currency restrictions.',
306
							'id'      => 'currency',
307
							'type'    => 'select',
308
							'options' => give_get_currencies(),
309
							'default' => 'USD',
310
						),
311
						array(
312
							'name'    => __( 'Currency Position', 'give' ),
313
							'desc'    => 'Choose the position of the currency sign.',
314
							'id'      => 'currency_position',
315
							'type'    => 'select',
316
							'options' => array(
317
								'before' => sprintf( __( 'Before - %1$s10', 'give' ), give_currency_symbol( give_get_currency() ) ),
318
								'after'  => sprintf( __( 'After - 10%1$s', 'give' ), give_currency_symbol( give_get_currency() ) )
319
							),
320
							'default' => 'before',
321
						),
322
						array(
323
							'name'    => __( 'Thousands Separator', 'give' ),
324
							'desc'    => __( 'The symbol (typically , or .) to separate thousands', 'give' ),
325
							'id'      => 'thousands_separator',
326
							'type'    => 'text_small',
327
							'default' => ',',
328
						),
329
						array(
330
							'name'    => __( 'Decimal Separator', 'give' ),
331
							'desc'    => __( 'The symbol (usually , or .) to separate decimal points', 'give' ),
332
							'id'      => 'decimal_separator',
333
							'type'    => 'text_small',
334
							'default' => '.',
335
						),
336
					)
337
				)
338
			),
339
			/**
340
			 * Payment Gateways
341
			 */
342
			'gateways'    => array(
343
				'id'         => 'payment_gateways',
344
				'give_title' => __( 'Payment Gateways', 'give' ),
345
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
346
				'fields'     => apply_filters( 'give_settings_gateways', array(
347
						array(
348
							'name' => __( 'Gateways Settings', 'give' ),
349
							'desc' => '',
350
							'id'   => 'give_title_gateway_settings_1',
351
							'type' => 'give_title'
352
						),
353
						array(
354
							'name' => __( 'Test Mode', 'give' ),
355
							'desc' => __( 'While in test mode no live transactions are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ),
356
							'id'   => 'test_mode',
357
							'type' => 'checkbox'
358
						),
359
						array(
360
							'name' => __( 'Enabled Gateways', 'give' ),
361
							'desc' => __( 'Choose the payment gateways you would like enabled.', 'give' ),
362
							'id'   => 'gateways',
363
							'type' => 'enabled_gateways'
364
						),
365
						array(
366
							'name' => __( 'Default Gateway', 'give' ),
367
							'desc' => __( 'This is the gateway that will be selected by default.', 'give' ),
368
							'id'   => 'default_gateway',
369
							'type' => 'default_gateway'
370
						),
371
						array(
372
							'name' => __( 'PayPal Standard', 'give' ),
373
							'desc' => '',
374
							'type' => 'give_title',
375
							'id'   => 'give_title_gateway_settings_2',
376
						),
377
						array(
378
							'name' => __( 'PayPal Email', 'give' ),
379
							'desc' => __( 'Enter your PayPal account\'s email', 'give' ),
380
							'id'   => 'paypal_email',
381
							'type' => 'text_email',
382
						),
383
						array(
384
							'name' => __( 'PayPal Page Style', 'give' ),
385
							'desc' => __( 'Enter the name of the page style to use, or leave blank to use the default', 'give' ),
386
							'id'   => 'paypal_page_style',
387
							'type' => 'text',
388
						),
389
						array(
390
							'name'    => __( 'PayPal Transaction Type', 'give' ),
391
							'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' ),
392
							'id'      => 'paypal_button_type',
393
							'type'    => 'radio_inline',
394
							'options' => array(
395
								'donation' => __( 'Donation', 'give' ),
396
								'standard' => __( 'Standard Transaction', 'give' )
397
							),
398
							'default' => 'donation',
399
						),
400
						array(
401
							'name' => __( 'Disable PayPal IPN Verification', 'give' ),
402
							'desc' => __( 'If donations are not getting marked as complete, then check this box. This forces the site to use a slightly less secure method of verifying donations.', 'give' ),
403
							'id'   => 'disable_paypal_verification',
404
							'type' => 'checkbox'
405
						),
406
						array(
407
							'name' => __( 'Offline Donations', 'give' ),
408
							'desc' => '',
409
							'type' => 'give_title',
410
							'id'   => 'give_title_gateway_settings_3',
411
						),
412
						array(
413
							'name' => __( 'Collect Billing Details', 'give' ),
414
							'desc' => __( 'This option will enable the billing details section for offline donations. The fieldset will appear above the offline donation instructions. Note: You may customize this option per form as needed.', 'give' ),
415
							'id'   => 'give_offline_donation_enable_billing_fields',
416
							'type' => 'checkbox'
417
						),
418
						array(
419
							'name'    => __( 'Offline Donation Instructions', 'give' ),
420
							'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' ),
421
							'id'      => 'global_offline_donation_content',
422
							'default' => give_get_default_offline_donation_content(),
423
							'type'    => 'wysiwyg',
424
							'options' => array(
425
								'textarea_rows' => 6,
426
							)
427
						),
428
						array(
429
							'name'    => __( 'Offline Donation Email Instructions Subject', 'give' ),
430
							'desc'    => __( 'Enter the subject line for the donation receipt email.', 'give' ),
431
							'id'      => 'offline_donation_subject',
432
							'default' => __( '{donation} - Offline Donation Instructions', 'give' ),
433
							'type'    => 'text'
434
						),
435
						array(
436
							'name'    => __( 'Offline Donation Email Instructions', 'give' ),
437
							'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' ),
438
							'id'      => 'global_offline_donation_email',
439
							'default' => give_get_default_offline_donation_email_content(),
440
							'type'    => 'wysiwyg',
441
							'options' => array(
442
								'textarea_rows' => 6,
443
							)
444
						)
445
					)
446
				)
447
			),
448
			/** Display Settings */
449
			'display'     => array(
450
				'id'         => 'display_settings',
451
				'give_title' => __( 'Display Settings', 'give' ),
452
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
453
				'fields'     => apply_filters( 'give_settings_display', array(
454
						array(
455
							'name' => __( 'Display Settings', 'give' ),
456
							'desc' => '',
457
							'id'   => 'give_title_display_settings_1',
458
							'type' => 'give_title'
459
						),
460
						array(
461
							'name' => __( 'Disable CSS', 'give' ),
462
							'desc' => __( 'Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give' ),
463
							'id'   => 'disable_css',
464
							'type' => 'checkbox'
465
						),
466
						array(
467
							'name' => __( 'Enable Floating Labels', 'give' ),
468
							'desc' => sprintf( esc_html__( 'Enable this option if you would like to enable %1$sfloating labels%2$s in Give\'s donation forms. %3$sBe aware that if you have the "Disable CSS" option enabled, you will need to style the floating labels yourself.', 'give' ), '<a href="' . esc_url( "http://bradfrost.com/blog/post/float-label-pattern/" ) . '" target="_blank">', '</a>', '<br />' ),
469
							'id'   => 'enable_floatlabels',
470
							'type' => 'checkbox'
471
						),
472
						array(
473
							'name' => __( 'Disable Welcome Screen', 'give' ),
474
							'desc' => sprintf( esc_html__( 'Enable this option if you would like to disable the Give Welcome screen every time Give is activated and/or updated. You can always access the Welcome Screen %1$shere%2$s if you want in the future.', 'give' ), '<a href="' . esc_url( admin_url( 'index.php?page=give-about' ) ) . '">', '</a>' ),
475
							'id'   => 'disable_welcome',
476
							'type' => 'checkbox'
477
						),
478
						array(
479
							'name' => __( 'Post Types', 'give' ),
480
							'desc' => '',
481
							'id'   => 'give_title_display_settings_2',
482
							'type' => 'give_title'
483
						),
484
						array(
485
							'name' => __( 'Disable Form Single Views', 'give' ),
486
							'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' ),
487
							'id'   => 'disable_forms_singular',
488
							'type' => 'checkbox'
489
						),
490
						array(
491
							'name' => __( 'Disable Form Archives', 'give' ),
492
							'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' ),
493
							'id'   => 'disable_forms_archives',
494
							'type' => 'checkbox'
495
						),
496
						array(
497
							'name' => __( 'Disable Form Excerpts', 'give' ),
498
							'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' ),
499
							'id'   => 'disable_forms_excerpt',
500
							'type' => 'checkbox'
501
						),
502
503
						array(
504
							'name'    => __( 'Featured Image Size', 'give' ),
505
							'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 forms\' featured image.', 'give' ),
506
							'id'      => 'featured_image_size',
507
							'type'    => 'select',
508
							'default' => 'large',
509
							'options' => give_get_featured_image_sizes()
510
						),
511
						array(
512
							'name' => __( 'Disable Form Featured Image', 'give' ),
513
							'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' ),
514
							'id'   => 'disable_form_featured_img',
515
							'type' => 'checkbox'
516
						),
517
						array(
518
							'name' => __( 'Disable Single Form Sidebar', 'give' ),
519
							'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' ),
520
							'id'   => 'disable_form_sidebar',
521
							'type' => 'checkbox'
522
						),
523
						array(
524
							'name' => __( 'Taxonomies', 'give' ),
525
							'desc' => '',
526
							'id'   => 'give_title_display_settings_3',
527
							'type' => 'give_title'
528
						),
529
						array(
530
							'name' => __( 'Enable Form Categories', 'give' ),
531
							'desc' => __( 'Check this option if you would like to categorize your donation forms. This option enables the form\'s category taxonomy.', 'give' ),
532
							'id'   => 'enable_categories',
533
							'type' => 'checkbox'
534
						),
535
						array(
536
							'name' => __( 'Enable Form Tags', 'give' ),
537
							'desc' => __( 'Check this option if you would like to tag your donation forms. This option enables the form\'s tag taxonomy.', 'give' ),
538
							'id'   => 'enable_tags',
539
							'type' => 'checkbox'
540
						),
541
					)
542
				)
543
544
			),
545
			/**
546
			 * Emails Options
547
			 */
548
			'emails'      => array(
549
				'id'         => 'email_settings',
550
				'give_title' => __( 'Email Settings', 'give' ),
551
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
552
				'fields'     => apply_filters( 'give_settings_emails', array(
553
						array(
554
							'name' => __( 'Email Settings', 'give' ),
555
							'desc' => '',
556
							'id'   => 'give_title_email_settings_1',
557
							'type' => 'give_title'
558
						),
559
						array(
560
							'id'      => 'email_template',
561
							'name'    => __( 'Email Template', 'give' ),
562
							'desc'    => __( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
563
							'type'    => 'select',
564
							'options' => give_get_email_templates()
565
						),
566
						array(
567
							'id'   => 'email_logo',
568
							'name' => __( 'Logo', 'give' ),
569
							'desc' => __( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
570
							'type' => 'file'
571
						),
572
						array(
573
							'id'      => 'from_name',
574
							'name'    => __( 'From Name', 'give' ),
575
							'desc'    => __( 'The name donation receipts are said to come from. This should probably be your site or shop name.', 'give' ),
576
							'default' => get_bloginfo( 'name' ),
577
							'type'    => 'text'
578
						),
579
						array(
580
							'id'      => 'from_email',
581
							'name'    => __( 'From Email', 'give' ),
582
							'desc'    => __( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
583
							'default' => get_bloginfo( 'admin_email' ),
584
							'type'    => 'text'
585
						),
586
						array(
587
							'name' => __( 'Donation Receipt', 'give' ),
588
							'desc' => '',
589
							'id'   => 'give_title_email_settings_2',
590
							'type' => 'give_title'
591
						),
592
						array(
593
							'id'      => 'donation_subject',
594
							'name'    => __( 'Donation Email Subject', 'give' ),
595
							'desc'    => __( 'Enter the subject line for the donation receipt email', 'give' ),
596
							'default' => __( 'Donation Receipt', 'give' ),
597
							'type'    => 'text'
598
						),
599
						array(
600
							'id'      => 'donation_receipt',
601
							'name'    => __( 'Donation Receipt', 'give' ),
602
							'desc'    => __( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags:', 'give' ) . '<br/>' . give_get_emails_tags_list(),
603
							'type'    => 'wysiwyg',
604
							'default' => give_get_default_donation_receipt_email()
605
						),
606
						array(
607
							'name' => __( 'New Donation Notification', 'give' ),
608
							'desc' => '',
609
							'id'   => 'give_title_email_settings_3',
610
							'type' => 'give_title'
611
						),
612
						array(
613
							'id'      => 'donation_notification_subject',
614
							'name'    => __( 'Donation Notification Subject', 'give' ),
615
							'desc'    => __( 'Enter the subject line for the donation notification email', 'give' ),
616
							'type'    => 'text',
617
							'default' => __( 'New Donation - #{payment_id}', 'give' )
618
						),
619
						array(
620
							'id'      => 'donation_notification',
621
							'name'    => __( 'Donation Notification', 'give' ),
622
							'desc'    => __( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags:', 'give' ) . '<br/>' . give_get_emails_tags_list(),
623
							'type'    => 'wysiwyg',
624
							'default' => give_get_default_donation_notification_email()
625
						),
626
						array(
627
							'id'      => 'admin_notice_emails',
628
							'name'    => __( 'Donation Notification Emails', 'give' ),
629
							'desc'    => sprintf( __( 'Enter the email address(es) that should receive a notification anytime a donation is made, please only enter %1$sone email address per line%2$s and not separated by commas.', 'give' ), '<span class="give-underline">', '</span>' ),
630
							'type'    => 'textarea',
631
							'default' => get_bloginfo( 'admin_email' )
632
						),
633
						array(
634
							'id'   => 'disable_admin_notices',
635
							'name' => __( 'Disable Admin Notifications', 'give' ),
636
							'desc' => __( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
637
							'type' => 'checkbox'
638
						)
639
					)
640
				)
641
			),
642
			/** Extension Settings */
643
			'addons'      => array(
644
				'id'         => 'addons',
645
				'give_title' => __( 'Give Add-ons Settings', 'give' ),
646
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
647
				'fields'     => apply_filters( 'give_settings_addons', array()
648
				)
649
			),
650
			/** Licenses Settings */
651
			'licenses'    => array(
652
				'id'         => 'licenses',
653
				'give_title' => __( 'Give Licenses', 'give' ),
654
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
655
				'fields'     => apply_filters( 'give_settings_licenses', array()
656
				)
657
			),
658
			/** Advanced Options */
659
			'advanced'    => array(
660
				'id'         => 'advanced_options',
661
				'give_title' => __( 'Advanced Options', 'give' ),
662
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
663
				'fields'     => apply_filters( 'give_settings_advanced', array(
664
						array(
665
							'name' => __( 'Access Control', 'give' ),
666
							'desc' => '',
667
							'id'   => 'give_title_session_control_1',
668
							'type' => 'give_title'
669
						),
670
						array(
671
							'id'      => 'session_lifetime',
672
							'name'    => __( 'Session Lifetime', 'give' ),
673
							'desc'    => __( 'Give will start a new session per user once they have donated. This option controls the lifetime a user\'s session is kept alive. An active session allows users to view donation receipts on your site without having to be logged in as long as they are using the same browser they used when donating.', 'give' ),
674
							'type'    => 'select',
675
							'options' => array(
676
								'86400'  => __( '24 Hours', 'give' ),
677
								'172800' => __( '48 Hours', 'give' ),
678
								'259200' => __( '72 Hours', 'give' ),
679
								'604800' => __( '1 Week', 'give' ),
680
							)
681
						),
682
						array(
683
							'name' => __( 'Email Access', 'give' ),
684
							'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' ),
685
							'id'   => 'email_access',
686
							'type' => 'checkbox',
687
						),
688
						array(
689
							'id'      => 'recaptcha_key',
690
							'name'    => __( 'reCAPTCHA Site Key', 'give' ),
691
							'desc'    => sprintf( __( 'If you would like to prevent spam on the email access form navigate to %1$sthe reCAPTCHA website%2$s and sign up for an API key. The reCAPTCHA uses Google\'s user-friendly single click verification method.', 'give' ), '<a href="https://www.google.com/recaptcha/" target="_blank">', '</a>' ),
692
							'default' => '',
693
							'type'    => 'text'
694
						),
695
						array(
696
							'id'      => 'recaptcha_secret',
697
							'name'    => __( 'reCAPTCHA Secret Key', 'give' ),
698
							'desc'    => __( 'Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give' ),
699
							'default' => '',
700
							'type'    => 'text'
701
						),
702
						array(
703
							'name' => __( 'Data Control', 'give' ),
704
							'desc' => '',
705
							'id'   => 'give_title_data_control_2',
706
							'type' => 'give_title'
707
						),
708
						array(
709
							'name' => __( 'Remove All Data on Uninstall?', 'give' ),
710
							'desc' => __( 'Check this box if you would like Give to completely remove all of its data when the plugin is deleted.', 'give' ),
711
							'id'   => 'uninstall_on_delete',
712
							'type' => 'checkbox'
713
						),
714
						array(
715
							'name' => __( 'Filter Control', 'give' ),
716
							'desc' => '',
717
							'id'   => 'give_title_filter_control',
718
							'type' => 'give_title'
719
						),
720
						array(
721
							'name' => __( 'Disable <code>the_content</code> filter', 'give' ),
722
							'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="%s" target="_blank">Learn more</a> about the_content filter.', 'give' ), esc_url( 'https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content' ) ),
723
							'id'   => 'disable_the_content_filter',
724
							'type' => 'checkbox'
725
						),
726
						array(
727
							'name' => __( 'Script Loading', 'give' ),
728
							'desc' => '',
729
							'id'   => 'give_title_script_control',
730
							'type' => 'give_title'
731
						),
732
						array(
733
							'name' => __( 'Load Scripts in Footer?', 'give' ),
734
							'desc' => __( 'Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give' ),
735
							'id'   => 'scripts_footer',
736
							'type' => 'checkbox'
737
						)
738
					)
739
				)
740
			),
741
			/** API Settings */
742
			'api'         => array(
743
				'id'         => 'api',
744
				'give_title' => __( 'API', 'give' ),
745
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
746
				'show_names' => false, // Hide field names on the left
747
				'fields'     => apply_filters( 'give_settings_system', array(
748
						array(
749
							'id'   => 'api',
750
							'name' => __( 'API', 'give' ),
751
							'type' => 'api'
752
						)
753
					)
754
				)
755
			),
756
			/** Licenses Settings */
757
			'system_info' => array(
758
				'id'         => 'system_info',
759
				'give_title' => __( 'System Info', 'give' ),
760
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key, ), ),
761
				'fields'     => apply_filters( 'give_settings_system', array(
762
						array(
763
							'id'   => 'system_info',
764
							'name' => __( 'System Info', 'give' ),
765
							'desc' => __( 'Please copy and paste this information in your ticket when contacting support.', 'give' ),
766
							'type' => 'system_info'
767
						)
768
					)
769
				)
770
			),
771
		);
772
773
		//Return all settings array if no active tab
774
		if ( $active_tab === null || ! isset( $give_settings[ $active_tab ] ) ) {
775
776
			return apply_filters( 'give_registered_settings', $give_settings );
777
			
778
		}
779
780
781
		// Add other tabs and settings fields as needed
782
		return apply_filters( 'give_registered_settings', $give_settings[ $active_tab ] );
783
784
	}
785
786
	/**
787
	 * Show Settings Notices
788
	 */
789
	public function settings_notices() {
790
791
		if ( ! isset( $_POST['give_settings_saved'] ) ) {
792
			return;
793
		}
794
795
		add_settings_error( 'give-notices', 'global-settings-updated', __( 'Settings updated.', 'give' ), 'updated' );
796
797
	}
798
799
800
	/**
801
	 * Public getter method for retrieving protected/private variables
802
	 *
803
	 * @since  1.0
804
	 *
805
	 * @param  string $field Field to retrieve
806
	 *
807
	 * @return mixed          Field value or exception is thrown
808
	 */
809
	public function __get( $field ) {
810
811
		// Allowed fields to retrieve
812
		if ( in_array( $field, array( 'key', 'fields', 'give_title', 'options_page' ), true ) ) {
813
			return $this->{$field};
814
		}
815
		if ( 'option_metabox' === $field ) {
816
			return $this->option_metabox();
0 ignored issues
show
Bug introduced by
The method option_metabox() does not seem to exist on object<Give_Plugin_Settings>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
817
		}
818
819
		throw new Exception( 'Invalid property: ' . $field );
820
	}
821
822
823
}
824
825
// Get it started
826
$Give_Settings = new Give_Plugin_Settings();
827
828
/**
829
 * Wrapper function around cmb2_get_option
830
 * @since  0.1.0
831
 *
832
 * @param  string $key Options array key
833
 *
834
 * @return mixed        Option value
835
 */
836
function give_get_option( $key = '', $default = false ) {
837
	global $give_options;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
838
	$value = ! empty( $give_options[ $key ] ) ? $give_options[ $key ] : $default;
839
	$value = apply_filters( 'give_get_option', $value, $key, $default );
840
841
	return apply_filters( 'give_get_option_' . $key, $value, $key, $default );
842
}
843
844
845
/**
846
 * Update an option
847
 *
848
 * Updates an give setting value in both the db and the global variable.
849
 * Warning: Passing in an empty, false or null string value will remove
850
 *          the key from the give_options array.
851
 *
852
 * @since 1.0
853
 *
854
 * @param string $key The Key to update
855
 * @param string|bool|int $value The value to set the key to
856
 *
857
 * @return boolean True if updated, false if not.
858
 */
859
function give_update_option( $key = '', $value = false ) {
860
861
	// If no key, exit
862
	if ( empty( $key ) ) {
863
		return false;
864
	}
865
866
	if ( empty( $value ) ) {
867
		$remove_option = give_delete_option( $key );
868
869
		return $remove_option;
870
	}
871
872
	// First let's grab the current settings
873
	$options = get_option( 'give_settings' );
874
875
	// Let's let devs alter that value coming in
876
	$value = apply_filters( 'give_update_option', $value, $key );
877
878
	// Next let's try to update the value
879
	$options[ $key ] = $value;
880
	$did_update      = update_option( 'give_settings', $options );
881
882
	// If it updated, let's update the global variable
883
	if ( $did_update ) {
884
		global $give_options;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
885
		$give_options[ $key ] = $value;
886
	}
887
888
	return $did_update;
889
}
890
891
/**
892
 * Remove an option
893
 *
894
 * Removes an give setting value in both the db and the global variable.
895
 *
896
 * @since 1.0
897
 *
898
 * @param string $key The Key to delete
899
 *
900
 * @return boolean True if updated, false if not.
901
 */
902
function give_delete_option( $key = '' ) {
903
904
	// If no key, exit
905
	if ( empty( $key ) ) {
906
		return false;
907
	}
908
909
	// First let's grab the current settings
910
	$options = get_option( 'give_settings' );
911
912
	// Next let's try to update the value
913
	if ( isset( $options[ $key ] ) ) {
914
915
		unset( $options[ $key ] );
916
917
	}
918
919
	$did_update = update_option( 'give_settings', $options );
920
921
	// If it updated, let's update the global variable
922
	if ( $did_update ) {
923
		global $give_options;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
924
		$give_options = $options;
925
	}
926
927
	return $did_update;
928
}
929
930
931
/**
932
 * Get Settings
933
 *
934
 * Retrieves all Give plugin settings
935
 *
936
 * @since 1.0
937
 * @return array Give settings
938
 */
939
function give_get_settings() {
940
941
	$settings = get_option( 'give_settings' );
942
943
	return (array) apply_filters( 'give_get_settings', $settings );
944
945
}
946
947
948
/**
949
 * Give Settings Array Insert
950
 *
951
 * @description: Allows other Add-ons and plugins to insert Give settings at a desired position
952
 *
953
 * @since      1.3.5
954
 *
955
 * @param $array
956
 * @param $position |int|string Expects an array key or 'id' of the settings field to appear after
957
 * @param $insert |array a valid array of options to insert
958
 *
959
 * @return array
960
 */
961
function give_settings_array_insert( $array, $position, $insert ) {
962
	if ( is_int( $position ) ) {
963
		array_splice( $array, $position, 0, $insert );
964
	} else {
965
966
		foreach ( $array as $index => $subarray ) {
967
			if ( isset( $subarray['id'] ) && $subarray['id'] == $position ) {
968
				$pos = $index;
969
			}
970
		}
971
972
		if ( ! isset( $pos ) ) {
973
			return $array;
974
		}
975
976
		$array = array_merge(
977
			array_slice( $array, 0, $pos ),
978
			$insert,
979
			array_slice( $array, $pos )
980
		);
981
	}
982
983
	return $array;
984
}
985
986
987
/**
988
 * Gateways Callback
989
 *
990
 * Renders gateways fields.
991
 *
992
 * @since 1.0
993
 *
994
 * @param $field_object
995
 * @param $escaped_value
996
 * @param $object_id
997
 * @param $object_type
998
 * @param $field_type_object
999
 *
1000
 * @return void
1001
 */
1002
function give_enabled_gateways_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...
1003
1004
	$id                = $field_type_object->field->args['id'];
1005
	$field_description = $field_type_object->field->args['desc'];
1006
	$gateways          = give_get_payment_gateways();
1007
1008
	echo '<ul class="cmb2-checkbox-list cmb2-list">';
1009
1010
	foreach ( $gateways as $key => $option ) :
1011
1012
		if ( is_array( $escaped_value ) && array_key_exists( $key, $escaped_value ) ) {
1013
			$enabled = '1';
1014
		} else {
1015
			$enabled = null;
1016
		}
1017
1018
		echo '<li><input name="' . $id . '[' . $key . ']" id="' . $id . '[' . $key . ']" type="checkbox" value="1" ' . checked( '1', $enabled, false ) . '/>&nbsp;';
1019
		echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
1020
1021
	endforeach;
1022
1023
	if ( $field_description ) {
1024
		echo '<p class="cmb2-metabox-description">' . $field_description . '</p>';
1025
	}
1026
1027
	echo '</ul>';
1028
1029
1030
}
1031
1032
/**
1033
 * Gateways Callback (drop down)
1034
 *
1035
 * Renders gateways select menu
1036
 *
1037
 * @since 1.0
1038
 *
1039
 * @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1040
 *
1041
 * @return void
1042
 */
1043
function give_default_gateway_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...
1044
1045
	$id                = $field_type_object->field->args['id'];
1046
	$field_description = $field_type_object->field->args['desc'];
1047
	$gateways          = give_get_enabled_payment_gateways();
1048
1049
	echo '<select class="cmb2_select" name="' . $id . '" id="' . $id . '">';
1050
1051
	//Add a field to the Give Form admin single post view of this field
1052
	if ( $field_type_object->field->object_type === 'post' ) {
1053
		echo '<option value="global">' . __( 'Global Default', 'give' ) . '</option>';
1054
	}
1055
1056
	foreach ( $gateways as $key => $option ) :
1057
1058
		$selected = isset( $escaped_value ) ? selected( $key, $escaped_value, false ) : '';
1059
1060
1061
		echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1062
1063
	endforeach;
1064
1065
	echo '</select>';
1066
1067
	echo '<p class="cmb2-metabox-description">' . $field_description . '</p>';
1068
1069
}
1070
1071
/**
1072
 * Give Title
1073
 *
1074
 * Renders custom section titles output; Really only an  because CMB2's output is a bit funky
1075
 *
1076
 * @since 1.0
1077
 *
1078
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1079
 *
1080
 * @return void
1081
 */
1082
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...
1083
1084
	$id                = $field_type_object->field->args['id'];
1085
	$title             = $field_type_object->field->args['name'];
1086
	$field_description = $field_type_object->field->args['desc'];
1087
1088
	echo '<hr>' . $field_description;
1089
1090
}
1091
1092
/**
1093
 * Give Description
1094
 *
1095
 * @description: Renders custom description text which any plugin can use to output content, html, php, etc.
1096
 *
1097
 * @since      1.3.5
1098
 *
1099
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1100
 *
1101
 * @return void
1102
 */
1103
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...
1104
1105
	$id                = $field_type_object->field->args['id'];
1106
	$title             = $field_type_object->field->args['name'];
1107
	$field_description = $field_type_object->field->args['desc'];
1108
1109
1110
	echo $field_description;
1111
1112
}
1113
1114
/**
1115
 * Gets a number of posts and displays them as options
1116
 *
1117
 * @param  array $query_args Optional. Overrides defaults.
1118
 * @param  bool $force Force the pages to be loaded even if not on settings
1119
 *
1120
 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
1121
 * @return array An array of options that matches the CMB2 options array
1122
 */
1123
function give_cmb2_get_post_options( $query_args, $force = false ) {
1124
1125
	$post_options = array( '' => '' ); // Blank option
1126
1127
	if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
1128
		return $post_options;
1129
	}
1130
1131
	$args = wp_parse_args( $query_args, array(
1132
		'post_type'   => 'page',
1133
		'numberposts' => 10,
1134
	) );
1135
1136
	$posts = get_posts( $args );
1137
1138
	if ( $posts ) {
1139
		foreach ( $posts as $post ) {
1140
1141
			$post_options[ $post->ID ] = $post->post_title;
1142
1143
		}
1144
	}
1145
1146
	return $post_options;
1147
}
1148
1149
1150
/**
1151
 * Featured Image Sizes
1152
 *
1153
 * @description: Outputs an array for the "Featured Image Size" option found under Settings > Display Options
1154
 *
1155
 * @since 1.4
1156
 */
1157
function give_get_featured_image_sizes() {
1158
	global $_wp_additional_image_sizes;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1159
	$sizes = array();
1160
1161
	foreach ( get_intermediate_image_sizes() as $_size ) {
1162
1163
		if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
1164
			$sizes[ $_size ] = $_size . ' - ' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
1165
		} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1166
			$sizes[ $_size ] = $_size . ' - ' . $_wp_additional_image_sizes[ $_size ]['width'] . 'x' . $_wp_additional_image_sizes[ $_size ]['height'];
1167
		}
1168
1169
	}
1170
1171
	return apply_filters( 'give_get_featured_image_sizes', $sizes );
1172
}
1173
1174
1175
/**
1176
 * Give License Key Callback
1177
 *
1178
 * @description Registers the license field callback for EDD's Software Licensing
1179
 * @since       1.0
1180
 *
1181
 * @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1182
 *
1183
 * @return void
1184
 */
1185
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...
1186
1187
	$id                = $field_type_object->field->args['id'];
1188
	$field_description = $field_type_object->field->args['desc'];
1189
	$license_status    = get_option( $field_type_object->field->args['options']['is_valid_license_option'] );
1190
	$field_classes     = 'regular-text give-license-field';
1191
	$type              = empty( $escaped_value ) ? 'text' : 'password';
1192
1193
	if ( $license_status === 'valid' ) {
1194
		$field_classes .= ' give-license-active';
1195
	}
1196
1197
	$html = $field_type_object->input( array(
1198
		'class' => $field_classes,
1199
		'type'  => $type
1200
	) );
1201
1202
	//License is active so show deactivate button
1203
	if ( $license_status === 'valid' ) {
1204
		$html .= '<input type="submit" class="button-secondary give-license-deactivate" name="' . $id . '_deactivate" value="' . __( 'Deactivate License', 'give' ) . '"/>';
1205
	} else {
1206
		//This license is not valid so delete it
1207
		give_delete_option( $id );
1208
	}
1209
1210
	$html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1211
1212
	wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1213
1214
	echo $html;
1215
}
1216
1217
1218
/**
1219
 * Display the API Keys
1220
 *
1221
 * @since       2.0
1222
 * @return      void
1223
 */
1224
function give_api_callback() {
1225
1226
	if ( ! current_user_can( 'manage_give_settings' ) ) {
1227
		return;
1228
	}
1229
1230
	do_action( 'give_tools_api_keys_before' );
1231
1232
	require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
1233
1234
	$api_keys_table = new Give_API_Keys_Table();
1235
	$api_keys_table->prepare_items();
1236
	$api_keys_table->display();
1237
	?>
1238
	<p>
1239
		<?php printf(
1240
			__( 'API keys allow users to use the <a href="%s">Give REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%s">Zapier</a>.', 'give' ),
1241
			'https://givewp.com/documentation/give-api-reference/',
1242
			'https://givewp.com/addons/zapier/'
1243
		); ?>
1244
	</p>
1245
1246
	<?php
1247
1248
	do_action( 'give_tools_api_keys_after' );
1249
}
1250
1251
add_action( 'give_settings_tab_api_keys', 'give_api_callback' );
1252
1253
/**
1254
 * Hook Callback
1255
 *
1256
 * Adds a do_action() hook in place of the field
1257
 *
1258
 * @since 1.0
1259
 *
1260
 * @param array $args Arguments passed by the setting
1261
 *
1262
 * @return void
1263
 */
1264
function give_hook_callback( $args ) {
1265
	do_action( 'give_' . $args['id'] );
1266
}
1267
1268
/**
1269
 * Get the CMB2 bootstrap!
1270
 *
1271
 * @description: Checks to see if CMB2 plugin is installed first the uses included CMB2; we can still use it even it it's not active. This prevents fatal error conflicts with other themes and users of the CMB2 WP.org plugin
1272
 *
1273
 */
1274
1275
if ( file_exists( WP_PLUGIN_DIR . '/cmb2/init.php' ) && ! defined( 'CMB2_LOADED' ) ) {
1276
	require_once WP_PLUGIN_DIR . '/cmb2/init.php';
1277
} elseif ( file_exists( GIVE_PLUGIN_DIR . '/includes/libraries/cmb2/init.php' ) && ! defined( 'CMB2_LOADED' ) ) {
1278
	require_once GIVE_PLUGIN_DIR . '/includes/libraries/cmb2/init.php';
1279
} elseif ( file_exists( GIVE_PLUGIN_DIR . '/includes/libraries/CMB2/init.php' ) && ! defined( 'CMB2_LOADED' ) ) {
1280
	require_once GIVE_PLUGIN_DIR . '/includes/libraries/CMB2/init.php';
1281
}