Completed
Push — issue/1680 ( 7086f3 )
by Ravinder
18:25
created

class-give-settings.php ➔ give_get_featured_image_sizes()   C

Complexity

Conditions 8
Paths 26

Size

Total Lines 40
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 20
nc 26
nop 0
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
1
<?php
0 ignored issues
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 17 and the first side effect is on line 806.

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
 * 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 CMB2 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';
123
124
		?>
125
126
		<div class="wrap give_settings_page cmb2_options_page <?php echo $this->key; ?>">
127
128
			<h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1>
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( add_query_arg( array(
135
						'settings-updated' => false,
136
						'tab'              => $tab_id,
137
					) ) );
138
139
					$active = $active_tab == $tab_id ? ' nav-tab-active' : '';
140
141
					echo '<a href="' . esc_url( $tab_url ) . '" class="nav-tab' . $active . '" id="tab-' . $tab_id . '">' . esc_html( $tab_name ) . '</a>';
142
143
				}
144
				?>
145
			</h2>
146
147
			<?php cmb2_metabox_form( $this->give_settings( $active_tab ), $this->key ); ?>
148
149
		</div><!-- .wrap -->
150
151
		<?php
152
	}
153
154
155
	/**
156
	 *
157
	 * Modify CMB2 Default Form Output
158
	 *
159
	 * @param string @args
160
	 *
161
	 * @since 1.0
162
	 *
163
	 * @param $form_format
164
	 * @param $object_id
165
	 * @param $cmb
166
	 *
167
	 * @return string
168
	 */
169
	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...
170
171
		// only modify the give settings form
172
		if ( 'give_settings' == $object_id ) {
173
174
			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>';
175
176
		}
177
178
		return $form_format;
179
180
	}
181
182
	/**
183
	 * Define General Settings Metabox and field configurations.
184
	 *
185
	 * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
186
	 *
187
	 * @param $active_tab |string active tab settings; null returns full array
188
	 *
189
	 * @return array
190
	 */
191
	public function give_settings( $active_tab ) {
192
193
		$give_settings = array(
194
			/**
195
			 * General Settings
196
			 */
197
			'general'     => array(
198
				'id'         => 'general_settings',
199
				'give_title' => __( 'General Settings', 'give' ),
200
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
201
				'fields'     => apply_filters( 'give_settings_general', array(
202
						array(
203
							'name' => __( 'General Settings', 'give' ),
204
							'desc' => '',
205
							'type' => 'give_title',
206
							'id'   => 'give_title_general_settings_1',
207
						),
208
						array(
209
							'name'    => __( 'Success Page', 'give' ),
210
							/* translators: %s: [give_receipt] */
211
							'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>' ),
212
							'id'      => 'success_page',
213
							'type'    => 'select',
214
							'options' => give_cmb2_get_post_options( array(
215
								'post_type'   => 'page',
216
								'numberposts' => - 1,
217
							) ),
218
						),
219
						array(
220
							'name'    => __( 'Failed Donation Page', 'give' ),
221
							'desc'    => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
222
							'id'      => 'failure_page',
223
							'type'    => 'select',
224
							'options' => give_cmb2_get_post_options( array(
225
								'post_type'   => 'page',
226
								'numberposts' => - 1,
227
							) ),
228
						),
229
						array(
230
							'name'    => __( 'Donation History Page', 'give' ),
231
							/* translators: %s: [donation_history] */
232
							'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>' ),
233
							'id'      => 'history_page',
234
							'type'    => 'select',
235
							'options' => give_cmb2_get_post_options( array(
236
								'post_type'   => 'page',
237
								'numberposts' => - 1,
238
							) ),
239
						),
240
						array(
241
							'name'    => __( 'Base Country', 'give' ),
242
							'desc'    => __( 'The country your site operates from.', 'give' ),
243
							'id'      => 'base_country',
244
							'type'    => 'select',
245
							'options' => give_get_country_list(),
246
						),
247
						array(
248
							'name' => __( 'Currency Settings', 'give' ),
249
							'desc' => '',
250
							'type' => 'give_title',
251
							'id'   => 'give_title_general_settings_2',
252
						),
253
						array(
254
							'name'    => __( 'Currency', 'give' ),
255
							'desc'    => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
256
							'id'      => 'currency',
257
							'type'    => 'select',
258
							'options' => give_get_currencies(),
259
							'default' => 'USD',
260
						),
261
						array(
262
							'name'    => __( 'Currency Position', 'give' ),
263
							'desc'    => __( 'The position of the currency symbol.', 'give' ),
264
							'id'      => 'currency_position',
265
							'type'    => 'select',
266
							'options' => array(
267
								/* translators: %s: currency symbol */
268
								'before' => sprintf( __( 'Before - %s10', 'give' ), give_currency_symbol( give_get_currency() ) ),
269
								/* translators: %s: currency symbol */
270
								'after'  => sprintf( __( 'After - 10%s', 'give' ), give_currency_symbol( give_get_currency() ) ),
271
							),
272
							'default' => 'before',
273
						),
274
						array(
275
							'name'            => __( 'Thousands Separator', 'give' ),
276
							'desc'            => __( 'The symbol (usually , or .) to separate thousands.', 'give' ),
277
							'id'              => 'thousands_separator',
278
							'type'            => 'text_small',
279
							'sanitization_cb' => 'give_sanitize_thousand_separator',
280
							'default'         => ',',
281
						),
282
						array(
283
							'name'    => __( 'Decimal Separator', 'give' ),
284
							'desc'    => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
285
							'id'      => 'decimal_separator',
286
							'type'    => 'text_small',
287
							'default' => '.',
288
						),
289
						array(
290
							'name'            => __( 'Number of Decimals', 'give' ),
291
							'desc'            => __( 'The number of decimal points displayed in amounts.', 'give' ),
292
							'id'              => 'number_decimals',
293
							'type'            => 'text_small',
294
							'default'         => 2,
295
							'sanitization_cb' => 'give_sanitize_number_decimals',
296
						),
297
					)
298
				),
299
			),
300
			/**
301
			 * Payment Gateways
302
			 */
303
			'gateways'    => array(
304
				'id'         => 'payment_gateways',
305
				'give_title' => __( 'Payment Gateways', 'give' ),
306
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
307
				'fields'     => apply_filters( 'give_settings_gateways', array(
308
						array(
309
							'name' => __( 'Gateways Settings', 'give' ),
310
							'desc' => '',
311
							'id'   => 'give_title_gateway_settings_1',
312
							'type' => 'give_title',
313
						),
314
						array(
315
							'name' => __( 'Test Mode', 'give' ),
316
							'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' ),
317
							'id'   => 'test_mode',
318
							'type' => 'checkbox',
319
						),
320
						array(
321
							'name' => __( 'Enabled Gateways', 'give' ),
322
							'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
323
							'id'   => 'gateways',
324
							'type' => 'enabled_gateways',
325
						),
326
						array(
327
							'name' => __( 'Default Gateway', 'give' ),
328
							'desc' => __( 'The gateway that will be selected by default.', 'give' ),
329
							'id'   => 'default_gateway',
330
							'type' => 'default_gateway',
331
						),
332
						array(
333
							'name' => __( 'PayPal Standard', 'give' ),
334
							'desc' => '',
335
							'type' => 'give_title',
336
							'id'   => 'give_title_gateway_settings_2',
337
						),
338
						array(
339
							'name' => __( 'PayPal Email', 'give' ),
340
							'desc' => __( 'Enter your PayPal account\'s email.', 'give' ),
341
							'id'   => 'paypal_email',
342
							'type' => 'text_email',
343
						),
344
						array(
345
							'name' => __( 'PayPal Page Style', 'give' ),
346
							'desc' => __( 'Enter the name of the page style to use, or leave blank to use the default.', 'give' ),
347
							'id'   => 'paypal_page_style',
348
							'type' => 'text',
349
						),
350
						array(
351
							'name'    => __( 'PayPal Transaction Type', 'give' ),
352
							'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' ),
353
							'id'      => 'paypal_button_type',
354
							'type'    => 'radio_inline',
355
							'options' => array(
356
								'donation' => __( 'Donation', 'give' ),
357
								'standard' => __( 'Standard Transaction', 'give' ),
358
							),
359
							'default' => 'donation',
360
						),
361
						array(
362
							'name' => __( 'Disable PayPal IPN Verification', 'give' ),
363
							'desc' => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
364
							'id'   => 'disable_paypal_verification',
365
							'type' => 'checkbox',
366
						),
367
						array(
368
							'name' => __( 'Offline Donations', 'give' ),
369
							'desc' => '',
370
							'type' => 'give_title',
371
							'id'   => 'give_title_gateway_settings_3',
372
						),
373
						array(
374
							'name' => __( 'Collect Billing Details', 'give' ),
375
							'desc' => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
376
							'id'   => 'give_offline_donation_enable_billing_fields',
377
							'type' => 'checkbox',
378
						),
379
						array(
380
							'name'    => __( 'Offline Donation Instructions', 'give' ),
381
							'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' ),
382
							'id'      => 'global_offline_donation_content',
383
							'default' => give_get_default_offline_donation_content(),
384
							'type'    => 'wysiwyg',
385
							'options' => array(
386
								'textarea_rows' => 6,
387
							),
388
						),
389
						array(
390
							'name'    => __( 'Offline Donation Email Instructions Subject', 'give' ),
391
							'desc'    => __( 'Enter the subject line for the donation receipt email.', 'give' ),
392
							'id'      => 'offline_donation_subject',
393
							'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ),
394
							'type'    => 'text',
395
						),
396
						array(
397
							'name'    => __( 'Offline Donation Email Instructions', 'give' ),
398
							'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' ),
399
							'id'      => 'global_offline_donation_email',
400
							'default' => give_get_default_offline_donation_email_content(),
401
							'type'    => 'wysiwyg',
402
							'options' => array(
403
								'textarea_rows' => 6,
404
							),
405
						),
406
					)
407
				),
408
			),
409
			/** Display Settings */
410
			'display'     => array(
411
				'id'         => 'display_settings',
412
				'give_title' => __( 'Display Settings', 'give' ),
413
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
414
				'fields'     => apply_filters( 'give_settings_display', array(
415
						array(
416
							'name' => __( 'Display Settings', 'give' ),
417
							'desc' => '',
418
							'id'   => 'give_title_display_settings_1',
419
							'type' => 'give_title',
420
						),
421
						array(
422
							'name' => __( 'Disable CSS', 'give' ),
423
							'desc' => __( 'Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give' ),
424
							'id'   => 'disable_css',
425
							'type' => 'checkbox',
426
						),
427
						array(
428
							'name' => __( 'Enable Floating Labels', 'give' ),
429
							/* translators: %s: http://docs.givewp.com/form-floating-labels */
430
							'desc' => sprintf( wp_kses( __( '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(
431
								'a' => array(
432
									'href'   => array(),
433
									'target' => array(),
434
								),
435
							) ), esc_url( 'http://docs.givewp.com/form-floating-labels' ) ),
436
							'id'   => 'floatlabels',
437
							'type' => 'checkbox',
438
						),
439
						array(
440
							'name' => __( 'Disable Welcome Screen', 'give' ),
441
							/* translators: %s: about page URL */
442
							'desc' => sprintf( wp_kses( __( '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(
443
								'a' => array(
444
									'href'   => array(),
445
									'target' => array(),
446
								),
447
							) ), esc_url( admin_url( 'index.php?page=give-about' ) ) ),
448
							'id'   => 'disable_welcome',
449
							'type' => 'checkbox',
450
						),
451
						array(
452
							'name' => __( 'Post Types', 'give' ),
453
							'desc' => '',
454
							'id'   => 'give_title_display_settings_2',
455
							'type' => 'give_title',
456
						),
457
						array(
458
							'name' => __( 'Disable Form Single Views', 'give' ),
459
							'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' ),
460
							'id'   => 'disable_forms_singular',
461
							'type' => 'checkbox',
462
						),
463
						array(
464
							'name' => __( 'Disable Form Archives', 'give' ),
465
							'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' ),
466
							'id'   => 'disable_forms_archives',
467
							'type' => 'checkbox',
468
						),
469
						array(
470
							'name' => __( 'Disable Form Excerpts', 'give' ),
471
							'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' ),
472
							'id'   => 'disable_forms_excerpt',
473
							'type' => 'checkbox',
474
						),
475
						array(
476
							'name'    => __( 'Featured Image Size', 'give' ),
477
							'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' ),
478
							'id'      => 'featured_image_size',
479
							'type'    => 'select',
480
							'default' => 'large',
481
							'options' => give_get_featured_image_sizes(),
482
						),
483
						array(
484
							'name' => __( 'Disable Form Featured Image', 'give' ),
485
							'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' ),
486
							'id'   => 'disable_form_featured_img',
487
							'type' => 'checkbox',
488
						),
489
						array(
490
							'name' => __( 'Disable Single Form Sidebar', 'give' ),
491
							'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' ),
492
							'id'   => 'disable_form_sidebar',
493
							'type' => 'checkbox',
494
						),
495
						array(
496
							'name' => __( 'Taxonomies', 'give' ),
497
							'desc' => '',
498
							'id'   => 'give_title_display_settings_3',
499
							'type' => 'give_title',
500
						),
501
						array(
502
							'name' => __( 'Enable Form Categories', 'give' ),
503
							'desc' => __( 'Enables the "Category" taxonomy for all Give forms.', 'give' ),
504
							'id'   => 'categories',
505
							'type' => 'checkbox',
506
						),
507
						array(
508
							'name' => __( 'Enable Form Tags', 'give' ),
509
							'desc' => __( 'Enables the "Tag" taxonomy for all Give forms.', 'give' ),
510
							'id'   => 'tags',
511
							'type' => 'checkbox',
512
						),
513
					)
514
				),
515
516
			),
517
			/**
518
			 * Emails Options
519
			 */
520
			'emails'      => array(
521
				'id'         => 'email_settings',
522
				'give_title' => __( 'Email Settings', 'give' ),
523
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
524
				'fields'     => apply_filters( 'give_settings_emails', array(
525
						array(
526
							'name' => __( 'Email Settings', 'give' ),
527
							'desc' => '',
528
							'id'   => 'give_title_email_settings_1',
529
							'type' => 'give_title',
530
						),
531
						array(
532
							'id'      => 'email_template',
533
							'name'    => __( 'Email Template', 'give' ),
534
							'desc'    => __( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
535
							'type'    => 'select',
536
							'options' => give_get_email_templates(),
537
						),
538
						array(
539
							'id'   => 'email_logo',
540
							'name' => __( 'Logo', 'give' ),
541
							'desc' => __( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
542
							'type' => 'file',
543
						),
544
						array(
545
							'id'      => 'from_name',
546
							'name'    => __( 'From Name', 'give' ),
547
							'desc'    => __( 'The name that appears in the "From" field in donation receipt emails.', 'give' ),
548
							'default' => get_bloginfo( 'name' ),
549
							'type'    => 'text',
550
						),
551
						array(
552
							'id'      => 'from_email',
553
							'name'    => __( 'From Email', 'give' ),
554
							'desc'    => __( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
555
							'default' => get_bloginfo( 'admin_email' ),
556
							'type'    => 'text',
557
						),
558
						array(
559
							'name' => __( 'Donation Receipt', 'give' ),
560
							'desc' => '',
561
							'id'   => 'give_title_email_settings_2',
562
							'type' => 'give_title',
563
						),
564
						array(
565
							'id'      => 'donation_subject',
566
							'name'    => __( 'Donation Email Subject', 'give' ),
567
							'desc'    => __( 'Enter the subject line for the donation receipt email.', 'give' ),
568
							'default' => esc_attr__( 'Donation Receipt', 'give' ),
569
							'type'    => 'text',
570
						),
571
						array(
572
							'id'      => 'donation_receipt',
573
							'name'    => __( 'Donation Receipt', 'give' ),
574
							'desc'    => sprintf(
575
								/* translators: %s: emails tags list */
576
								__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
577
								'<br/>' . give_get_emails_tags_list()
578
							),
579
							'type'    => 'wysiwyg',
580
							'default' => give_get_default_donation_receipt_email(),
581
						),
582
						array(
583
							'name' => __( 'New Donation Notification', 'give' ),
584
							'desc' => '',
585
							'id'   => 'give_title_email_settings_3',
586
							'type' => 'give_title',
587
						),
588
						array(
589
							'id'      => 'donation_notification_subject',
590
							'name'    => __( 'Donation Notification Subject', 'give' ),
591
							'desc'    => __( 'Enter the subject line for the donation notification email.', 'give' ),
592
							'type'    => 'text',
593
							'default' => esc_attr__( 'New Donation - #{payment_id}', 'give' ),
594
						),
595
						array(
596
							'id'      => 'donation_notification',
597
							'name'    => __( 'Donation Notification', 'give' ),
598
							'desc'    => sprintf(
599
								/* translators: %s: emails tags list */
600
								__( 'Enter the email that is sent to donation notification emails after completion of a donation. HTML is accepted. Available template tags: %s', 'give' ),
601
								'<br/>' . give_get_emails_tags_list()
602
							),
603
							'type'    => 'wysiwyg',
604
							'default' => give_get_default_donation_notification_email(),
605
						),
606
						array(
607
							'id'      => 'admin_notice_emails',
608
							'name'    => __( 'Donation Notification Emails', 'give' ),
609
							'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' ),
610
							'type'    => 'textarea',
611
							'default' => get_bloginfo( 'admin_email' ),
612
						),
613
						array(
614
							'id'   => 'disable_admin_notices',
615
							'name' => __( 'Disable Admin Notifications', 'give' ),
616
							'desc' => __( 'Check this box if you do not want to receive emails when new donations are made.', 'give' ),
617
							'type' => 'checkbox',
618
						),
619
					)
620
				),
621
			),
622
			/** Extension Settings */
623
			'addons'      => array(
624
				'id'         => 'addons',
625
				'give_title' => __( 'Give Add-ons Settings', 'give' ),
626
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
627
				'fields'     => apply_filters( 'give_settings_addons', array()
628
				),
629
			),
630
			/** Licenses Settings */
631
			'licenses'    => array(
632
				'id'         => 'licenses',
633
				'give_title' => __( 'Give Licenses', 'give' ),
634
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
635
				'fields'     => apply_filters( 'give_settings_licenses', array()
636
				),
637
			),
638
			/** Advanced Options */
639
			'advanced'    => array(
640
				'id'         => 'advanced_options',
641
				'give_title' => __( 'Advanced Options', 'give' ),
642
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
643
				'fields'     => apply_filters( 'give_settings_advanced', array(
644
						array(
645
							'name' => __( 'Access Control', 'give' ),
646
							'desc' => '',
647
							'id'   => 'give_title_session_control_1',
648
							'type' => 'give_title',
649
						),
650
						array(
651
							'id'      => 'session_lifetime',
652
							'name'    => __( 'Session Lifetime', 'give' ),
653
							'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' ),
654
							'type'    => 'select',
655
							'options' => array(
656
								'86400'  => __( '24 Hours', 'give' ),
657
								'172800' => __( '48 Hours', 'give' ),
658
								'259200' => __( '72 Hours', 'give' ),
659
								'604800' => __( '1 Week', 'give' ),
660
							),
661
						),
662
						array(
663
							'name' => __( 'Email Access', 'give' ),
664
							'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' ),
665
							'id'   => 'email_access',
666
							'type' => 'checkbox',
667
						),
668
						array(
669
							'id'      => 'recaptcha_key',
670
							'name'    => __( 'reCAPTCHA Site Key', 'give' ),
671
							/* translators: %s: https://www.google.com/recaptcha/ */
672
							'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/' ) ),
673
							'default' => '',
674
							'type'    => 'text',
675
						),
676
						array(
677
							'id'      => 'recaptcha_secret',
678
							'name'    => __( 'reCAPTCHA Secret Key', 'give' ),
679
							'desc'    => __( 'Please paste the reCAPTCHA secret key here from your manage reCAPTCHA API Keys panel.', 'give' ),
680
							'default' => '',
681
							'type'    => 'text',
682
						),
683
						array(
684
							'name' => __( 'Data Control', 'give' ),
685
							'desc' => '',
686
							'id'   => 'give_title_data_control_2',
687
							'type' => 'give_title',
688
						),
689
						array(
690
							'name' => __( 'Remove All Data on Uninstall?', 'give' ),
691
							'desc' => __( 'When the plugin is deleted, completely remove all Give data.', 'give' ),
692
							'id'   => 'uninstall_on_delete',
693
							'type' => 'checkbox',
694
						),
695
						array(
696
							'name' => __( 'Filter Control', 'give' ),
697
							'desc' => '',
698
							'id'   => 'give_title_filter_control',
699
							'type' => 'give_title',
700
						),
701
						array(
702
							/* translators: %s: the_content */
703
							'name' => sprintf( __( 'Disable %s filter', 'give' ), '<code>the_content</code>' ),
704
							/* translators: 1: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content 2: the_content */
705
							'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>' ),
706
							'id'   => 'disable_the_content_filter',
707
							'type' => 'checkbox',
708
						),
709
						array(
710
							'name' => __( 'Script Loading', 'give' ),
711
							'desc' => '',
712
							'id'   => 'give_title_script_control',
713
							'type' => 'give_title',
714
						),
715
						array(
716
							'name' => __( 'Load Scripts in Footer?', 'give' ),
717
							'desc' => __( 'Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give' ),
718
							'id'   => 'scripts_footer',
719
							'type' => 'checkbox',
720
						),
721
					)
722
				),
723
			),
724
			/** API Settings */
725
			'api'         => array(
726
				'id'         => 'api',
727
				'give_title' => __( 'API', 'give' ),
728
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
729
				'show_names' => false, // Hide field names on the left
730
				'fields'     => apply_filters( 'give_settings_system', array(
731
						array(
732
							'id'   => 'api',
733
							'name' => __( 'API', 'give' ),
734
							'type' => 'api',
735
						),
736
					)
737
				),
738
			),
739
			/** Licenses Settings */
740
			'system_info' => array(
741
				'id'         => 'system_info',
742
				'give_title' => __( 'System Info', 'give' ),
743
				'show_on'    => array( 'key' => 'options-page', 'value' => array( $this->key ) ),
744
				'fields'     => apply_filters( 'give_settings_system', array(
745
						array(
746
							'id'   => 'system-info-textarea',
747
							'name' => __( 'System Info', 'give' ),
748
							'desc' => __( 'Please copy and paste this information in your ticket when contacting support.', 'give' ),
749
							'type' => 'system_info',
750
						),
751
					)
752
				),
753
			),
754
		);
755
756
		$give_settings = apply_filters( 'give_registered_settings', $give_settings );
757
758
		// Return all settings array if no active tab
759
		if ( empty( $active_tab ) || ! isset( $give_settings[ $active_tab ] ) ) {
760
			return $give_settings;
761
		}
762
763
		// Add other tabs and settings fields as needed
764
		return $give_settings[ $active_tab ];
765
766
	}
767
768
	/**
769
	 * Show Settings Notices
770
	 */
771
	public function settings_notices() {
772
773
		if ( ! isset( $_POST['give_settings_saved'] ) ) {
774
			return;
775
		}
776
777
		add_settings_error( 'give-notices', 'global-settings-updated', __( 'Settings updated.', 'give' ), 'updated' );
778
779
	}
780
781
782
	/**
783
	 * Public getter method for retrieving protected/private variables
784
	 *
785
	 * @since  1.0
786
	 *
787
	 * @param  string $field Field to retrieve
788
	 *
789
	 * @return mixed         Field value or exception is thrown.
790
	 * @throws Exception     Throws an exception if the field is invalid.
791
	 */
792
	public function __get( $field ) {
793
794
		// Allowed fields to retrieve
795
		if ( in_array( $field, array( 'key', 'fields', 'give_title', 'options_page' ), true ) ) {
796
			return $this->{$field};
797
		}
798
799
		throw new Exception( sprintf( __( 'Invalid property: %s', 'give' ), $field ) );
800
	}
801
802
803
}
804
805
// Get it started
806
$Give_Settings = new Give_Plugin_Settings();
807
808
/**
809
 * Helps get a single option from the give_get_settings() array.
810
 *
811
 * @since  0.1.0
812
 *
813
 * @param  string      $key     Options array key
814
 * @param  string|bool $default The default option if the option isn't set
815
 *
816
 * @return mixed        Option value
817
 */
818
function give_get_option( $key = '', $default = false ) {
819
	$give_options = give_get_settings();
820
	$value        = ! empty( $give_options[ $key ] ) ? $give_options[ $key ] : $default;
821
	$value        = apply_filters( 'give_get_option', $value, $key, $default );
822
823
	return apply_filters( "give_get_option_{$key}", $value, $key, $default );
824
}
825
826
827
/**
828
 * Update an option
829
 *
830
 * Updates an give setting value in both the db and the global variable.
831
 * Warning: Passing in an empty, false or null string value will remove
832
 *          the key from the give_options array.
833
 *
834
 * @since 1.0
835
 *
836
 * @param string          $key   The Key to update
837
 * @param string|bool|int $value The value to set the key to
838
 *
839
 * @return boolean True if updated, false if not.
840
 */
841
function give_update_option( $key = '', $value = false ) {
842
843
	// If no key, exit
844
	if ( empty( $key ) ) {
845
		return false;
846
	}
847
848
	if ( empty( $value ) ) {
849
		$remove_option = give_delete_option( $key );
850
851
		return $remove_option;
852
	}
853
854
	// First let's grab the current settings
855
	$options = get_option( 'give_settings' );
856
857
	// Let's let devs alter that value coming in
858
	$value = apply_filters( 'give_update_option', $value, $key );
859
860
	// Next let's try to update the value
861
	$options[ $key ] = $value;
862
	$did_update      = update_option( 'give_settings', $options );
863
864
	// If it updated, let's update the global variable
865
	if ( $did_update ) {
866
		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...
867
		$give_options[ $key ] = $value;
868
	}
869
870
	return $did_update;
871
}
872
873
/**
874
 * Remove an option
875
 *
876
 * Removes an give setting value in both the db and the global variable.
877
 *
878
 * @since 1.0
879
 *
880
 * @global       $give_options
881
 *
882
 * @param string $key The Key to delete
883
 *
884
 * @return boolean True if updated, false if not.
885
 */
886
function give_delete_option( $key = '' ) {
887
888
	// If no key, exit
889
	if ( empty( $key ) ) {
890
		return false;
891
	}
892
893
	// First let's grab the current settings
894
	$options = get_option( 'give_settings' );
895
896
	// Next let's try to update the value
897
	if ( isset( $options[ $key ] ) ) {
898
		unset( $options[ $key ] );
899
	}
900
901
	$did_update = update_option( 'give_settings', $options );
902
903
	// If it updated, let's update the global variable
904
	if ( $did_update ) {
905
		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...
906
		$give_options = $options;
907
	}
908
909
	return $did_update;
910
}
911
912
913
/**
914
 * Get Settings
915
 *
916
 * Retrieves all Give plugin settings
917
 *
918
 * @since 1.0
919
 * @return array Give settings
920
 */
921
function give_get_settings() {
922
923
	$settings = get_option( 'give_settings' );
924
925
	return (array) apply_filters( 'give_get_settings', $settings );
926
927
}
928
929
930
/**
931
 * Give Settings Array Insert.
932
 *
933
 * Allows other Add-ons and plugins to insert Give settings at a desired position.
934
 *
935
 * @since      1.3.5
936
 *
937
 * @param $array
938
 * @param $position |int|string Expects an array key or 'id' of the settings field to appear after
939
 * @param $insert   |array a valid array of options to insert
940
 *
941
 * @return array
942
 */
943
function give_settings_array_insert( $array, $position, $insert ) {
944
	if ( is_int( $position ) ) {
945
		array_splice( $array, $position, 0, $insert );
946
	} else {
947
948
		foreach ( $array as $index => $subarray ) {
949
			if ( isset( $subarray['id'] ) && $subarray['id'] == $position ) {
950
				$pos = $index;
951
			}
952
		}
953
954
		if ( ! isset( $pos ) ) {
955
			return $array;
956
		}
957
958
		$array = array_merge(
959
			array_slice( $array, 0, $pos ),
960
			$insert,
961
			array_slice( $array, $pos )
962
		);
963
	}
964
965
	return $array;
966
}
967
968
969
/**
970
 * Gateways Callback
971
 *
972
 * Renders gateways fields.
973
 *
974
 * @since 1.0
975
 *
976
 * @param array $field_arr
977
 * @param array $saved_values
978
 *
979
 * @return void
980
 */
981
function give_enabled_gateways_callback( $field_arr, $saved_values = array() ) {
982
983
	$id       = $field_arr['id'];
984
	$gateways = give_get_ordered_payment_gateways( give_get_payment_gateways() );
985
986
	echo '<ul class="give-checklist-fields give-payment-gatways-list">';
987
988
	foreach ( $gateways as $key => $option ) :
989
990
		if ( is_array( $saved_values ) && array_key_exists( $key, $saved_values ) ) {
991
			$enabled = '1';
992
		} else {
993
			$enabled = null;
994
		}
995
996
		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;';
997
		echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
998
999
	endforeach;
1000
1001
	echo '</ul>';
1002
}
1003
1004
/**
1005
 * Gateways Callback (drop down)
1006
 *
1007
 * Renders gateways select menu
1008
 *
1009
 * @since  1.0
1010
 *
1011
 * @param  array $field_arr
1012
 * @param  array $saved_value
1013
 *
1014
 * @return void
1015
 */
1016
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...
1017
	$id          = $field_arr['id'];
1018
	$gateways    = give_get_enabled_payment_gateways();
1019
	$saved_value = give_get_default_gateway( null );
1020
1021
	echo '<select class="give-select" name="' . $id . '" id="' . $id . '">';
1022
1023
	foreach ( $gateways as $key => $option ) :
1024
		$selected = isset( $saved_value ) ? selected( $key, $saved_value, false ) : '';
1025
		echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1026
	endforeach;
1027
1028
	echo '</select>';
1029
1030
}
1031
1032
/**
1033
 * Give Title
1034
 *
1035
 * Renders custom section titles output; Really only an  because CMB2's output is a bit funky
1036
 *
1037
 * @since 1.0
1038
 *
1039
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1040
 *
1041
 * @return void
1042
 */
1043
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...
1044
1045
	$id                = $field_type_object->field->args['id'];
1046
	$title             = $field_type_object->field->args['name'];
1047
	$field_description = $field_type_object->field->args['desc'];
1048
1049
	echo '<hr>' . $field_description;
1050
1051
}
1052
1053
/**
1054
 * Give Description
1055
 *
1056
 * Renders custom description text which any plugin can use to output content, html, php, etc.
1057
 *
1058
 * @since      1.3.5
1059
 *
1060
 * @param       $field_object , $escaped_value, $object_id, $object_type, $field_type_object
1061
 *
1062
 * @return void
1063
 */
1064
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...
1065
1066
	$id                = $field_type_object->field->args['id'];
1067
	$title             = $field_type_object->field->args['name'];
1068
	$field_description = $field_type_object->field->args['desc'];
1069
1070
	echo $field_description;
1071
1072
}
1073
1074
/**
1075
 * Gets a number of posts and displays them as options
1076
 *
1077
 * @param  array $query_args Optional. Overrides defaults.
1078
 * @param  bool  $force      Force the pages to be loaded even if not on settings
1079
 *
1080
 * @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
1081
 * @return array An array of options that matches the CMB2 options array
1082
 */
1083
function give_cmb2_get_post_options( $query_args, $force = false ) {
1084
1085
	$post_options = array( '' => '' ); // Blank option
1086
1087
	if ( ( ! isset( $_GET['page'] ) || 'give-settings' != $_GET['page'] ) && ! $force ) {
1088
		return $post_options;
1089
	}
1090
1091
	$args = wp_parse_args( $query_args, array(
1092
		'post_type'   => 'page',
1093
		'numberposts' => 10,
1094
	) );
1095
1096
	$posts = get_posts( $args );
1097
1098
	if ( $posts ) {
1099
		foreach ( $posts as $post ) {
1100
1101
			$post_options[ $post->ID ] = $post->post_title;
1102
1103
		}
1104
	}
1105
1106
	return $post_options;
1107
}
1108
1109
1110
/**
1111
 * Featured Image Sizes
1112
 *
1113
 * Outputs an array for the "Featured Image Size" option found under Settings > Display Options.
1114
 *
1115
 * @since 1.4
1116
 *
1117
 * @global $_wp_additional_image_sizes
1118
 *
1119
 * @return array $sizes
1120
 */
1121
function give_get_featured_image_sizes() {
1122
	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...
1123
	$sizes     = array();
1124
	$get_sizes = get_intermediate_image_sizes();
1125
1126
	// check whether intermediate image sizes exist first
1127
	if ( empty( $get_sizes ) ) {
1128
		$get_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
1129
	}
1130
1131
    // This will help us to filter special characters from a string
1132
    $filter_slug_items = array( '_', '-' );
1133
1134
	foreach ( $get_sizes as $_size ) {
1135
1136
        // Check for height of image having 0 or 9999 in pixels to label them as responsive
1137
        $is_image_size_responsive = false;
1138
        if( 0 == get_option( "{$_size}_size_h" ) || 9999 == get_option( "{$_size}_size_h" ) ){
1139
            $is_image_size_responsive = true;
1140
        }
1141
1142
        // Converting image size slug to title case
1143
        $sizes[ $_size ] = give_slug_to_title( $_size, $filter_slug_items );
1144
1145
        if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
1146
 			$sizes[ $_size ] .= ' (' . get_option( "{$_size}_size_w" ) . 'x' . get_option( "{$_size}_size_h" );
1147
 		} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
1148
 			$sizes[ $_size ] .= ' (' . $_wp_additional_image_sizes[ $_size ]['width'] . 'x' . $_wp_additional_image_sizes[ $_size ]['height'];
1149
 		}
1150
1151
        // Based on the above image height check, label the respective resolution as responsive
1152
        if($is_image_size_responsive){
1153
            $sizes[ $_size ] .= ' - responsive';
1154
        }
1155
        $sizes[ $_size ] .= ')';
1156
1157
	}
1158
1159
	return apply_filters( 'give_get_featured_image_sizes', $sizes );
1160
}
1161
1162
1163
/**
1164
 *  Slug to Title
1165
 *
1166
 *  Converts a string with hyphen(-) or underscores(_) or any special character to a string with Title case
1167
 *
1168
 *  @since 1.8.8
1169
 *
1170
 *  @params $string text
1171
 *  @params $filter array
1172
 *
1173
 *  @return text $string
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1174
 */
1175
function give_slug_to_title( $string, $filters = array() ){
1176
1177
    foreach( $filters as $filter_item ){
1178
        $string = str_replace( $filter_item, ' ', $string );
1179
    }
1180
1181
    // Return updated string after converting it to title case
1182
    return ucwords( $string );
1183
1184
}
1185
1186
1187
/**
1188
 * Give License Key Callback
1189
 *
1190
 * Registers the license field callback for EDD's Software Licensing.
1191
 *
1192
 * @since       1.0
1193
 *
1194
 * @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
1195
 *
1196
 * @return void
1197
 */
1198
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...
1199
	/* @var CMB2_Types $field_type_object */
1200
1201
	$id                 = $field_type_object->field->args['id'];
1202
	$field_description  = $field_type_object->field->args['desc'];
1203
	$license            = $field_type_object->field->args['options']['license'];
1204
	$license_key        = $escaped_value;
1205
	$is_license_key     = apply_filters( 'give_is_license_key', ( is_object( $license ) && ! empty( $license ) ) );
1206
	$is_valid_license   = apply_filters( 'give_is_valid_license', ( $is_license_key && property_exists( $license, 'license' ) && 'valid' === $license->license ) );
1207
	$shortname          = $field_type_object->field->args['options']['shortname'];
1208
	$field_classes      = 'regular-text give-license-field';
1209
	$type               = empty( $escaped_value ) || ! $is_valid_license ? 'text' : 'password';
1210
	$custom_html        = '';
1211
	$messages           = array();
1212
	$class              = '';
1213
	$account_page_link  = $field_type_object->field->args['options']['account_url'];
1214
	$checkout_page_link = $field_type_object->field->args['options']['checkout_url'];
1215
	$addon_name         = $field_type_object->field->args['options']['item_name'];
1216
	$license_status     = null;
1217
	$is_in_subscription = null;
1218
1219
	// By default query on edd api url will return license object which contain status and message property, this can break below functionality.
1220
	// To combat that check if status is set to error or not, if yes then set $is_license_key to false.
1221
	if ( $is_license_key && property_exists( $license, 'status' ) && 'error' === $license->status ) {
1222
		$is_license_key = false;
1223
	}
1224
1225
	// Check if current license is part of subscription or not.
1226
	$subscriptions = get_option( 'give_subscriptions' );
1227
1228
	if ( $is_license_key && $subscriptions ) {
1229
		foreach ( $subscriptions as $subscription ) {
1230
			if ( in_array( $license_key, $subscription['licenses'] ) ) {
1231
				$is_in_subscription = $subscription['id'];
1232
				break;
1233
			}
1234
		}
1235
	}
1236
1237
	if ( $is_license_key ) {
1238
		if ( $is_in_subscription ) {
1239
			$subscription_expires = strtotime( $subscriptions[ $is_in_subscription ]['expires'] );
1240
			$subscription_status  = __( 'renew', 'give' );
1241
1242
			if ( ( 'active' !== $subscriptions[ $is_in_subscription ]['status'] ) ) {
1243
				$subscription_status = __( 'expire', 'give' );
1244
			}
1245
1246
			if ( $subscription_expires < current_time( 'timestamp', 1 ) ) {
1247
				$messages[]     = sprintf(
1248
					__( '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' ),
1249
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1250
					$subscriptions[ $is_in_subscription ]['payment_id'],
1251
					$checkout_page_link . '?edd_license_key=' . $subscriptions[ $is_in_subscription ]['license_key'] . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1252
				);
1253
				$license_status = 'license-expired';
1254
			} elseif ( strtotime( '- 7 days', $subscription_expires ) < current_time( 'timestamp', 1 ) ) {
1255
				$messages[]     = sprintf(
1256
					__( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s in %4$s.', 'give' ),
1257
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1258
					$subscriptions[ $is_in_subscription ]['payment_id'],
1259
					$subscription_status,
1260
					human_time_diff( current_time( 'timestamp', 1 ), strtotime( $subscriptions[ $is_in_subscription ]['expires'] ) )
1261
				);
1262
				$license_status = 'license-expires-soon';
1263
			} else {
1264
				$messages[]     = sprintf(
1265
					__( 'Your subscription (<a href="%1$s" target="_blank">#%2$d</a>) will %3$s on %4$s.', 'give' ),
1266
					urldecode( $subscriptions[ $is_in_subscription ]['invoice_url'] ),
1267
					$subscriptions[ $is_in_subscription ]['payment_id'],
1268
					$subscription_status,
1269
					date_i18n( get_option( 'date_format' ), strtotime( $subscriptions[ $is_in_subscription ]['expires'], current_time( 'timestamp' ) ) )
1270
				);
1271
				$license_status = 'license-expiration-date';
1272
			}
1273
		} elseif ( empty( $license->success ) && property_exists( $license, 'error' ) ) {
1274
1275
			// activate_license 'invalid' on anything other than valid, so if there was an error capture it
1276
			switch ( $license->error ) {
1277
				case 'expired' :
1278
					$class          = $license->error;
1279
					$messages[]     = sprintf(
1280
						__( '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' ),
1281
						date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1282
						$checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired'
1283
					);
1284
					$license_status = 'license-' . $class;
1285
					break;
1286
1287
				case 'missing' :
1288
					$class          = $license->error;
1289
					$messages[]     = sprintf(
1290
						__( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'give' ),
1291
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=missing'
1292
					);
1293
					$license_status = 'license-' . $class;
1294
					break;
1295
1296
				case 'invalid' :
1297
					$class          = $license->error;
1298
					$messages[]     = sprintf(
1299
						__( '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' ),
1300
						$addon_name,
1301
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1302
					);
1303
					$license_status = 'license-' . $class;
1304
					break;
1305
1306
				case 'site_inactive' :
1307
					$class          = $license->error;
1308
					$messages[]     = sprintf(
1309
						__( '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' ),
1310
						$addon_name,
1311
						$account_page_link . '?utm_campaign=admin&utm_source=licenses&utm_medium=invalid'
1312
					);
1313
					$license_status = 'license-' . $class;
1314
					break;
1315
1316
				case 'item_name_mismatch' :
1317
					$class          = $license->error;
1318
					$messages[]     = sprintf( __( 'This license %1$s does not belong to %2$s.', 'give' ), $license_key, $addon_name );
1319
					$license_status = 'license-' . $class;
1320
					break;
1321
1322
				case 'no_activations_left':
1323
					$class          = $license->error;
1324
					$messages[]     = sprintf( __( 'Your license key has reached it\'s activation limit. <a href="%s">View possible upgrades</a> now.', 'give' ), $account_page_link );
1325
					$license_status = 'license-' . $class;
1326
					break;
1327
			}
1328
		} else {
1329
			switch ( $license->license ) {
1330
				case 'valid' :
1331
				default:
1332
					$class      = 'valid';
1333
					$now        = current_time( 'timestamp' );
1334
					$expiration = strtotime( $license->expires, current_time( 'timestamp' ) );
1335
1336
					if ( 'lifetime' === $license->expires ) {
1337
						$messages[]     = __( 'License key never expires.', 'give' );
1338
						$license_status = 'license-lifetime-notice';
1339
					} elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
1340
						$messages[]     = sprintf(
1341
							__( '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' ),
1342
							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ),
1343
							$checkout_page_link . '?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=renew'
1344
						);
1345
						$license_status = 'license-expires-soon';
1346
					} else {
1347
						$messages[]     = sprintf(
1348
							__( 'Your license key expires on %s.', 'give' ),
1349
							date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
1350
						);
1351
						$license_status = 'license-expiration-date';
1352
					}
1353
					break;
1354
			}
1355
		}
1356
	} else {
1357
		$messages[]     = sprintf(
1358
			__( 'To receive updates, please enter your valid %s license key.', 'give' ),
1359
			$addon_name
1360
		);
1361
		$license_status = 'inactive';
1362
	}
1363
1364
	// Add class for input field if license is active.
1365
	if ( $is_valid_license ) {
1366
		$field_classes .= ' give-license-active';
1367
	}
1368
1369
	// Get input field html.
1370
	$input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\">";
1371
1372
	// If license is active so show deactivate button.
1373
	if ( $is_valid_license ) {
1374
		// Get input field html.
1375
		$input_field_html = "<input type=\"{$type}\" name=\"{$id}\" class=\"{$field_classes}\" value=\"{$license_key}\" readonly=\"readonly\">";
1376
1377
		$custom_html = '<input type="submit" class="button button-small give-license-deactivate" name="' . $id . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'give' ) . '"/>';
1378
1379
	}
1380
1381
	// Field description.
1382
	$custom_html .= '<label for="give_settings[' . $id . ']"> ' . $field_description . '</label>';
1383
1384
	// If no messages found then inform user that to get updated in future register yourself.
1385
	if ( empty( $messages ) ) {
1386
		$messages[] = apply_filters( "{$shortname}_default_addon_notice", __( 'To receive updates, please enter your valid license key.', 'give' ) );
1387
	}
1388
1389
	foreach ( $messages as $message ) {
1390
		$custom_html .= '<div class="give-license-status-notice give-' . $license_status . '">';
1391
		$custom_html .= '<p>' . $message . '</p>';
1392
		$custom_html .= '</div>';
1393
	}
1394
1395
	// Field html.
1396
	$custom_html = apply_filters( 'give_license_key_field_html', $input_field_html . $custom_html, $field_type_object );
1397
1398
	// Nonce.
1399
	wp_nonce_field( $id . '-nonce', $id . '-nonce' );
1400
1401
	// Print field html.
1402
	echo "<div class=\"give-license-key\"><label for=\"{$id}\">{$addon_name }</label></div><div class=\"give-license-block\">{$custom_html}</div>";
1403
}
1404
1405
1406
/**
1407
 * Display the API Keys
1408
 *
1409
 * @since       1.0
1410
 * @return      void
1411
 */
1412
function give_api_callback() {
1413
1414
	if ( ! current_user_can( 'manage_give_settings' ) ) {
1415
		return;
1416
	}
1417
1418
	/**
1419
	 * Fires before displaying API keys.
1420
	 *
1421
	 * @since 1.0
1422
	 */
1423
	do_action( 'give_tools_api_keys_before' );
1424
1425
	require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
1426
1427
	$api_keys_table = new Give_API_Keys_Table();
1428
	$api_keys_table->prepare_items();
1429
	$api_keys_table->display();
1430
	?>
1431
	<span class="cmb2-metabox-description api-description">
1432
		<?php echo sprintf(
1433
			/* translators: 1: http://docs.givewp.com/api 2: http://docs.givewp.com/addon-zapier */
1434
			__( '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' ),
1435
			esc_url( 'http://docs.givewp.com/api' ),
1436
			esc_url( 'http://docs.givewp.com/addon-zapier' )
1437
		); ?>
1438
	</span>
1439
	<?php
1440
1441
	/**
1442
	 * Fires after displaying API keys.
1443
	 *
1444
	 * @since 1.0
1445
	 */
1446
	do_action( 'give_tools_api_keys_after' );
1447
}
1448
1449
add_action( 'give_settings_tab_api_keys', 'give_api_callback' );
1450
1451
/**
1452
 * Hook Callback
1453
 *
1454
 * Adds a do_action() hook in place of the field.
1455
 *
1456
 * @since 1.0
1457
 *
1458
 * @param array $args Arguments passed by the setting
1459
 *
1460
 * @return void
1461
 */
1462
function give_hook_callback( $args ) {
1463
1464
	$id = $args['id'];
1465
1466
	/**
1467
	 * Fires in give field.
1468
	 *
1469
	 * @since 1.0
1470
	 */
1471
	do_action( "give_{$id}" );
1472
1473
}
1474
1475
1476
/**
1477
 * Check if radio(enabled/disabled) and checkbox(on) is active or not.
1478
 *
1479
 * @since  1.8
1480
 *
1481
 * @param  string $value
1482
 * @param  string $compare_with
1483
 *
1484
 * @return bool
1485
 */
1486
function give_is_setting_enabled( $value, $compare_with = null ) {
1487
	if ( ! is_null( $compare_with ) ) {
1488
1489
		if ( is_array( $compare_with ) ) {
1490
			// Output.
1491
			return in_array( $value, $compare_with );
1492
		}
1493
1494
		// Output.
1495
		return ( $value === $compare_with );
1496
	}
1497
1498
	// Backward compatibility: From version 1.8 most of setting is modified to enabled/disabled
1499
	// Output.
1500
	return ( in_array( $value, array( 'enabled', 'on', 'yes' ) ) ? true : false );
1501
}
1502