Test Failed
Push — hotfix/license ( b489e1 )
by Ravinder
05:03
created

donors.php ➔ give_render_donor_view()   D

Complexity

Conditions 13
Paths 128

Size

Total Lines 81
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 52
nc 128
nop 2
dl 0
loc 81
rs 4.6762
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Donors.
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Donors
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Donors Page.
19
 *
20
 * Renders the donors page contents.
21
 *
22
 * @since  1.0
23
 * @return void
24
 */
25
function give_donors_page() {
26
	$default_views  = give_donor_views();
27
	$requested_view = isset( $_GET['view'] ) ? sanitize_text_field( $_GET['view'] ) : 'donors';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
28
	if ( array_key_exists( $requested_view, $default_views ) && function_exists( $default_views[ $requested_view ] ) ) {
29
		give_render_donor_view( $requested_view, $default_views );
30
	} else {
31
		give_donors_list();
32
	}
33
}
34
35
/**
36
 * Register the views for donor management.
37
 *
38
 * @since  1.0
39
 * @return array Array of views and their callbacks.
40
 */
41
function give_donor_views() {
42
43
	$views = array();
44
45
	return apply_filters( 'give_donor_views', $views );
46
47
}
48
49
/**
50
 * Register the tabs for donor management.
51
 *
52
 * @since  1.0
53
 * @return array Array of tabs for the donor.
54
 */
55
function give_donor_tabs() {
56
57
	$tabs = array();
58
59
	return apply_filters( 'give_donor_tabs', $tabs );
60
61
}
62
63
/**
64
 * List table of donors.
65
 *
66
 * @since  1.0
67
 * @return void
68
 */
69
function give_donors_list() {
70
	include dirname( __FILE__ ) . '/class-donor-table.php';
71
72
	$donors_table = new Give_Donor_List_Table();
73
	$donors_table->prepare_items();
74
	?>
75
	<div class="wrap">
76
		<h1 class="wp-heading-inline"><?php echo get_admin_page_title(); ?></h1>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_admin_page_title'
Loading history...
77
		<?php
78
		/**
79
		 * Fires in donors screen, above the table.
80
		 *
81
		 * @since 1.0
82
		 */
83
		do_action( 'give_donors_table_top' );
84
		?>
85
86
		<hr class="wp-header-end">
87
88
		<form id="give-donors-filter" method="get" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
89
			<?php
90
			$donors_table->search_box( __( 'Search Donors', 'give' ), 'give-donors' );
91
			$donors_table->display();
92
			?>
93
			<input type="hidden" name="post_type" value="give_forms" />
94
			<input type="hidden" name="page" value="give-donors" />
95
			<input type="hidden" name="view" value="donors" />
96
		</form>
97
		<?php
98
		/**
99
		 * Fires in donors screen, below the table.
100
		 *
101
		 * @since 1.0
102
		 */
103
		do_action( 'give_donors_table_bottom' );
104
		?>
105
	</div>
106
	<?php
107
}
108
109
/**
110
 * Renders the donor view wrapper.
111
 *
112
 * @since  1.0
113
 *
114
 * @param  string $view      The View being requested.
115
 * @param  array  $callbacks The Registered views and their callback functions.
116
 *
117
 * @return void
118
 */
119
function give_render_donor_view( $view, $callbacks ) {
120
121
	$render = true;
122
123
	$donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
124
125
	if ( ! current_user_can( $donor_view_role ) ) {
126
		give_set_error( 'give-no-access', __( 'You are not permitted to view this data.', 'give' ) );
127
		$render = false;
128
	}
129
130
	if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
131
		give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
132
		$render = false;
133
	}
134
135
	$donor_id          = (int) $_GET['id'];
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
136
	$reconnect_user_id = ! empty( $_GET['user_id'] ) ? (int) $_GET['user_id'] : '';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
137
	$donor             = new Give_Donor( $donor_id );
0 ignored issues
show
Documentation introduced by
$donor_id is of type integer, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
138
139
	// Reconnect User with Donor profile.
140
	if( $reconnect_user_id ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
141
		give_connect_user_donor_profile( $donor, array( 'user_id' => $reconnect_user_id ), array() );
142
	}
143
144
	if ( empty( $donor->id ) ) {
145
		give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
146
		$render = false;
147
	}
148
149
	$donor_tabs = give_donor_tabs();
150
	?>
151
152
	<div class='wrap'>
153
154
		<?php if ( give_get_errors() ) : ?>
155
			<div class="error settings-error">
156
				<?php Give()->notices->render_frontend_notices( 0 ); ?>
157
			</div>
158
		<?php endif; ?>
159
160
		<h1 class="wp-heading-inline">
161
			<?php
162
			printf(
163
			/* translators: %s: donor number */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 12.
Loading history...
164
				esc_html__( 'Donor %s', 'give' ),
165
				$donor_id
166
			);
167
			?>
168
		</h1>
169
170
		<hr class="wp-header-end">
171
		
172
		<?php if ( $donor && $render ) : ?>
173
174
			<h2 class="nav-tab-wrapper">
175
				<?php
176
				foreach ( $donor_tabs as $key => $tab ) :
177
					$active = $key === $view ? true : false;
178
					$class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
179
					printf(
180
						'<a href="%1$s" class="%2$s"><span class="dashicons %3$s"></span>%4$s</a>' . "\n",
181
						esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=' . $key . '&id=' . $donor->id ) ),
182
						esc_attr( $class ),
183
						sanitize_html_class( $tab['dashicon'] ),
184
						esc_html( $tab['title'] )
185
					);
186
				endforeach;
187
				?>
188
			</h2>
189
190
			<div id="give-donor-card-wrapper">
191
				<?php $callbacks[ $view ]( $donor ) ?>
192
			</div>
193
194
		<?php endif; ?>
195
196
	</div>
197
	<?php
198
199
}
200
201
202
/**
203
 * View a donor
204
 *
205
 * @since  1.0
206
 *
207
 * @param  Give_Donor $donor The Donor object being displayed.
208
 *
209
 * @return void
210
 */
211
function give_donor_view( $donor ) {
212
213
	$donor_edit_role   = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
214
215
	/**
216
	 * Fires in donor profile screen, above the donor card.
217
	 *
218
	 * @since 1.0
219
	 *
220
	 * @param object $donor The donor object being displayed.
221
	 */
222
	do_action( 'give_donor_card_top', $donor );
223
	?>
224
225
	<div id="donor-summary" class="info-wrapper donor-section postbox">
226
227
		<form id="edit-donor-info" method="post" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
228
229
			<div class="donor-info">
230
231
				<div class="donor-bio-header clearfix">
232
233
					<div class="avatar-wrap left" id="donor-avatar">
234
						<?php echo get_avatar( $donor->email ); ?>
235
					</div>
236
237
					<div id="donor-name-wrap" class="left">
238
						<span class="donor-id">#<?php echo $donor->id; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
239
						<span class="donor-name info-item edit-item"><input size="15" data-key="name" name="customerinfo[name]" type="text" value="<?php echo esc_attr( $donor->name ); ?>" placeholder="<?php _e( 'Donor Name', 'give' ); ?>" /></span>
240
						<span class="donor-name info-item editable"><span data-key="name"><?php echo $donor->name; ?></span></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
241
					</div>
242
					<p class="donor-since info-item">
243
						<?php _e( 'Donor since', 'give' ); ?>
244
						<?php echo date_i18n( give_date_format(), strtotime( $donor->date_created ) ) ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'date_i18n'
Loading history...
245
					</p>
246
					<?php if ( current_user_can( $donor_edit_role ) ) : ?>
247
						<a href="#" id="edit-donor" class="button info-item editable donor-edit-link"><?php _e( 'Edit Donor', 'give' ); ?></a>
248
					<?php endif; ?>
249
				</div>
250
				<!-- /donor-bio-header -->
251
252
				<div class="donor-main-wrapper">
253
254
					<table class="widefat">
255
						<tbody>
256
						<tr class="alternate">
257
							<th scope="col"><label for="tablecell"><?php _e( 'User:', 'give' ); ?></label></th>
258
							<td>
259
								<span class="donor-user-id info-item edit-item">
260
									<?php
261
262
									$user_id   = $donor->user_id > 0 ? $donor->user_id : '';
263
264
									$data_atts = array(
265
										'key'     => 'user_login',
266
										'search-type' => 'user',
267
									);
268
									$user_args = array(
269
										'name'  => 'customerinfo[user_id]',
270
										'class' => 'give-user-dropdown',
271
										'data'  => $data_atts,
272
									);
273
274
									if ( ! empty( $user_id ) ) {
275
										$userdata           = get_userdata( $user_id );
276
										$user_args['selected'] = $user_id;
277
									}
278
279
									echo Give()->html->ajax_user_search( $user_args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
280
									?>
281
								</span>
282
283
								<span class="donor-user-id info-item editable">
284
									<?php if ( ! empty( $userdata ) ) { ?>
285
										<span data-key="user_id">#<?php echo $donor->user_id . ' - ' . $userdata->display_name; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$userdata'
Loading history...
286
									<?php } else { ?>
287
										<span data-key="user_id"><?php _e( 'None', 'give' ); ?></span>
288
									<?php } ?>
289
									<?php if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ) { ?>
290
										<span class="disconnect-user">
291
 											-
292
 											<a id="disconnect-donor" href="#disconnect" aria-label="<?php _e( 'Disconnects the current user ID from this donor record.', 'give' ); ?>">
293
 												<?php _e( 'Disconnect User', 'give' ); ?>
294
											</a>
295
 										</span>
296
										<span class="view-user-profile">
297
 											|
298
 											<a id="view-user-profile" href="<?php echo 'user-edit.php?user_id=' . $donor->user_id; ?>" aria-label="<?php _e( 'View User Profile of current user ID.', 'give' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
299
 												<?php _e( 'View User Profile', 'give' ); ?>
300
											</a>
301
 										</span>
302
									<?php } ?>
303
								</span>
304
							</td>
305
						</tr>
306
						<?php if ( isset( $donor->user_id ) && $donor->user_id > 0 ) : ?>
307
308
							<tr>
309
								<th scope="col"><?php _e( 'Address:', 'give' ); ?></th>
310
								<td class="row-title">
311
312
									<div class="donor-address-wrapper">
313
314
										<?php
315
										$address  = get_user_meta( $donor->user_id, '_give_user_address', true );
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
316
										$defaults = array(
317
											'line1'   => '',
318
											'line2'   => '',
319
											'city'    => '',
320
											'state'   => '',
321
											'country' => '',
322
											'zip'     => '',
323
										);
324
325
										$address = wp_parse_args( $address, $defaults );
326
										?>
327
328
										<?php if ( ! empty( $address ) ) { ?>
329
											<span class="donor-address info-item editable">
330
												<span class="info-item" data-key="line1"><?php echo $address['line1']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
331
												<span class="info-item" data-key="line2"><?php echo $address['line2']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
332
												<span class="info-item" data-key="city"><?php echo $address['city']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
333
												<span class="info-item" data-key="state"><?php echo $address['state']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
334
												<span class="info-item" data-key="country"><?php echo $address['country']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
335
												<span class="info-item" data-key="zip"><?php echo $address['zip']; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
336
											</span>
337
										<?php }
338
339
										// For country.
340
										$selected_country = $address['country'];
341
										$countries = give_get_country_list();
342
343
										// For State.
344
										$selected_state = give_get_state();
345
										$states         = give_get_states( $selected_country );
346
										$selected_state = ( isset( $address['state'] ) ? $address['state'] : $selected_state );
347
348
										// Get the country list that does not have any states init.
349
										$no_states_country = give_no_states_country_list();
350
										?>
351
										<span class="donor-address info-item edit-item">
352
											<select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country give-select edit-item">
353
												<?php
354 View Code Duplication
												foreach ( $countries as $country_code => $country ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
355
													echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$country'
Loading history...
356
												}
357
												?>
358
											</select>
359
											<input class="info-item" type="text" data-key="line1" name="customerinfo[line1]" placeholder="<?php _e( 'Address 1', 'give' ); ?>" value="<?php echo $address['line1']; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
360
											<input class="info-item" type="text" data-key="line2" name="customerinfo[line2]" placeholder="<?php _e( 'Address 2', 'give' ); ?>" value="<?php echo $address['line2']; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
361
											<?php
362
											if ( ! empty( $states ) ) {
363
												?>
364
												<select data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-select info-item">
365
													<?php
366 View Code Duplication
													foreach ( $states as $state_code => $state ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
367
														echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$state_code'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$state'
Loading history...
368
													}
369
													?>
370
												</select>
371
												<?php
372
											} else {
373
												?>
374
												<input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ? 'give-hidden' : '' ); ?>" placeholder="<?php _e( 'State / Province / County', 'give' ); ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
375
												<?php
376
											}
377
											?>
378
											<input class="info-item" type="text" data-key="city" name="customerinfo[city]" placeholder="<?php _e( 'City', 'give' ); ?>" value="<?php echo $address['city']; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
379
											<input class="info-item" type="text" data-key="zip" name="customerinfo[zip]" placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>" value="<?php echo $address['zip']; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$address'
Loading history...
380
										</span>
381
382
									</div>
383
								</td>
384
							</tr>
385
						<?php endif; ?>
386
						</tbody>
387
					</table>
388
389
				</div>
390
391
			</div>
392
393
			<span id="donor-edit-actions" class="edit-item">
394
				<input type="hidden" data-key="id" name="customerinfo[id]" value="<?php echo $donor->id; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
395
				<?php wp_nonce_field( 'edit-donor', '_wpnonce', false, true ); ?>
396
				<input type="hidden" name="give_action" value="edit-donor" />
397
				<input type="submit" id="give-edit-donor-save" class="button-secondary" value="<?php _e( 'Update Donor', 'give' ); ?>" />
398
				<a id="give-edit-donor-cancel" href="" class="delete"><?php _e( 'Cancel', 'give' ); ?></a>
399
			</span>
400
401
		</form>
402
403
	</div>
404
405
	<?php
406
	/**
407
	 * Fires in donor profile screen, above the stats list.
408
	 *
409
	 * @since 1.0
410
	 *
411
	 * @param object $donor The donor object being displayed.
412
	 */
413
	do_action( 'give_donor_before_stats', $donor );
414
	?>
415
416
	<div id="donor-stats-wrapper" class="donor-section postbox clear">
417
		<ul>
418
			<li>
419
				<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor->id ) ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
420
					<span class="dashicons dashicons-heart"></span>
421
					<?php
422
					// Completed Donations.
423
					$completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $donor->purchase_count, 'give' ), $donor->purchase_count );
424
					echo apply_filters( 'give_donor_completed_donations', $completed_donations_text, $donor );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
425
					?>
426
				</a>
427
			</li>
428
			<li>
429
				<span class="dashicons dashicons-chart-area"></span>
430
				<?php echo give_currency_filter( give_format_amount( $donor->purchase_value, array( 'sanitize' => false ) ) ); ?> <?php _e( 'Lifetime Donations', 'give' ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_currency_filter'
Loading history...
431
			</li>
432
			<?php
433
			/**
434
			 * Fires in donor profile screen, in the stats list.
435
			 *
436
			 * Allows you to add more list items to the stats list.
437
			 *
438
			 * @since 1.0
439
			 *
440
			 * @param object $donor The donor object being displayed.
441
			 */
442
			do_action( 'give_donor_stats_list', $donor );
443
			?>
444
		</ul>
445
	</div>
446
447
	<?php
448
	/**
449
	 * Fires in donor profile screen, above the tables wrapper.
450
	 *
451
	 * @since 1.0
452
	 *
453
	 * @param object $donor The donor object being displayed.
454
	 */
455
	do_action( 'give_donor_before_tables_wrapper', $donor );
456
	?>
457
458
	<div id="donor-tables-wrapper" class="donor-section">
459
460
		<?php
461
		/**
462
		 * Fires in donor profile screen, above the tables.
463
		 *
464
		 * @since 1.0
465
		 *
466
		 * @param object $donor The donor object being displayed.
467
		 */
468
		do_action( 'give_donor_before_tables', $donor );
469
		?>
470
471
		<h3><?php _e( 'Donor Emails', 'give' ); ?></h3>
472
473
		<table class="wp-list-table widefat striped emails">
474
			<thead>
475
			<tr>
476
				<th><?php _e( 'Email', 'give' ); ?></th>
477
				<th><?php _e( 'Actions', 'give' ); ?></th>
478
			</tr>
479
			</thead>
480
481
			<tbody>
482
			<?php if ( ! empty( $donor->emails ) ) { ?>
483
484
				<?php foreach ( $donor->emails as $key => $email ) : ?>
485
					<tr data-key="<?php echo $key; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
486
						<td>
487
							<?php echo $email; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$email'
Loading history...
488
							<?php if ( 'primary' === $key ) : ?>
489
								<span class="dashicons dashicons-star-filled primary-email-icon"></span>
490
							<?php endif; ?>
491
						</td>
492
						<td>
493
							<?php if ( 'primary' !== $key ) : ?>
494
								<?php
495
								$base_url    = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id );
496
								$promote_url = wp_nonce_url( add_query_arg( array(
497
									'email' => rawurlencode( $email ),
498
									'give_action' => 'set_donor_primary_email',
499
								), $base_url ), 'give-set-donor-primary-email' );
500
								$remove_url  = wp_nonce_url( add_query_arg( array(
501
									'email' => rawurlencode( $email ),
502
									'give_action' => 'remove_donor_email',
503
								), $base_url ), 'give-remove-donor-email' );
504
								?>
505
								<a href="<?php echo $promote_url; ?>"><?php _e( 'Make Primary', 'give' ); ?></a>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$promote_url'
Loading history...
506
								&nbsp;|&nbsp;
507
								<a href="<?php echo $remove_url; ?>" class="delete"><?php _e( 'Remove', 'give' ); ?></a>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$remove_url'
Loading history...
508
							<?php endif; ?>
509
						</td>
510
					</tr>
511
				<?php endforeach; ?>
512
513
				<tr class="add-donor-email-row">
514
					<td colspan="2" class="add-donor-email-td">
515
						<div class="add-donor-email-wrapper">
516
							<input type="hidden" name="donor-id" value="<?php echo $donor->id; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
517
							<?php wp_nonce_field( 'give_add_donor_email', 'add_email_nonce', false, true ); ?>
518
							<input type="email" name="additional-email" value="" placeholder="<?php _e( 'Email Address', 'give' ); ?>" />&nbsp;
519
							<input type="checkbox" name="make-additional-primary" value="1" id="make-additional-primary" />&nbsp;<label for="make-additional-primary"><?php _e( 'Make Primary', 'give' ); ?></label>
520
							<button class="button-secondary give-add-donor-email" id="add-donor-email"><?php _e( 'Add Email', 'give' ); ?></button>
521
							<span class="spinner"></span>
522
						</div>
523
						<div class="notice-wrap"></div>
524
					</td>
525
				</tr>
526
			<?php } else { ?>
527
				<tr><td colspan="2"><?php _e( 'No Emails Found', 'give' ); ?></td></tr>
528
			<?php }// End if().
529
			?>
530
			</tbody>
531
		</table>
532
533
		<h3><?php _e( 'Recent Donations', 'give' ); ?></h3>
534
		<?php
535
		$payment_ids = explode( ',', $donor->payment_ids );
536
		$payments    = give_get_payments( array(
537
			'post__in' => $payment_ids,
538
		) );
539
		$payments    = array_slice( $payments, 0, 10 );
540
		?>
541
		<table class="wp-list-table widefat striped payments">
542
			<thead>
543
			<tr>
544
				<th scope="col"><?php _e( 'ID', 'give' ); ?></th>
545
				<th scope="col"><?php _e( 'Amount', 'give' ); ?></th>
546
				<th scope="col"><?php _e( 'Date', 'give' ); ?></th>
547
				<th scope="col"><?php _e( 'Status', 'give' ); ?></th>
548
				<th scope="col"><?php _e( 'Actions', 'give' ); ?></th>
549
			</tr>
550
			</thead>
551
			<tbody>
552
			<?php if ( ! empty( $payments ) ) { ?>
553
				<?php foreach ( $payments as $payment ) : ?>
554
					<tr>
555
						<td><?php echo $payment->ID; ?></td>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$payment'
Loading history...
556
						<td><?php echo give_payment_amount( $payment->ID ); ?></td>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_payment_amount'
Loading history...
557
						<td><?php echo date_i18n( give_date_format(), strtotime( $payment->post_date ) ); ?></td>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'date_i18n'
Loading history...
558
						<td><?php echo give_get_payment_status( $payment, true ); ?></td>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_payment_status'
Loading history...
559
						<td>
560
							<?php
561
							printf(
562
								'<a href="%1$s" aria-label="%2$s">%3$s</a>',
563
								admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment->ID ),
564
								sprintf(
565
								/* translators: %s: Donation ID */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 36 spaces, but found 32.
Loading history...
566
									esc_attr__( 'View Donation %s.', 'give' ),
567
									$payment->ID
568
								),
569
								__( 'View Donation', 'give' )
570
							);
571
							?>
572
573
							<?php
574
							/**
575
							 * Fires in donor profile screen, in the recent donations tables action links.
576
							 *
577
							 * Allows you to add more action links for each donation, after the 'View Donation' action link.
578
							 *
579
							 * @since 1.0
580
							 *
581
							 * @param object $donor The donor object being displayed.
582
							 * @param object $payment  The payment object being displayed.
583
							 */
584
							do_action( 'give_donor_recent_purchases_actions', $donor, $payment );
585
							?>
586
						</td>
587
					</tr>
588
				<?php endforeach; ?>
589
			<?php } else { ?>
590
				<tr>
591
					<td colspan="5"><?php _e( 'No donations found.', 'give' ); ?></td>
592
				</tr>
593
			<?php }// End if().
594
			?>
595
			</tbody>
596
		</table>
597
598
		<h3><?php _e( 'Completed Forms', 'give' ); ?></h3>
599
		<?php
600
		$donations = give_get_users_completed_donations( $donor->email );
601
		?>
602
		<table class="wp-list-table widefat striped donations">
603
			<thead>
604
			<tr>
605
				<th scope="col"><?php _e( 'Form', 'give' ); ?></th>
606
				<th scope="col" width="120px"><?php _e( 'Actions', 'give' ); ?></th>
607
			</tr>
608
			</thead>
609
			<tbody>
610
			<?php if ( ! empty( $donations ) ) { ?>
611
				<?php foreach ( $donations as $donation ) : ?>
0 ignored issues
show
Bug introduced by
The expression $donations of type boolean|object is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
612
					<tr>
613
						<td><?php echo $donation->post_title; ?></td>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donation'
Loading history...
614
						<td>
615
							<?php
616
							printf(
617
								'<a href="%1$s" aria-label="%2$s">%3$s</a>',
618
								esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ),
619
								sprintf(
620
								/* translators: %s: form name */
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 36 spaces, but found 32.
Loading history...
621
									esc_attr__( 'View Form %s.', 'give' ),
622
									$donation->post_title
623
								),
624
								__( 'View Form', 'give' )
625
							);
626
							?>
627
						</td>
628
					</tr>
629
				<?php endforeach; ?>
630
			<?php } else { ?>
631
				<tr>
632
					<td colspan="2"><?php _e( 'No completed donations found.', 'give' ); ?></td>
633
				</tr>
634
			<?php } ?>
635
			</tbody>
636
		</table>
637
638
		<?php
639
		/**
640
		 * Fires in donor profile screen, below the tables.
641
		 *
642
		 * @since 1.0
643
		 *
644
		 * @param object $donor The donor object being displayed.
645
		 */
646
		do_action( 'give_donor_after_tables', $donor );
647
		?>
648
649
	</div>
650
651
	<?php
652
	/**
653
	 * Fires in donor profile screen, below the donor card.
654
	 *
655
	 * @since 1.0
656
	 *
657
	 * @param object $donor The donor object being displayed.
658
	 */
659
	do_action( 'give_donor_card_bottom', $donor );
660
661
}
662
663
/**
664
 * View the notes of a donor.
665
 *
666
 * @since  1.0
667
 *
668
 * @param  object $donor The donor object being displayed.
669
 *
670
 * @return void
671
 */
672
function give_donor_notes_view( $donor ) {
673
674
	$paged          = isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) ? $_GET['paged'] : 1;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
675
	$paged          = absint( $paged );
676
	$note_count     = $donor->get_notes_count();
677
	$per_page       = apply_filters( 'give_donor_notes_per_page', 20 );
678
	$total_pages    = ceil( $note_count / $per_page );
679
	$donor_notes = $donor->get_notes( $per_page, $paged );
680
	?>
681
682
	<div id="donor-notes-wrapper">
683
		<div class="donor-notes-header">
684
			<?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
685
		</div>
686
		<h3><?php _e( 'Notes', 'give' ); ?></h3>
687
688
		<?php if ( 1 == $paged ) : ?>
689
			<div style="display: block; margin-bottom: 55px;">
690
				<form id="give-add-donor-note" method="post" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor->id ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
691
					<textarea id="donor-note" name="donor_note" class="donor-note-input" rows="10"></textarea>
692
					<br />
693
					<input type="hidden" id="donor-id" name="customer_id" value="<?php echo $donor->id; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
694
					<input type="hidden" name="give_action" value="add-donor-note" />
695
					<?php wp_nonce_field( 'add-donor-note', 'add_donor_note_nonce', true, true ); ?>
696
					<input id="add-donor-note" class="right button-primary" type="submit" value="Add Note" />
697
				</form>
698
			</div>
699
		<?php endif; ?>
700
701
		<?php
702
		$pagination_args = array(
703
			'base'     => '%_%',
704
			'format'   => '?paged=%#%',
705
			'total'    => $total_pages,
706
			'current'  => $paged,
707
			'show_all' => true,
708
		);
709
710
		echo paginate_links( $pagination_args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'paginate_links'
Loading history...
711
		?>
712
713
		<div id="give-donor-notes" class="postbox">
714
			<?php if ( count( $donor_notes ) > 0 ) { ?>
715
				<?php foreach ( $donor_notes as $key => $note ) : ?>
716
					<div class="donor-note-wrapper dashboard-comment-wrap comment-item">
717
					<span class="note-content-wrap">
718
						<?php echo stripslashes( $note ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'stripslashes'
Loading history...
719
					</span>
720
					</div>
721
				<?php endforeach; ?>
722
			<?php } else { ?>
723
				<div class="give-no-donor-notes">
724
					<?php _e( 'No donor notes found.', 'give' ); ?>
725
				</div>
726
			<?php } ?>
727
		</div>
728
729
		<?php echo paginate_links( $pagination_args ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'paginate_links'
Loading history...
730
731
	</div>
732
733
	<?php
734
}
735
736
/**
737
 * Thw donor delete view.
738
 *
739
 * @since  1.0
740
 *
741
 * @param  object $donor The donor object being displayed.
742
 *
743
 * @return void
744
 */
745
function give_donor_delete_view( $donor ) {
746
747
	$donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
0 ignored issues
show
Unused Code introduced by
$donor_edit_role is not used, you could remove the assignment.

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

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

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

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

Loading history...
748
749
	/**
750
	 * Fires in donor delete screen, above the content.
751
	 *
752
	 * @since 1.0
753
	 *
754
	 * @param object $donor The donor object being displayed.
755
	 */
756
	do_action( 'give_donor_delete_top', $donor );
757
	?>
758
759
	<div class="info-wrapper donor-section">
760
761
		<form id="delete-donor" method="post" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor->id ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
762
763
			<div class="donor-notes-header">
764
				<?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
765
			</div>
766
767
768
			<div class="donor-info delete-donor">
769
770
				<span class="delete-donor-options">
771
					<p>
772
						<?php echo Give()->html->checkbox( array(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
773
							'name' => 'give-donor-delete-confirm',
774
						) ); ?>
775
						<label for="give-donor-delete-confirm"><?php _e( 'Are you sure you want to delete this donor?', 'give' ); ?></label>
776
					</p>
777
778
					<p>
779
						<?php echo Give()->html->checkbox( array(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
780
							'name'    => 'give-donor-delete-records',
781
							'options' => array(
782
								'disabled' => true,
783
							),
784
						) ); ?>
785
						<label for="give-donor-delete-records"><?php _e( 'Delete all associated donations and records?', 'give' ); ?></label>
786
					</p>
787
788
					<?php
789
					/**
790
					 * Fires in donor delete screen, bellow the delete inputs.
791
					 *
792
					 * Allows you to add custom delete inputs.
793
					 *
794
					 * @since 1.0
795
					 *
796
					 * @param object $donor The donor object being displayed.
797
					 */
798
					do_action( 'give_donor_delete_inputs', $donor );
799
					?>
800
				</span>
801
802
				<span id="donor-edit-actions">
803
					<input type="hidden" name="customer_id" value="<?php echo $donor->id; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$donor'
Loading history...
804
					<?php wp_nonce_field( 'delete-donor', '_wpnonce', false, true ); ?>
805
					<input type="hidden" name="give_action" value="delete-donor" />
806
					<input type="submit" disabled="disabled" id="give-delete-donor" class="button-primary" value="<?php _e( 'Delete Donor', 'give' ); ?>" />
807
					<a id="give-delete-donor-cancel" href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ); ?>" class="delete"><?php _e( 'Cancel', 'give' ); ?></a>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
808
				</span>
809
810
			</div>
811
812
		</form>
813
	</div>
814
815
	<?php
816
	/**
817
	 * Fires in donor delete screen, bellow the content.
818
	 *
819
	 * @since 1.0
820
	 *
821
	 * @param object $donor The donor object being displayed.
822
	 */
823
	do_action( 'give_donor_delete_bottom', $donor );
824
}
825