Test Failed
Push — issues/2147 ( f99407 )
by Ravinder
04:53
created

donors.php ➔ give_render_donor_view()   D

Complexity

Conditions 13
Paths 128

Size

Total Lines 79
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 52
nc 128
nop 2
dl 0
loc 79
rs 4.761
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
		<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...
86
			<?php
87
			$donors_table->search_box( __( 'Search Donors', 'give' ), 'give-donors' );
88
			$donors_table->display();
89
			?>
90
			<input type="hidden" name="post_type" value="give_forms" />
91
			<input type="hidden" name="page" value="give-donors" />
92
			<input type="hidden" name="view" value="donors" />
93
		</form>
94
		<?php
95
		/**
96
		 * Fires in donors screen, below the table.
97
		 *
98
		 * @since 1.0
99
		 */
100
		do_action( 'give_donors_table_bottom' );
101
		?>
102
	</div>
103
	<?php
104
}
105
106
/**
107
 * Renders the donor view wrapper.
108
 *
109
 * @since  1.0
110
 *
111
 * @param  string $view      The View being requested.
112
 * @param  array  $callbacks The Registered views and their callback functions.
113
 *
114
 * @return void
115
 */
116
function give_render_donor_view( $view, $callbacks ) {
117
118
	$render = true;
119
120
	$donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
121
122
	if ( ! current_user_can( $donor_view_role ) ) {
123
		give_set_error( 'give-no-access', __( 'You are not permitted to view this data.', 'give' ) );
124
		$render = false;
125
	}
126
127
	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...
128
		give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
129
		$render = false;
130
	}
131
132
	$donor_id          = (int) $_GET['id'];
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
133
	$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...
134
	$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...
135
136
	// Reconnect User with Donor profile.
137
	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...
138
		give_connect_user_donor_profile( $donor, array( 'user_id' => $reconnect_user_id ), array() );
139
	}
140
141
	if ( empty( $donor->id ) ) {
142
		give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
143
		$render = false;
144
	}
145
146
	$donor_tabs = give_donor_tabs();
147
	?>
148
149
	<div class='wrap'>
150
151
		<?php if ( give_get_errors() ) : ?>
152
			<div class="error settings-error">
153
				<?php Give()->notices->render_frontend_notices( 0 ); ?>
154
			</div>
155
		<?php endif; ?>
156
157
		<h1 class="wp-heading-inline">
158
			<?php
159
			printf(
160
			/* 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...
161
				esc_html__( 'Donor %s', 'give' ),
162
				$donor_id
163
			);
164
			?>
165
		</h1>
166
167
		<?php if ( $donor && $render ) : ?>
168
169
			<h2 class="nav-tab-wrapper">
170
				<?php
171
				foreach ( $donor_tabs as $key => $tab ) :
172
					$active = $key === $view ? true : false;
173
					$class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
174
					printf(
175
						'<a href="%1$s" class="%2$s"><span class="dashicons %3$s"></span>%4$s</a>' . "\n",
176
						esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=' . $key . '&id=' . $donor->id ) ),
177
						esc_attr( $class ),
178
						sanitize_html_class( $tab['dashicon'] ),
179
						esc_html( $tab['title'] )
180
					);
181
				endforeach;
182
				?>
183
			</h2>
184
185
			<div id="give-donor-card-wrapper">
186
				<?php $callbacks[ $view ]( $donor ) ?>
187
			</div>
188
189
		<?php endif; ?>
190
191
	</div>
192
	<?php
193
194
}
195
196
197
/**
198
 * View a donor
199
 *
200
 * @since  1.0
201
 *
202
 * @param  Give_Donor $donor The Donor object being displayed.
203
 *
204
 * @return void
205
 */
206
function give_donor_view( $donor ) {
207
208
	$donor_edit_role   = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
209
210
	/**
211
	 * Fires in donor profile screen, above the donor card.
212
	 *
213
	 * @since 1.0
214
	 *
215
	 * @param object $donor The donor object being displayed.
216
	 */
217
	do_action( 'give_donor_card_top', $donor );
218
	?>
219
220
	<div id="donor-summary" class="info-wrapper donor-section postbox">
221
222
		<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...
223
224
			<div class="donor-info">
225
226
				<div class="donor-bio-header clearfix">
227
228
					<div class="avatar-wrap left" id="donor-avatar">
229
						<?php echo get_avatar( $donor->email ); ?>
230
					</div>
231
232
					<div id="donor-name-wrap" class="left">
233
						<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...
234
						<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>
235
						<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...
236
					</div>
237
					<p class="donor-since info-item">
238
						<?php _e( 'Donor since', 'give' ); ?>
239
						<?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...
240
					</p>
241
					<?php if ( current_user_can( $donor_edit_role ) ) : ?>
242
						<a href="#" id="edit-donor" class="button info-item editable donor-edit-link"><?php _e( 'Edit Donor', 'give' ); ?></a>
243
					<?php endif; ?>
244
				</div>
245
				<!-- /donor-bio-header -->
246
247
				<div class="donor-main-wrapper">
248
249
					<table class="widefat">
250
						<tbody>
251
						<tr class="alternate">
252
							<th scope="col"><label for="tablecell"><?php _e( 'User:', 'give' ); ?></label></th>
253
							<td>
254
								<span class="donor-user-id info-item edit-item">
255
									<?php
256
257
									$user_id   = $donor->user_id > 0 ? $donor->user_id : '';
258
259
									$data_atts = array(
260
										'key'     => 'user_login',
261
										'search-type' => 'user',
262
									);
263
									$user_args = array(
264
										'name'  => 'customerinfo[user_id]',
265
										'class' => 'give-user-dropdown',
266
										'data'  => $data_atts,
267
									);
268
269
									if ( ! empty( $user_id ) ) {
270
										$userdata           = get_userdata( $user_id );
271
										$user_args['selected'] = $user_id;
272
									}
273
274
									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...
275
									?>
276
								</span>
277
278
								<span class="donor-user-id info-item editable">
279
									<?php if ( ! empty( $userdata ) ) { ?>
280
										<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...
281
									<?php } else { ?>
282
										<span data-key="user_id"><?php _e( 'None', 'give' ); ?></span>
283
									<?php } ?>
284
									<?php if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ) { ?>
285
										<span class="disconnect-user">
286
 											-
287
 											<a id="disconnect-donor" href="#disconnect" aria-label="<?php _e( 'Disconnects the current user ID from this donor record.', 'give' ); ?>">
288
 												<?php _e( 'Disconnect User', 'give' ); ?>
289
											</a>
290
 										</span>
291
										<span class="view-user-profile">
292
 											|
293
 											<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...
294
 												<?php _e( 'View User Profile', 'give' ); ?>
295
											</a>
296
 										</span>
297
									<?php } ?>
298
								</span>
299
							</td>
300
						</tr>
301
						<?php if ( isset( $donor->user_id ) && $donor->user_id > 0 ) : ?>
302
303
							<tr>
304
								<th scope="col"><?php _e( 'Address:', 'give' ); ?></th>
305
								<td class="row-title">
306
307
									<div class="donor-address-wrapper">
308
309
										<?php
310
										$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...
311
										$defaults = array(
312
											'line1'   => '',
313
											'line2'   => '',
314
											'city'    => '',
315
											'state'   => '',
316
											'country' => '',
317
											'zip'     => '',
318
										);
319
320
										$address = wp_parse_args( $address, $defaults );
321
										?>
322
323
										<?php if ( ! empty( $address ) ) { ?>
324
											<span class="donor-address info-item editable">
325
												<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...
326
												<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...
327
												<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...
328
												<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...
329
												<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...
330
												<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...
331
											</span>
332
										<?php }
333
334
										// For country.
335
										$selected_country = $address['country'];
336
										$countries = give_get_country_list();
337
338
										// For State.
339
										$selected_state = give_get_state();
340
										$states         = give_get_states( $selected_country );
341
										$selected_state = ( isset( $address['state'] ) ? $address['state'] : $selected_state );
342
343
										// Get the country list that does not have any states init.
344
										$no_states_country = give_no_states_country_list();
345
										?>
346
										<span class="donor-address info-item edit-item">
347
											<select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country give-select edit-item">
348
												<?php
349 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...
350
													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...
351
												}
352
												?>
353
											</select>
354
											<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...
355
											<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...
356
											<?php
357
											if ( ! empty( $states ) ) {
358
												?>
359
												<select data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-select info-item">
360
													<?php
361
													foreach ( $states as $state_code => $state ) {
362
														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...
363
													}
364
													?>
365
												</select>
366
												<?php
367
											} else {
368
												?>
369
												<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...
370
												<?php
371
											}
372
											?>
373
											<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...
374
											<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...
375
										</span>
376
377
									</div>
378
								</td>
379
							</tr>
380
						<?php endif; ?>
381
						</tbody>
382
					</table>
383
384
				</div>
385
386
			</div>
387
388
			<span id="donor-edit-actions" class="edit-item">
389
				<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...
390
				<?php wp_nonce_field( 'edit-donor', '_wpnonce', false, true ); ?>
391
				<input type="hidden" name="give_action" value="edit-donor" />
392
				<input type="submit" id="give-edit-donor-save" class="button-secondary" value="<?php _e( 'Update Donor', 'give' ); ?>" />
393
				<a id="give-edit-donor-cancel" href="" class="delete"><?php _e( 'Cancel', 'give' ); ?></a>
394
			</span>
395
396
		</form>
397
398
	</div>
399
400
	<?php
401
	/**
402
	 * Fires in donor profile screen, above the stats list.
403
	 *
404
	 * @since 1.0
405
	 *
406
	 * @param object $donor The donor object being displayed.
407
	 */
408
	do_action( 'give_donor_before_stats', $donor );
409
	?>
410
411
	<div id="donor-stats-wrapper" class="donor-section postbox clear">
412
		<ul>
413
			<li>
414
				<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...
415
					<span class="dashicons dashicons-heart"></span>
416
					<?php
417
					// Completed Donations.
418
					$completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $donor->purchase_count, 'give' ), $donor->purchase_count );
419
					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...
420
					?>
421
				</a>
422
			</li>
423
			<li>
424
				<span class="dashicons dashicons-chart-area"></span>
425
				<?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...
426
			</li>
427
			<?php
428
			/**
429
			 * Fires in donor profile screen, in the stats list.
430
			 *
431
			 * Allows you to add more list items to the stats list.
432
			 *
433
			 * @since 1.0
434
			 *
435
			 * @param object $donor The donor object being displayed.
436
			 */
437
			do_action( 'give_donor_stats_list', $donor );
438
			?>
439
		</ul>
440
	</div>
441
442
	<?php
443
	/**
444
	 * Fires in donor profile screen, above the tables wrapper.
445
	 *
446
	 * @since 1.0
447
	 *
448
	 * @param object $donor The donor object being displayed.
449
	 */
450
	do_action( 'give_donor_before_tables_wrapper', $donor );
451
	?>
452
453
	<div id="donor-tables-wrapper" class="donor-section">
454
455
		<?php
456
		/**
457
		 * Fires in donor profile screen, above the tables.
458
		 *
459
		 * @since 1.0
460
		 *
461
		 * @param object $donor The donor object being displayed.
462
		 */
463
		do_action( 'give_donor_before_tables', $donor );
464
		?>
465
466
		<h3><?php _e( 'Donor Emails', 'give' ); ?></h3>
467
468
		<table class="wp-list-table widefat striped emails">
469
			<thead>
470
			<tr>
471
				<th><?php _e( 'Email', 'give' ); ?></th>
472
				<th><?php _e( 'Actions', 'give' ); ?></th>
473
			</tr>
474
			</thead>
475
476
			<tbody>
477
			<?php if ( ! empty( $donor->emails ) ) { ?>
478
479
				<?php foreach ( $donor->emails as $key => $email ) : ?>
480
					<tr data-key="<?php echo $key; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$key'
Loading history...
481
						<td>
482
							<?php echo $email; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$email'
Loading history...
483
							<?php if ( 'primary' === $key ) : ?>
484
								<span class="dashicons dashicons-star-filled primary-email-icon"></span>
485
							<?php endif; ?>
486
						</td>
487
						<td>
488
							<?php if ( 'primary' !== $key ) : ?>
489
								<?php
490
								$base_url    = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id );
491
								$promote_url = wp_nonce_url( add_query_arg( array(
492
									'email' => rawurlencode( $email ),
493
									'give_action' => 'set_donor_primary_email',
494
								), $base_url ), 'give-set-donor-primary-email' );
495
								$remove_url  = wp_nonce_url( add_query_arg( array(
496
									'email' => rawurlencode( $email ),
497
									'give_action' => 'remove_donor_email',
498
								), $base_url ), 'give-remove-donor-email' );
499
								?>
500
								<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...
501
								&nbsp;|&nbsp;
502
								<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...
503
							<?php endif; ?>
504
						</td>
505
					</tr>
506
				<?php endforeach; ?>
507
508
				<tr class="add-donor-email-row">
509
					<td colspan="2" class="add-donor-email-td">
510
						<div class="add-donor-email-wrapper">
511
							<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...
512
							<?php wp_nonce_field( 'give_add_donor_email', 'add_email_nonce', false, true ); ?>
513
							<input type="email" name="additional-email" value="" placeholder="<?php _e( 'Email Address', 'give' ); ?>" />&nbsp;
514
							<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>
515
							<button class="button-secondary give-add-donor-email" id="add-donor-email"><?php _e( 'Add Email', 'give' ); ?></button>
516
							<span class="spinner"></span>
517
						</div>
518
						<div class="notice-wrap"></div>
519
					</td>
520
				</tr>
521
			<?php } else { ?>
522
				<tr><td colspan="2"><?php _e( 'No Emails Found', 'give' ); ?></td></tr>
523
			<?php }// End if().
524
			?>
525
			</tbody>
526
		</table>
527
528
		<h3><?php _e( 'Recent Donations', 'give' ); ?></h3>
529
		<?php
530
		$payment_ids = explode( ',', $donor->payment_ids );
531
		$payments    = give_get_payments( array(
532
			'post__in' => $payment_ids,
533
		) );
534
		$payments    = array_slice( $payments, 0, 10 );
535
		?>
536
		<table class="wp-list-table widefat striped payments">
537
			<thead>
538
			<tr>
539
				<th scope="col"><?php _e( 'ID', 'give' ); ?></th>
540
				<th scope="col"><?php _e( 'Amount', 'give' ); ?></th>
541
				<th scope="col"><?php _e( 'Date', 'give' ); ?></th>
542
				<th scope="col"><?php _e( 'Status', 'give' ); ?></th>
543
				<th scope="col"><?php _e( 'Actions', 'give' ); ?></th>
544
			</tr>
545
			</thead>
546
			<tbody>
547
			<?php if ( ! empty( $payments ) ) { ?>
548
				<?php foreach ( $payments as $payment ) : ?>
549
					<tr>
550
						<td><?php echo $payment->ID; ?></td>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$payment'
Loading history...
551
						<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...
552
						<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...
553
						<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...
554
						<td>
555
							<?php
556
							printf(
557
								'<a href="%1$s" aria-label="%2$s">%3$s</a>',
558
								admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment->ID ),
559
								sprintf(
560
								/* 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...
561
									esc_attr__( 'View Donation %s.', 'give' ),
562
									$payment->ID
563
								),
564
								__( 'View Donation', 'give' )
565
							);
566
							?>
567
568
							<?php
569
							/**
570
							 * Fires in donor profile screen, in the recent donations tables action links.
571
							 *
572
							 * Allows you to add more action links for each donation, after the 'View Donation' action link.
573
							 *
574
							 * @since 1.0
575
							 *
576
							 * @param object $donor The donor object being displayed.
577
							 * @param object $payment  The payment object being displayed.
578
							 */
579
							do_action( 'give_donor_recent_purchases_actions', $donor, $payment );
580
							?>
581
						</td>
582
					</tr>
583
				<?php endforeach; ?>
584
			<?php } else { ?>
585
				<tr>
586
					<td colspan="5"><?php _e( 'No donations found.', 'give' ); ?></td>
587
				</tr>
588
			<?php }// End if().
589
			?>
590
			</tbody>
591
		</table>
592
593
		<h3><?php _e( 'Completed Forms', 'give' ); ?></h3>
594
		<?php
595
		$donations = give_get_users_completed_donations( $donor->email );
596
		?>
597
		<table class="wp-list-table widefat striped donations">
598
			<thead>
599
			<tr>
600
				<th scope="col"><?php _e( 'Form', 'give' ); ?></th>
601
				<th scope="col" width="120px"><?php _e( 'Actions', 'give' ); ?></th>
602
			</tr>
603
			</thead>
604
			<tbody>
605
			<?php if ( ! empty( $donations ) ) { ?>
606
				<?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...
607
					<tr>
608
						<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...
609
						<td>
610
							<?php
611
							printf(
612
								'<a href="%1$s" aria-label="%2$s">%3$s</a>',
613
								esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ),
614
								sprintf(
615
								/* 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...
616
									esc_attr__( 'View Form %s.', 'give' ),
617
									$donation->post_title
618
								),
619
								__( 'View Form', 'give' )
620
							);
621
							?>
622
						</td>
623
					</tr>
624
				<?php endforeach; ?>
625
			<?php } else { ?>
626
				<tr>
627
					<td colspan="2"><?php _e( 'No completed donations found.', 'give' ); ?></td>
628
				</tr>
629
			<?php } ?>
630
			</tbody>
631
		</table>
632
633
		<?php
634
		/**
635
		 * Fires in donor profile screen, below the tables.
636
		 *
637
		 * @since 1.0
638
		 *
639
		 * @param object $donor The donor object being displayed.
640
		 */
641
		do_action( 'give_donor_after_tables', $donor );
642
		?>
643
644
	</div>
645
646
	<?php
647
	/**
648
	 * Fires in donor profile screen, below the donor card.
649
	 *
650
	 * @since 1.0
651
	 *
652
	 * @param object $donor The donor object being displayed.
653
	 */
654
	do_action( 'give_donor_card_bottom', $donor );
655
656
}
657
658
/**
659
 * View the notes of a donor.
660
 *
661
 * @since  1.0
662
 *
663
 * @param  object $donor The donor object being displayed.
664
 *
665
 * @return void
666
 */
667
function give_donor_notes_view( $donor ) {
668
669
	$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...
670
	$paged          = absint( $paged );
671
	$note_count     = $donor->get_notes_count();
672
	$per_page       = apply_filters( 'give_donor_notes_per_page', 20 );
673
	$total_pages    = ceil( $note_count / $per_page );
674
	$donor_notes = $donor->get_notes( $per_page, $paged );
675
	?>
676
677
	<div id="donor-notes-wrapper">
678
		<div class="donor-notes-header">
679
			<?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...
680
		</div>
681
		<h3><?php _e( 'Notes', 'give' ); ?></h3>
682
683
		<?php if ( 1 == $paged ) : ?>
684
			<div style="display: block; margin-bottom: 55px;">
685
				<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...
686
					<textarea id="donor-note" name="donor_note" class="donor-note-input" rows="10"></textarea>
687
					<br />
688
					<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...
689
					<input type="hidden" name="give_action" value="add-donor-note" />
690
					<?php wp_nonce_field( 'add-donor-note', 'add_donor_note_nonce', true, true ); ?>
691
					<input id="add-donor-note" class="right button-primary" type="submit" value="Add Note" />
692
				</form>
693
			</div>
694
		<?php endif; ?>
695
696
		<?php
697
		$pagination_args = array(
698
			'base'     => '%_%',
699
			'format'   => '?paged=%#%',
700
			'total'    => $total_pages,
701
			'current'  => $paged,
702
			'show_all' => true,
703
		);
704
705
		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...
706
		?>
707
708
		<div id="give-donor-notes" class="postbox">
709
			<?php if ( count( $donor_notes ) > 0 ) { ?>
710
				<?php foreach ( $donor_notes as $key => $note ) : ?>
711
					<div class="donor-note-wrapper dashboard-comment-wrap comment-item">
712
					<span class="note-content-wrap">
713
						<?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...
714
					</span>
715
					</div>
716
				<?php endforeach; ?>
717
			<?php } else { ?>
718
				<div class="give-no-donor-notes">
719
					<?php _e( 'No donor notes found.', 'give' ); ?>
720
				</div>
721
			<?php } ?>
722
		</div>
723
724
		<?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...
725
726
	</div>
727
728
	<?php
729
}
730
731
/**
732
 * Thw donor delete view.
733
 *
734
 * @since  1.0
735
 *
736
 * @param  object $donor The donor object being displayed.
737
 *
738
 * @return void
739
 */
740
function give_donor_delete_view( $donor ) {
741
742
	$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...
743
744
	/**
745
	 * Fires in donor delete screen, above the content.
746
	 *
747
	 * @since 1.0
748
	 *
749
	 * @param object $donor The donor object being displayed.
750
	 */
751
	do_action( 'give_donor_delete_top', $donor );
752
	?>
753
754
	<div class="info-wrapper donor-section">
755
756
		<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...
757
758
			<div class="donor-notes-header">
759
				<?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...
760
			</div>
761
762
763
			<div class="donor-info delete-donor">
764
765
				<span class="delete-donor-options">
766
					<p>
767
						<?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...
768
							'name' => 'give-donor-delete-confirm',
769
						) ); ?>
770
						<label for="give-donor-delete-confirm"><?php _e( 'Are you sure you want to delete this donor?', 'give' ); ?></label>
771
					</p>
772
773
					<p>
774
						<?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...
775
							'name'    => 'give-donor-delete-records',
776
							'options' => array(
777
								'disabled' => true,
778
							),
779
						) ); ?>
780
						<label for="give-donor-delete-records"><?php _e( 'Delete all associated donations and records?', 'give' ); ?></label>
781
					</p>
782
783
					<?php
784
					/**
785
					 * Fires in donor delete screen, bellow the delete inputs.
786
					 *
787
					 * Allows you to add custom delete inputs.
788
					 *
789
					 * @since 1.0
790
					 *
791
					 * @param object $donor The donor object being displayed.
792
					 */
793
					do_action( 'give_donor_delete_inputs', $donor );
794
					?>
795
				</span>
796
797
				<span id="donor-edit-actions">
798
					<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...
799
					<?php wp_nonce_field( 'delete-donor', '_wpnonce', false, true ); ?>
800
					<input type="hidden" name="give_action" value="delete-donor" />
801
					<input type="submit" disabled="disabled" id="give-delete-donor" class="button-primary" value="<?php _e( 'Delete Donor', 'give' ); ?>" />
802
					<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...
803
				</span>
804
805
			</div>
806
807
		</form>
808
	</div>
809
810
	<?php
811
	/**
812
	 * Fires in donor delete screen, bellow the content.
813
	 *
814
	 * @since 1.0
815
	 *
816
	 * @param object $donor The donor object being displayed.
817
	 */
818
	do_action( 'give_donor_delete_bottom', $donor );
819
}
820