PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / trunk
GiveWP – Donation Plugin and Fundraising Platform vtrunk
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / donors / donors.php
give / includes / admin / donors Last commit date
class-donor-table.php 1 year ago donor-actions.php 1 year ago donor-functions.php 1 year ago donors.php 7 months ago
donors.php
1218 lines
1 <?php
2 /**
3 * Donors.
4 *
5 * @package Give
6 * @subpackage Admin/Donors
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 use Give\Donors\DonorsAdminPage;
13 use Give\Donors\Models\Donor;
14 use Give\Helpers\IntlTelInput;
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21
22 /**
23 * Get formatted address
24 *
25 * @since 4.9.0 rename function - PHP 8 compatibility
26 * @since 2.0
27 *
28 * @param array $address
29 * @param array $address_args
30 *
31 * @return string
32 */
33 function give_get_format_address( $address, $address_args = array() ) {
34 $address_html = '';
35 $address_args = wp_parse_args(
36 $address_args,
37 array(
38 'type' => '',
39 'id' => null,
40 'index' => null,
41 'default_address' => false,
42 )
43 );
44
45 $address_id = $address_args['type'];
46
47 // Bailout.
48 if ( empty( $address ) || ! is_array( $address ) ) {
49 return $address_html;
50 }
51
52 // Address html.
53 $address_html = '';
54 $address_html .= sprintf(
55 '<span data-address-type="line1">%1$s</span>%2$s',
56 $address['line1'],
57 ( ! empty( $address['line2'] ) ? '<br>' : '' )
58 );
59 $address_html .= sprintf(
60 '<span data-address-type="line2">%1$s</span>%2$s',
61 $address['line2'],
62 ( ! empty( $address['city'] ) ? '<br>' : '' )
63 );
64 $address_html .= sprintf(
65 '<span data-address-type="city">%1$s</span><span data-address-type="state">%2$s</span><span data-address-type="zip">%3$s</span>%4$s',
66 $address['city'],
67 ( ! empty( $address['state'] ) ? ", {$address['state']}" : '' ),
68 ( ! empty( $address['zip'] ) ? " {$address['zip']}" : '' ),
69 ( ! empty( $address['country'] ) ? '<br>' : '' )
70 );
71 $address_html .= sprintf(
72 '<span data-address-type="country">%s</span><br>',
73 $address['country']
74 );
75
76 // Address action.
77 $address_html .= sprintf(
78 '<br><a href="#" class="js-edit">%1$s</a> | <a href="#" class="js-remove">%2$s</a>',
79 __( 'Edit', 'give' ),
80 __( 'Remove', 'give' )
81 );
82
83 /**
84 * Filter the address label
85 *
86 * @since 2.0
87 */
88 $address_label = apply_filters( "give_donor_{$address_args['type']}_address_label", ucfirst( $address_args['type'] ), $address_args );
89
90 // Set unique id and index for multi type address.
91 if ( isset( $address_args['index'] ) ) {
92 $address_label = "{$address_label} #{$address_args['index']}";
93 }
94
95 if ( isset( $address_args['id'] ) ) {
96 $address_id = "{$address_id}_{$address_args['id']}";
97 }
98
99 // Add address wrapper.
100 $address_html = sprintf(
101 '<div class="give-grid-col-4"><div data-address-id="%s" class="address"><span class="alignright address-number-label">%s</span>%s</div></div>',
102 $address_id,
103 $address_label,
104 $address_html
105 );
106
107 return $address_html;
108 }
109
110 /**
111 * Donors Page.
112 *
113 * Renders the donors page contents.
114 *
115 * @since 4.13.1 add early return if showing new details page
116 * @since 1.0
117 * @return void
118 */
119 function give_donors_page() {
120 if (DonorsAdminPage::isShowingNewDetailsPage()) {
121 return;
122 }
123
124 $default_views = give_donor_views();
125 $requested_view = isset( $_GET['view'] ) ? sanitize_text_field( $_GET['view'] ) : 'donors';
126 if ( array_key_exists( $requested_view, $default_views ) && function_exists( $default_views[ $requested_view ] ) ) {
127 give_render_donor_view( $requested_view, $default_views );
128 }
129 else {
130 $userId = get_current_user_id();
131 $showLegacy = get_user_meta($userId, '_give_donors_archive_show_legacy', true);
132 if ($showLegacy == 1)
133 {
134 give_donors_list();
135 }
136 }
137 }
138
139 /**
140 * Register the views for donor management.
141 *
142 * @since 1.0
143 * @return array Array of views and their callbacks.
144 */
145 function give_donor_views() {
146
147 $views = array();
148
149 return apply_filters( 'give_donor_views', $views );
150
151 }
152
153 /**
154 * Register the tabs for donor management.
155 *
156 * @since 1.0
157 * @return array Array of tabs for the donor.
158 */
159 function give_donor_tabs() {
160
161 $tabs = array();
162
163 return apply_filters( 'give_donor_tabs', $tabs );
164
165 }
166
167 /**
168 * List table of donors.
169 *
170 * @since 1.0
171 * @return void
172 */
173 function give_donors_list() {
174
175 include GIVE_PLUGIN_DIR . 'includes/admin/donors/class-donor-table.php';
176
177 $donors_table = new Give_Donor_List_Table();
178 $donors_table->prepare_items();
179 ?>
180 <div class="wrap">
181 <h1 class="wp-heading-inline"><?php echo get_admin_page_title(); ?></h1>
182 <?php
183 /**
184 * Fires in donors screen, above the table.
185 *
186 * @since 1.0
187 */
188 do_action( 'give_donors_table_top' );
189 ?>
190
191 <hr class="wp-header-end">
192 <form id="give-donors-filter" method="get" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors' ); ?>">
193 <?php
194 $donors_table->advanced_filters();
195 $donors_table->display();
196 ?>
197 <input type="hidden" name="post_type" value="give_forms"/>
198 <input type="hidden" name="page" value="give-donors"/>
199 <input type="hidden" name="view" value="donors"/>
200 </form>
201 <?php
202 /**
203 * Fires in donors screen, below the table.
204 *
205 * @since 1.0
206 */
207 do_action( 'give_donors_table_bottom' );
208 ?>
209 </div>
210 <?php
211 }
212
213 /**
214 * Renders the donor view wrapper.
215 *
216 * @since 1.0
217 *
218 * @param string $view The View being requested.
219 * @param array $callbacks The Registered views and their callback functions.
220 *
221 * @return void
222 */
223 function give_render_donor_view( $view, $callbacks ) {
224
225 $render = true;
226
227 $donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
228
229 if ( ! current_user_can( $donor_view_role ) ) {
230 give_set_error( 'give-no-access', __( 'You are not permitted to view this data.', 'give' ) );
231 $render = false;
232 }
233
234 if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
235 give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
236 $render = false;
237 }
238
239 $donor_id = (int) $_GET['id'];
240 $reconnect_user_id = ! empty( $_GET['user_id'] ) ? (int) $_GET['user_id'] : '';
241 $donor = new Give_Donor( $donor_id );
242
243 // Reconnect User with Donor profile.
244 if ( $reconnect_user_id ) {
245 give_connect_user_donor_profile( $donor, array( 'user_id' => $reconnect_user_id ), array() );
246 }
247
248 if ( empty( $donor->id ) ) {
249 give_set_error( 'give-invalid_donor', __( 'Invalid Donor ID.', 'give' ) );
250 $render = false;
251 }
252
253 ?>
254
255 <div class='wrap'>
256
257 <h1 class="wp-heading-inline">
258 <?php
259 printf(
260 /* translators: %s: donor first name */
261 __( 'Edit Donor: %1$s %2$s', 'give' ),
262 $donor->get_first_name(),
263 $donor->get_last_name()
264 );
265 ?>
266 </h1>
267
268 <hr class="wp-header-end">
269
270 <?php if ( give_get_errors() ) : ?>
271 <div class="error settings-error">
272 <?php Give()->notices->render_frontend_notices( 0 ); ?>
273 </div>
274 <?php endif; ?>
275
276 <?php if ( $donor && $render ) : ?>
277
278 <div class="nav-tab-wrapper give-nav-tab-wrapper">
279 <?php
280
281 $donor_tabs = give_donor_tabs();
282
283 foreach ( $donor_tabs as $key => $tab ) :
284 $active = $key === $view ? true : false;
285 $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab';
286 printf(
287 '<a href="%1$s" class="%2$s">%3$s</a>' . "\n",
288 esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=' . $key . '&id=' . $donor->id ) ),
289 esc_attr( $class ),
290 esc_html( $tab['title'] )
291 );
292 endforeach;
293 ?>
294 </div>
295
296 <div id="give-donor-card-wrapper">
297 <?php $callbacks[ $view ]( $donor ); ?>
298 </div>
299
300 <?php endif; ?>
301
302 </div>
303 <?php
304
305 }
306
307
308 /**
309 * View a donor
310 *
311 * @since 3.7.0 Add "phone" field
312 * @since 1.0
313 *
314 * @param Give_Donor $donor The Donor object being displayed.
315 *
316 * @return void
317 */
318 function give_donor_view( $donor ) {
319
320 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
321
322 /**
323 * Fires in donor profile screen, above the donor card.
324 *
325 * @since 1.0
326 *
327 * @param object $donor The donor object being displayed.
328 */
329 do_action( 'give_donor_card_top', $donor );
330
331 // Set Read only to the fields which needs to be locked.
332 $read_only = '';
333 if ( $donor->user_id ) {
334 $read_only = 'readonly="readonly"';
335 }
336
337 // List of title prefixes.
338 $title_prefixes = give_get_name_title_prefixes();
339
340 // Prepend title prefix to name if it is set.
341 $title_prefix = Give()->donor_meta->get_meta( $donor->id, '_give_donor_title_prefix', true );
342 $donor_name_without_prefix = $donor->name;
343 $donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name );
344 ?>
345 <div id="donor-summary" class="info-wrapper donor-section postbox">
346 <form id="edit-donor-info" method="post"
347 action="<?php echo esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) ); ?>">
348 <div class="donor-info">
349 <div class="donor-bio-header clearfix">
350 <div class="avatar-wrap left" id="donor-avatar">
351 <?php
352
353 // Check whether a Gravatar exists for a donor or not.
354 $validate_gravatar_image = give_validate_gravatar( $donor->email );
355
356 // Get donor's initials for non-gravatars
357 $donor_name_array = explode( ' ', $donor_name_without_prefix );
358 $donor_name_args['firstname'] = ! empty( $donor_name_array[0] ) ? $donor_name_array[0] : '';
359 $donor_name_args['lastname'] = ! empty( $donor_name_array[1] ) ? $donor_name_array[1] : '';
360 $donor_name_initial = give_get_name_initial( $donor_name_args );
361
362 // Gravatars image for donor
363 if ( $validate_gravatar_image ) {
364 $donor_gravatar_image = get_avatar( $donor->email );
365 } else {
366 $donor_gravatar_image = '<div class="give-donor-admin-avatar">' . $donor_name_initial . '</div>';
367 }
368
369 echo $donor_gravatar_image;
370 ?>
371 </div>
372 <div id="donor-name-wrap" class="left">
373 <span class="donor-name info-item edit-item">
374 <select name="donor_info[title]">
375 <option disabled value="0"><?php esc_html_e( 'Title', 'give' ); ?></option>
376 <option value="">&nbsp;</option>
377 <?php
378 if ( is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) {
379 foreach ( $title_prefixes as $title ) {
380 echo sprintf(
381 '<option %1$s value="%2$s">%2$s</option>',
382 selected( $title_prefix, $title, false ),
383 esc_html( $title )
384 );
385 }
386 }
387 ?>
388 </select>
389 <input <?php echo $read_only; ?> size="15" data-key="first_name"
390 name="donor_info[first_name]" type="text"
391 value="<?php echo esc_html( $donor->get_first_name() ); ?>"
392 placeholder="<?php esc_html_e( 'First Name', 'give' ); ?>"/>
393 <?php if ( $donor->user_id ) : ?>
394 <a href="#" class="give-lock-block">
395 <i class="give-icon give-icon-locked"></i>
396 </a>
397 <?php endif; ?>
398 <input <?php echo $read_only; ?> size="15" data-key="last_name"
399 name="donor_info[last_name]" type="text"
400 value="<?php echo esc_html( $donor->get_last_name() ); ?>"
401 placeholder="<?php esc_html_e( 'Last Name', 'give' ); ?>"/>
402 <?php if ( $donor->user_id ) : ?>
403 <a href="#" class="give-lock-block">
404 <i class="give-icon give-icon-locked"></i>
405 </a>
406 <?php endif; ?>
407 </span>
408 <span class="donor-name info-item editable">
409 <span data-key="name"><?php echo esc_html( $donor->name ); ?></span>
410 </span>
411 </div>
412 <p class="donor-since info-item">
413 <?php esc_html_e( 'Donor since', 'give' ); ?>
414 <?php echo date_i18n( give_date_format(), strtotime( $donor->date_created ) ); ?>
415 </p>
416 <?php if ( current_user_can( $donor_edit_role ) ) : ?>
417 <a href="#" id="edit-donor" class="button info-item editable donor-edit-link">
418 <?php esc_html_e( 'Edit Donor', 'give' ); ?>
419 </a>
420 <?php endif; ?>
421 </div>
422 <!-- /donor-bio-header -->
423
424 <div class="donor-main-wrapper">
425
426 <table class="widefat striped">
427 <tbody>
428 <tr>
429 <th scope="col"><label for="tablecell"><?php esc_html_e( 'Donor ID:', 'give' ); ?></label>
430 </th>
431 <td><?php echo intval( $donor->id ); ?></td>
432 </tr>
433 <tr>
434 <th scope="col"><label for="tablecell"><?php esc_html_e( 'User ID:', 'give' ); ?></label>
435 </th>
436 <td>
437 <span class="donor-user-id info-item edit-item">
438 <?php
439
440 $user_id = $donor->user_id > 0 ? $donor->user_id : '';
441
442 $data_atts = array(
443 'key' => 'user_login',
444 'search-type' => 'user',
445 );
446 $user_args = array(
447 'name' => 'donor_info[user_id]',
448 'class' => 'give-user-dropdown',
449 'data' => $data_atts,
450 );
451
452 if ( ! empty( $user_id ) ) {
453 $userdata = get_userdata( $user_id );
454 $user_args['selected'] = $user_id;
455 }
456
457 echo Give()->html->ajax_user_search( $user_args );
458 ?>
459 </span>
460
461 <span class="donor-user-id info-item editable">
462 <?php if ( ! empty( $userdata ) ) : ?>
463 <span
464 data-key="user_id">#<?php echo $donor->user_id . ' - ' . $userdata->display_name; ?></span>
465 <?php else : ?>
466 <span
467 data-key="user_id"><?php esc_html_e( 'Unregistered', 'give' ); ?></span>
468 <?php endif; ?>
469 <?php
470 if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ) :
471
472 echo sprintf(
473 '- <span class="disconnect-user">
474 <a id="disconnect-donor" href="#disconnect" aria-label="%1$s">%2$s</a>
475 </span> |
476 <span class="view-user-profile">
477 <a id="view-user-profile" href="%3$s" aria-label="%4$s">%5$s</a>
478 </span>',
479 esc_html__( 'Disconnects the current user ID from this donor record.', 'give' ),
480 esc_html__( 'Disconnect User', 'give' ),
481 esc_url( 'user-edit.php?user_id=' . $donor->user_id ),
482 esc_html__( 'View User Profile of current user ID.', 'give' ),
483 esc_html__( 'View User Profile', 'give' )
484 );
485
486 endif;
487 ?>
488 </span>
489 </td>
490 </tr>
491
492 <?php
493
494 $donor_phone_number = Donor::find($donor->id)->phone;
495 ?>
496 <tr class="alternate">
497 <th scope="col">
498 <label for="tablecell"><?php
499 esc_html_e('Phone:', 'give'); ?></label>
500 </th>
501 <td>
502 <span class="donor-user-id info-item edit-item">
503 <?php
504 echo IntlTelInput::getHtmlInput($donor_phone_number, "give_donor_phone_number"); ?>
505 </span>
506
507 <span class="donor-user-id info-item editable">
508 <?php
509 echo $donor_phone_number; ?>
510 </span>
511 </td>
512 </tr>
513 <?php
514 $donor_company = $donor->get_meta( '_give_donor_company', true );
515 ?>
516 <tr class="">
517 <th scope="col">
518 <label for="tablecell"><?php esc_html_e( 'Company Name:', 'give' ); ?></label>
519 </th>
520 <td>
521 <span class="donor-user-id info-item edit-item">
522 <input name="give_donor_company" value="<?php echo $donor_company; ?>" type="text">
523 </span>
524
525 <span class="donor-user-id info-item editable">
526 <?php echo $donor_company; ?>
527 </span>
528 </td>
529 </tr>
530 </tbody>
531 </table>
532 </div>
533
534 </div>
535
536 <span id="donor-edit-actions" class="edit-item">
537 <input type="hidden" data-key="id" name="donor_info[id]" value="<?php echo intval( $donor->id ); ?>"/>
538 <?php wp_nonce_field( 'edit-donor', '_wpnonce', false, true ); ?>
539 <input type="hidden" name="give_action" value="edit-donor"/>
540 <input type="submit" id="give-edit-donor-save" class="button-secondary"
541 value="<?php esc_html_e( 'Update Donor', 'give' ); ?>"/>
542 <a id="give-edit-donor-cancel" href="" class="delete"><?php esc_html_e( 'Cancel', 'give' ); ?></a>
543 </span>
544
545 </form>
546
547 </div>
548
549 <?php
550 /**
551 * Fires in donor profile screen, above the stats list.
552 *
553 * @since 1.0
554 *
555 * @param Give_Donor $donor The donor object being displayed.
556 */
557 do_action( 'give_donor_before_stats', $donor );
558 ?>
559
560 <div id="donor-stats-wrapper" class="donor-section postbox clear">
561 <ul>
562 <li>
563 <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor->id ) ); ?>">
564 <span class="dashicons dashicons-heart"></span>
565 <?php
566 // Completed Donations.
567 $completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $donor->purchase_count, 'give' ), $donor->purchase_count );
568 echo apply_filters( 'give_donor_completed_donations', $completed_donations_text, $donor );
569 ?>
570 </a>
571 </li>
572 <li>
573 <span class="dashicons dashicons-chart-area"></span>
574 <?php echo give_currency_filter( give_format_amount( $donor->get_total_donation_amount(), array( 'sanitize' => false ) ) ); ?> <?php _e( 'Lifetime Donations', 'give' ); ?>
575 </li>
576 <?php
577 /**
578 * Fires in donor profile screen, in the stats list.
579 *
580 * Allows you to add more list items to the stats list.
581 *
582 * @since 1.0
583 *
584 * @param object $donor The donor object being displayed.
585 */
586 do_action( 'give_donor_stats_list', $donor );
587 ?>
588 </ul>
589 </div>
590
591 <?php
592 /**
593 * Fires in donor profile screen, above the address list.
594 *
595 * @since 1.8.14
596 *
597 * @param Give_Donor $donor The donor object being displayed.
598 */
599 do_action( 'give_donor_before_address', $donor );
600 ?>
601
602 <div id="donor-address-wrapper" class="donor-section clear">
603 <h3><?php _e( 'Addresses', 'give' ); ?></h3>
604
605 <div class="postbox give-donor-addresses">
606 <div class="give-spinner-wrapper">
607 <span class="give-spinner spinner aligncenter"></span>
608 </div>
609 <div class="inside">
610 <div class="all-address">
611 <div class="give-grid-row">
612 <?php
613 if ( ! empty( $donor->address ) ) :
614 // Default address always will be at zero array index.
615 $is_set_as_default = null;
616
617 foreach ( $donor->address as $address_type => $addresses ) {
618
619 switch ( true ) {
620 case is_array( end( $addresses ) ):
621 $index = 1;
622 foreach ( $addresses as $id => $address ) {
623 echo give_get_format_address(
624 $address,
625 array(
626 'type' => $address_type,
627 'id' => $id,
628 'index' => $index,
629 )
630 );
631
632 $index ++;
633 }
634 break;
635
636 case is_string( end( $addresses ) ):
637 echo give_get_format_address(
638 $addresses,
639 array(
640 'type' => $address_type,
641 )
642 );
643 break;
644 }
645 }
646 endif;
647 ?>
648 </div>
649 <span class="give-no-address-message
650 <?php
651 if ( ! empty( $donor->address ) ) {
652 echo ' give-hidden';
653 }
654 ?>
655 ">
656 <?php _e( 'This donor does not have any addresses saved.', 'give' ); ?>
657 </span>
658 <button class="button add-new-address">
659 <?php _e( 'Add Address', 'give' ); ?>
660 </button>
661 </div>
662
663 <div class="address-form add-new-address-form-hidden">
664 <form action="" method="post">
665 <table class="widefat striped">
666 <tbody>
667 <tr>
668 <th class="col">
669 <label class="country"><?php esc_html_e( 'Country:', 'give' ); ?></label>
670 </th>
671 <td>
672 <?php
673 echo Give()->html->select(
674 array(
675 'options' => give_get_country_list(),
676 'name' => 'country',
677 'selected' => give_get_option( 'base_country' ),
678 'show_option_all' => false,
679 'show_option_none' => false,
680 'chosen' => true,
681 'placeholder' => esc_attr__( 'Select a country', 'give' ),
682 'data' => array( 'search-type' => 'no_ajax' ),
683 'autocomplete' => 'country',
684 )
685 );
686 ?>
687 </td>
688 </tr>
689 <tr>
690 <th class="col">
691 <label for="line1"><?php esc_html_e( 'Address 1:', 'give' ); ?></label>
692 </th>
693 <td>
694 <input id="line1" name="line1" type="text" class="medium-text"/>
695 </td>
696 </tr>
697 <tr>
698 <th class="col">
699 <label for="line2"><?php esc_html_e( 'Address 2:', 'give' ); ?></label>
700 </th>
701 <td>
702 <input id="line2" type="text" name="line2" value="" class="medium-text"/>
703
704 </td>
705 </tr>
706 <tr>
707 <th class="col">
708 <label for="city"><?php esc_html_e( 'City:', 'give' ); ?></label>
709 </th>
710 <td>
711 <input id="city" type="text" name="city" value="" class="medium-text"/>
712 </td>
713 </tr>
714 <?php
715 $no_states_country = give_no_states_country_list();
716 $base_country = give_get_option( 'base_country' );
717 if ( ! array_key_exists( $base_country, $no_states_country ) ) {
718 ?>
719 <tr class="give-field-wrap">
720 <th class="col">
721 <label
722 for="state"><?php esc_html_e( 'State / Province / County:', 'give' ); ?></label>
723 </th>
724 <td>
725 <?php
726 $states = give_get_states( $base_country );
727 $state_args = array(
728 'name' => 'state',
729 'class' => 'regular-text',
730 'autocomplete' => 'address-level1',
731 );
732
733 if ( empty( $states ) ) {
734
735 // Show Text field, if empty states.
736 $state_args = wp_parse_args(
737 $state_args,
738 array(
739 'value' => give_get_option( 'base_state' ),
740 )
741 );
742 echo Give()->html->text( $state_args );
743 } else {
744
745 // Show Chosen DropDown, if states are not empty.
746 $state_args = wp_parse_args(
747 $state_args,
748 array(
749 'options' => $states,
750 'selected' => give_get_option( 'base_state' ),
751 'show_option_all' => false,
752 'show_option_none' => false,
753 'chosen' => true,
754 'placeholder' => __( 'Select a state', 'give' ),
755 'data' => array( 'search-type' => 'no_ajax' ),
756 )
757 );
758 echo Give()->html->select( $state_args );
759 }
760 ?>
761 </td>
762 </tr>
763 <?php
764 }
765 ?>
766 <tr>
767 <th class="col">
768 <label for="zip"><?php esc_html_e( 'Zip / Postal Code:', 'give' ); ?></label>
769 </th>
770 <td>
771 <input id="zip" type="text" name="zip" value="" class="medium-text"/>
772 </td>
773 </tr>
774 <tr>
775 <td colspan="2">
776 <?php wp_nonce_field( 'give-manage-donor-addresses', '_wpnonce', false ); ?>
777 <input type="hidden" name="address-action" value="add">
778 <input type="hidden" name="address-id" value="">
779 <input type="submit" class="button button-primary js-save"
780 value="<?php _e( 'Save', 'give' ); ?>">&nbsp;&nbsp;<button
781 class="button js-cancel"><?php _e( 'Cancel', 'give' ); ?></button>
782 </td>
783 </tr>
784 </tbody>
785 </table>
786 </form>
787 </div>
788 </div>
789 </div>
790 </div>
791
792 <?php
793 /**
794 * Fires in donor profile screen, above the tables wrapper.
795 *
796 * @since 1.0
797 *
798 * @param Give_Donor $donor The donor object being displayed.
799 */
800 do_action( 'give_donor_before_tables_wrapper', $donor );
801 ?>
802
803 <div id="donor-tables-wrapper" class="donor-section">
804
805 <?php
806 /**
807 * Fires in donor profile screen, above the tables.
808 *
809 * @since 1.0
810 *
811 * @param object $donor The donor object being displayed.
812 */
813 do_action( 'give_donor_before_tables', $donor );
814 ?>
815
816 <h3><?php _e( 'Donor Emails', 'give' ); ?></h3>
817
818 <table class="wp-list-table widefat striped emails">
819 <thead>
820 <tr>
821 <th><?php _e( 'Email', 'give' ); ?></th>
822 <th><?php _e( 'Actions', 'give' ); ?></th>
823 </tr>
824 </thead>
825
826 <tbody>
827 <?php if ( ! empty( $donor->emails ) ) { ?>
828
829 <?php foreach ( $donor->emails as $key => $email ) : ?>
830 <tr data-key="<?php echo $key; ?>">
831 <td>
832 <?php echo $email; ?>
833 <?php if ( 'primary' === $key ) : ?>
834 <span class="dashicons dashicons-star-filled primary-email-icon"></span>
835 <?php endif; ?>
836 </td>
837 <td>
838 <?php if ( 'primary' !== $key ) : ?>
839 <?php
840 $base_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id );
841 $promote_url = wp_nonce_url(
842 add_query_arg(
843 array(
844 'email' => rawurlencode( $email ),
845 'give_action' => 'set_donor_primary_email',
846 ),
847 $base_url
848 ),
849 'give-set-donor-primary-email'
850 );
851 $remove_url = wp_nonce_url(
852 add_query_arg(
853 array(
854 'email' => rawurlencode( $email ),
855 'give_action' => 'remove_donor_email',
856 ),
857 $base_url
858 ),
859 'give-remove-donor-email'
860 );
861 ?>
862 <a href="<?php echo esc_url( $promote_url ); ?>"><?php _e( 'Make Primary', 'give' ); ?></a>
863 &nbsp;|&nbsp;
864 <a href="<?php echo esc_url( $remove_url ); ?>" class="delete"><?php _e( 'Remove', 'give' ); ?></a>
865 <?php endif; ?>
866 </td>
867 </tr>
868 <?php endforeach; ?>
869
870 <tr class="add-donor-email-row">
871 <td colspan="2" class="add-donor-email-td">
872 <div class="add-donor-email-wrapper">
873 <input type="hidden" name="donor-id" value="<?php echo $donor->id; ?>"/>
874 <?php wp_nonce_field( 'give_add_donor_email', 'add_email_nonce', false, true ); ?>
875 <input type="email" name="additional-email" value=""
876 placeholder="<?php _e( 'Email Address', 'give' ); ?>"/>&nbsp;
877 <input type="checkbox" name="make-additional-primary" value="1"
878 id="make-additional-primary"/>&nbsp;<label
879 for="make-additional-primary"><?php _e( 'Make Primary', 'give' ); ?></label>
880 <button class="button-secondary give-add-donor-email"
881 id="add-donor-email"><?php _e( 'Add Email', 'give' ); ?></button>
882 <span class="spinner"></span>
883 </div>
884 <div class="notice-wrap"></div>
885 </td>
886 </tr>
887 <?php } else { ?>
888 <tr>
889 <td colspan="2"><?php _e( 'No Emails Found', 'give' ); ?></td>
890 </tr>
891 <?php
892 }// End if().
893 ?>
894 </tbody>
895 </table>
896
897 <h3><?php _e( 'Recent Donations', 'give' ); ?></h3>
898 <?php
899 $payment_ids = explode( ',', $donor->payment_ids );
900 $payments = give_get_payments(
901 array(
902 'post__in' => $payment_ids,
903 )
904 );
905 $payments = array_slice( $payments, 0, 10 );
906 ?>
907 <table class="wp-list-table widefat striped payments">
908 <thead>
909 <tr>
910 <th scope="col"><?php _e( 'ID', 'give' ); ?></th>
911 <th scope="col"><?php _e( 'Amount', 'give' ); ?></th>
912 <th scope="col"><?php _e( 'Date', 'give' ); ?></th>
913 <th scope="col"><?php _e( 'Status', 'give' ); ?></th>
914 <th scope="col"><?php _e( 'Actions', 'give' ); ?></th>
915 </tr>
916 </thead>
917 <tbody>
918 <?php if ( ! empty( $payments ) ) { ?>
919 <?php foreach ( $payments as $payment ) : ?>
920 <tr>
921 <td><?php echo Give()->seq_donation_number->get_serial_code( $payment->ID ); ?></td>
922 <td>
923 <?php
924 echo give_donation_amount(
925 $payment->ID,
926 array(
927 'currency' => true,
928 'amount' => true,
929 'type' => 'donor',
930 )
931 );
932 ?>
933 </td>
934 <td><?php echo date_i18n( give_date_format(), strtotime( $payment->post_date ) ); ?></td>
935 <td><?php echo give_get_payment_status( $payment, true ); ?></td>
936 <td>
937 <?php
938 printf(
939 '<a href="%1$s" aria-label="%2$s">%3$s</a>',
940 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment->ID ),
941 sprintf(
942 /* translators: %s: Donation ID */
943 esc_attr__( 'View Donation %s.', 'give' ),
944 $payment->ID
945 ),
946 __( 'View Donation', 'give' )
947 );
948 ?>
949
950 <?php
951 /**
952 * Fires in donor profile screen, in the recent donations tables action links.
953 *
954 * Allows you to add more action links for each donation, after the 'View Donation' action link.
955 *
956 * @since 1.0
957 *
958 * @param object $donor The donor object being displayed.
959 * @param object $payment The payment object being displayed.
960 */
961 do_action( 'give_donor_recent_purchases_actions', $donor, $payment );
962 ?>
963 </td>
964 </tr>
965 <?php endforeach; ?>
966 <?php } else { ?>
967 <tr>
968 <td colspan="5"><?php _e( 'No donations found.', 'give' ); ?></td>
969 </tr>
970 <?php
971 }// End if().
972 ?>
973 </tbody>
974 </table>
975
976 <h3><?php _e( 'Completed Forms', 'give' ); ?></h3>
977 <?php
978 $donations = give_get_users_completed_donations( $donor->email );
979 ?>
980 <table class="wp-list-table widefat striped donations">
981 <thead>
982 <tr>
983 <th scope="col"><?php _e( 'Form', 'give' ); ?></th>
984 <th scope="col" width="120px"><?php _e( 'Actions', 'give' ); ?></th>
985 </tr>
986 </thead>
987 <tbody>
988 <?php if ( ! empty( $donations ) ) { ?>
989 <?php foreach ( $donations as $donation ) : ?>
990 <tr>
991 <td><?php echo $donation->post_title; ?></td>
992 <td>
993 <?php
994 printf(
995 '<a href="%1$s" aria-label="%2$s">%3$s</a>',
996 esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ),
997 sprintf(
998 /* translators: %s: form name */
999 esc_attr__( 'View Form %s.', 'give' ),
1000 $donation->post_title
1001 ),
1002 __( 'View Form', 'give' )
1003 );
1004 ?>
1005 </td>
1006 </tr>
1007 <?php endforeach; ?>
1008 <?php } else { ?>
1009 <tr>
1010 <td colspan="2"><?php _e( 'No completed donations found.', 'give' ); ?></td>
1011 </tr>
1012 <?php } ?>
1013 </tbody>
1014 </table>
1015 <?php
1016 /**
1017 * Fires in donor profile screen, below the tables.
1018 *
1019 * @since 1.0
1020 *
1021 * @param object $donor The donor object being displayed.
1022 */
1023 do_action( 'give_donor_after_tables', $donor );
1024 ?>
1025
1026 </div>
1027
1028 <?php
1029 /**
1030 * Fires in donor profile screen, below the donor card.
1031 *
1032 * @since 1.0
1033 *
1034 * @param object $donor The donor object being displayed.
1035 */
1036 do_action( 'give_donor_card_bottom', $donor );
1037
1038 }
1039
1040 /**
1041 * View the notes of a donor.
1042 *
1043 * @since 4.6.0 Escape donor note
1044 * @since 1.0
1045 *
1046 * @param Give_Donor $donor The donor object being displayed.
1047 *
1048 * @return void
1049 */
1050 function give_donor_notes_view( $donor ) {
1051
1052 $paged = isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) ? $_GET['paged'] : 1;
1053 $paged = absint( $paged );
1054 $note_count = $donor->get_notes_count();
1055 $per_page = apply_filters( 'give_donor_notes_per_page', 20 );
1056 $total_pages = ceil( $note_count / $per_page );
1057 $donor_notes = $donor->get_notes( $per_page, $paged );
1058 ?>
1059
1060 <div id="donor-notes-wrapper">
1061 <div class="donor-notes-header">
1062 <?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
1063 </div>
1064 <h3><?php _e( 'Notes', 'give' ); ?></h3>
1065
1066 <?php if ( 1 == $paged ) : ?>
1067 <div style="display: block; margin-bottom: 55px;">
1068 <form id="give-add-donor-note" method="post"
1069 action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor->id ); ?>">
1070 <textarea id="donor-note" name="donor_note" class="donor-note-input" rows="10"></textarea>
1071 <br/>
1072 <input type="hidden" id="donor-id" name="customer_id" value="<?php echo $donor->id; ?>"/>
1073 <input type="hidden" name="give_action" value="add-donor-note"/>
1074 <?php wp_nonce_field( 'add-donor-note', 'add_donor_note_nonce', true, true ); ?>
1075 <input id="add-donor-note" class="right button-primary" type="submit" value="Add Note"/>
1076 </form>
1077 </div>
1078 <?php endif; ?>
1079
1080 <?php
1081 $pagination_args = array(
1082 'base' => '%_%',
1083 'format' => '?paged=%#%',
1084 'total' => $total_pages,
1085 'current' => $paged,
1086 'show_all' => true,
1087 );
1088
1089 echo paginate_links( $pagination_args );
1090 ?>
1091
1092 <div id="give-donor-notes" class="postbox">
1093 <?php if ( count( $donor_notes ) > 0 ) { ?>
1094 <?php foreach ( $donor_notes as $key => $note ) : ?>
1095 <div class="donor-note-wrapper dashboard-comment-wrap comment-item">
1096 <span class="note-content-wrap">
1097 <?php echo stripslashes( esc_html( $note ) ); ?>
1098 </span>
1099 </div>
1100 <?php endforeach; ?>
1101 <?php } else { ?>
1102 <div class="give-no-donor-notes">
1103 <?php _e( 'No donor notes found.', 'give' ); ?>
1104 </div>
1105 <?php } ?>
1106 </div>
1107
1108 <?php echo paginate_links( $pagination_args ); ?>
1109
1110 </div>
1111
1112 <?php
1113 }
1114
1115 /**
1116 * The donor delete view.
1117 *
1118 * @since 1.0
1119 *
1120 * @param object $donor The donor object being displayed.
1121 *
1122 * @return void
1123 */
1124 function give_donor_delete_view( $donor ) {
1125
1126 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
1127
1128 /**
1129 * Fires in donor delete screen, above the content.
1130 *
1131 * @since 1.0
1132 *
1133 * @param object $donor The donor object being displayed.
1134 */
1135 do_action( 'give_donor_delete_top', $donor );
1136 ?>
1137
1138 <div class="info-wrapper donor-section">
1139
1140 <form id="delete-donor" method="post"
1141 action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor->id ); ?>">
1142
1143 <div class="donor-notes-header">
1144 <?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
1145 </div>
1146
1147
1148 <div class="donor-info delete-donor">
1149
1150 <span class="delete-donor-options">
1151 <p>
1152 <?php
1153 echo Give()->html->checkbox(
1154 array(
1155 'name' => 'give-donor-delete-confirm',
1156 )
1157 );
1158 ?>
1159 <label
1160 for="give-donor-delete-confirm"><?php _e( 'Are you sure you want to delete this donor?', 'give' ); ?></label>
1161 </p>
1162
1163 <p>
1164 <?php
1165 echo Give()->html->checkbox(
1166 array(
1167 'name' => 'give-donor-delete-records',
1168 'options' => array(
1169 'disabled' => true,
1170 ),
1171 )
1172 );
1173 ?>
1174 <label
1175 for="give-donor-delete-records"><?php _e( 'Delete all associated donations and records?', 'give' ); ?></label>
1176 </p>
1177
1178 <?php
1179 /**
1180 * Fires in donor delete screen, bellow the delete inputs.
1181 *
1182 * Allows you to add custom delete inputs.
1183 *
1184 * @since 1.0
1185 *
1186 * @param object $donor The donor object being displayed.
1187 */
1188 do_action( 'give_donor_delete_inputs', $donor );
1189 ?>
1190 </span>
1191
1192 <span id="donor-edit-actions">
1193 <input type="hidden" name="donor_id" value="<?php echo $donor->id; ?>"/>
1194 <?php wp_nonce_field( 'give-delete-donor', '_wpnonce', false, true ); ?>
1195 <input type="hidden" name="give_action" value="delete_donor"/>
1196 <input type="submit" disabled="disabled" id="give-delete-donor" class="button-primary"
1197 value="<?php _e( 'Delete Donor', 'give' ); ?>"/>
1198 <a id="give-delete-donor-cancel"
1199 href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ); ?>"
1200 class="delete"><?php _e( 'Cancel', 'give' ); ?></a>
1201 </span>
1202
1203 </div>
1204
1205 </form>
1206 </div>
1207
1208 <?php
1209 /**
1210 * Fires in donor delete screen, bellow the content.
1211 *
1212 * @since 1.0
1213 *
1214 * @param object $donor The donor object being displayed.
1215 */
1216 do_action( 'give_donor_delete_bottom', $donor );
1217 }
1218