PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.16.5
GiveWP – Donation Plugin and Fundraising Platform v4.16.5
4.16.5 4.16.4 4.16.3 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 1 week ago
donors.php
1219 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 4.16.4 Escaped the donor company and phone output.
312 * @since 3.7.0 Add "phone" field
313 * @since 1.0
314 *
315 * @param Give_Donor $donor The Donor object being displayed.
316 *
317 * @return void
318 */
319 function give_donor_view( $donor ) {
320
321 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
322
323 /**
324 * Fires in donor profile screen, above the donor card.
325 *
326 * @since 1.0
327 *
328 * @param object $donor The donor object being displayed.
329 */
330 do_action( 'give_donor_card_top', $donor );
331
332 // Set Read only to the fields which needs to be locked.
333 $read_only = '';
334 if ( $donor->user_id ) {
335 $read_only = 'readonly="readonly"';
336 }
337
338 // List of title prefixes.
339 $title_prefixes = give_get_name_title_prefixes();
340
341 // Prepend title prefix to name if it is set.
342 $title_prefix = Give()->donor_meta->get_meta( $donor->id, '_give_donor_title_prefix', true );
343 $donor_name_without_prefix = $donor->name;
344 $donor->name = give_get_donor_name_with_title_prefixes( $title_prefix, $donor->name );
345 ?>
346 <div id="donor-summary" class="info-wrapper donor-section postbox">
347 <form id="edit-donor-info" method="post"
348 action="<?php echo esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ) ); ?>">
349 <div class="donor-info">
350 <div class="donor-bio-header clearfix">
351 <div class="avatar-wrap left" id="donor-avatar">
352 <?php
353
354 // Check whether a Gravatar exists for a donor or not.
355 $validate_gravatar_image = give_validate_gravatar( $donor->email );
356
357 // Get donor's initials for non-gravatars
358 $donor_name_array = explode( ' ', $donor_name_without_prefix );
359 $donor_name_args['firstname'] = ! empty( $donor_name_array[0] ) ? $donor_name_array[0] : '';
360 $donor_name_args['lastname'] = ! empty( $donor_name_array[1] ) ? $donor_name_array[1] : '';
361 $donor_name_initial = give_get_name_initial( $donor_name_args );
362
363 // Gravatars image for donor
364 if ( $validate_gravatar_image ) {
365 $donor_gravatar_image = get_avatar( $donor->email );
366 } else {
367 $donor_gravatar_image = '<div class="give-donor-admin-avatar">' . $donor_name_initial . '</div>';
368 }
369
370 echo $donor_gravatar_image;
371 ?>
372 </div>
373 <div id="donor-name-wrap" class="left">
374 <span class="donor-name info-item edit-item">
375 <select name="donor_info[title]">
376 <option disabled value="0"><?php esc_html_e( 'Title', 'give' ); ?></option>
377 <option value="">&nbsp;</option>
378 <?php
379 if ( is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) {
380 foreach ( $title_prefixes as $title ) {
381 echo sprintf(
382 '<option %1$s value="%2$s">%2$s</option>',
383 selected( $title_prefix, $title, false ),
384 esc_html( $title )
385 );
386 }
387 }
388 ?>
389 </select>
390 <input <?php echo $read_only; ?> size="15" data-key="first_name"
391 name="donor_info[first_name]" type="text"
392 value="<?php echo esc_html( $donor->get_first_name() ); ?>"
393 placeholder="<?php esc_html_e( 'First Name', 'give' ); ?>"/>
394 <?php if ( $donor->user_id ) : ?>
395 <a href="#" class="give-lock-block">
396 <i class="give-icon give-icon-locked"></i>
397 </a>
398 <?php endif; ?>
399 <input <?php echo $read_only; ?> size="15" data-key="last_name"
400 name="donor_info[last_name]" type="text"
401 value="<?php echo esc_html( $donor->get_last_name() ); ?>"
402 placeholder="<?php esc_html_e( 'Last Name', 'give' ); ?>"/>
403 <?php if ( $donor->user_id ) : ?>
404 <a href="#" class="give-lock-block">
405 <i class="give-icon give-icon-locked"></i>
406 </a>
407 <?php endif; ?>
408 </span>
409 <span class="donor-name info-item editable">
410 <span data-key="name"><?php echo esc_html( $donor->name ); ?></span>
411 </span>
412 </div>
413 <p class="donor-since info-item">
414 <?php esc_html_e( 'Donor since', 'give' ); ?>
415 <?php echo date_i18n( give_date_format(), strtotime( $donor->date_created ) ); ?>
416 </p>
417 <?php if ( current_user_can( $donor_edit_role ) ) : ?>
418 <a href="#" id="edit-donor" class="button info-item editable donor-edit-link">
419 <?php esc_html_e( 'Edit Donor', 'give' ); ?>
420 </a>
421 <?php endif; ?>
422 </div>
423 <!-- /donor-bio-header -->
424
425 <div class="donor-main-wrapper">
426
427 <table class="widefat striped">
428 <tbody>
429 <tr>
430 <th scope="col"><label for="tablecell"><?php esc_html_e( 'Donor ID:', 'give' ); ?></label>
431 </th>
432 <td><?php echo intval( $donor->id ); ?></td>
433 </tr>
434 <tr>
435 <th scope="col"><label for="tablecell"><?php esc_html_e( 'User ID:', 'give' ); ?></label>
436 </th>
437 <td>
438 <span class="donor-user-id info-item edit-item">
439 <?php
440
441 $user_id = $donor->user_id > 0 ? $donor->user_id : '';
442
443 $data_atts = array(
444 'key' => 'user_login',
445 'search-type' => 'user',
446 );
447 $user_args = array(
448 'name' => 'donor_info[user_id]',
449 'class' => 'give-user-dropdown',
450 'data' => $data_atts,
451 );
452
453 if ( ! empty( $user_id ) ) {
454 $userdata = get_userdata( $user_id );
455 $user_args['selected'] = $user_id;
456 }
457
458 echo Give()->html->ajax_user_search( $user_args );
459 ?>
460 </span>
461
462 <span class="donor-user-id info-item editable">
463 <?php if ( ! empty( $userdata ) ) : ?>
464 <span
465 data-key="user_id">#<?php echo $donor->user_id . ' - ' . $userdata->display_name; ?></span>
466 <?php else : ?>
467 <span
468 data-key="user_id"><?php esc_html_e( 'Unregistered', 'give' ); ?></span>
469 <?php endif; ?>
470 <?php
471 if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ) :
472
473 echo sprintf(
474 '- <span class="disconnect-user">
475 <a id="disconnect-donor" href="#disconnect" aria-label="%1$s">%2$s</a>
476 </span> |
477 <span class="view-user-profile">
478 <a id="view-user-profile" href="%3$s" aria-label="%4$s">%5$s</a>
479 </span>',
480 esc_html__( 'Disconnects the current user ID from this donor record.', 'give' ),
481 esc_html__( 'Disconnect User', 'give' ),
482 esc_url( 'user-edit.php?user_id=' . $donor->user_id ),
483 esc_html__( 'View User Profile of current user ID.', 'give' ),
484 esc_html__( 'View User Profile', 'give' )
485 );
486
487 endif;
488 ?>
489 </span>
490 </td>
491 </tr>
492
493 <?php
494
495 $donor_phone_number = Donor::find($donor->id)->phone;
496 ?>
497 <tr class="alternate">
498 <th scope="col">
499 <label for="tablecell"><?php
500 esc_html_e('Phone:', 'give'); ?></label>
501 </th>
502 <td>
503 <span class="donor-user-id info-item edit-item">
504 <?php
505 echo IntlTelInput::getHtmlInput($donor_phone_number, "give_donor_phone_number"); ?>
506 </span>
507
508 <span class="donor-user-id info-item editable">
509 <?php
510 echo esc_html( $donor_phone_number ); ?>
511 </span>
512 </td>
513 </tr>
514 <?php
515 $donor_company = $donor->get_meta( '_give_donor_company', true );
516 ?>
517 <tr class="">
518 <th scope="col">
519 <label for="tablecell"><?php esc_html_e( 'Company Name:', 'give' ); ?></label>
520 </th>
521 <td>
522 <span class="donor-user-id info-item edit-item">
523 <input name="give_donor_company" value="<?php echo esc_attr( $donor_company ); ?>" type="text">
524 </span>
525
526 <span class="donor-user-id info-item editable">
527 <?php echo esc_html( $donor_company ); ?>
528 </span>
529 </td>
530 </tr>
531 </tbody>
532 </table>
533 </div>
534
535 </div>
536
537 <span id="donor-edit-actions" class="edit-item">
538 <input type="hidden" data-key="id" name="donor_info[id]" value="<?php echo intval( $donor->id ); ?>"/>
539 <?php wp_nonce_field( 'edit-donor', '_wpnonce', false, true ); ?>
540 <input type="hidden" name="give_action" value="edit-donor"/>
541 <input type="submit" id="give-edit-donor-save" class="button-secondary"
542 value="<?php esc_html_e( 'Update Donor', 'give' ); ?>"/>
543 <a id="give-edit-donor-cancel" href="" class="delete"><?php esc_html_e( 'Cancel', 'give' ); ?></a>
544 </span>
545
546 </form>
547
548 </div>
549
550 <?php
551 /**
552 * Fires in donor profile screen, above the stats list.
553 *
554 * @since 1.0
555 *
556 * @param Give_Donor $donor The donor object being displayed.
557 */
558 do_action( 'give_donor_before_stats', $donor );
559 ?>
560
561 <div id="donor-stats-wrapper" class="donor-section postbox clear">
562 <ul>
563 <li>
564 <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor->id ) ); ?>">
565 <span class="dashicons dashicons-heart"></span>
566 <?php
567 // Completed Donations.
568 $completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $donor->purchase_count, 'give' ), $donor->purchase_count );
569 echo apply_filters( 'give_donor_completed_donations', $completed_donations_text, $donor );
570 ?>
571 </a>
572 </li>
573 <li>
574 <span class="dashicons dashicons-chart-area"></span>
575 <?php echo give_currency_filter( give_format_amount( $donor->get_total_donation_amount(), array( 'sanitize' => false ) ) ); ?> <?php _e( 'Lifetime Donations', 'give' ); ?>
576 </li>
577 <?php
578 /**
579 * Fires in donor profile screen, in the stats list.
580 *
581 * Allows you to add more list items to the stats list.
582 *
583 * @since 1.0
584 *
585 * @param object $donor The donor object being displayed.
586 */
587 do_action( 'give_donor_stats_list', $donor );
588 ?>
589 </ul>
590 </div>
591
592 <?php
593 /**
594 * Fires in donor profile screen, above the address list.
595 *
596 * @since 1.8.14
597 *
598 * @param Give_Donor $donor The donor object being displayed.
599 */
600 do_action( 'give_donor_before_address', $donor );
601 ?>
602
603 <div id="donor-address-wrapper" class="donor-section clear">
604 <h3><?php _e( 'Addresses', 'give' ); ?></h3>
605
606 <div class="postbox give-donor-addresses">
607 <div class="give-spinner-wrapper">
608 <span class="give-spinner spinner aligncenter"></span>
609 </div>
610 <div class="inside">
611 <div class="all-address">
612 <div class="give-grid-row">
613 <?php
614 if ( ! empty( $donor->address ) ) :
615 // Default address always will be at zero array index.
616 $is_set_as_default = null;
617
618 foreach ( $donor->address as $address_type => $addresses ) {
619
620 switch ( true ) {
621 case is_array( end( $addresses ) ):
622 $index = 1;
623 foreach ( $addresses as $id => $address ) {
624 echo give_get_format_address(
625 $address,
626 array(
627 'type' => $address_type,
628 'id' => $id,
629 'index' => $index,
630 )
631 );
632
633 $index ++;
634 }
635 break;
636
637 case is_string( end( $addresses ) ):
638 echo give_get_format_address(
639 $addresses,
640 array(
641 'type' => $address_type,
642 )
643 );
644 break;
645 }
646 }
647 endif;
648 ?>
649 </div>
650 <span class="give-no-address-message
651 <?php
652 if ( ! empty( $donor->address ) ) {
653 echo ' give-hidden';
654 }
655 ?>
656 ">
657 <?php _e( 'This donor does not have any addresses saved.', 'give' ); ?>
658 </span>
659 <button class="button add-new-address">
660 <?php _e( 'Add Address', 'give' ); ?>
661 </button>
662 </div>
663
664 <div class="address-form add-new-address-form-hidden">
665 <form action="" method="post">
666 <table class="widefat striped">
667 <tbody>
668 <tr>
669 <th class="col">
670 <label class="country"><?php esc_html_e( 'Country:', 'give' ); ?></label>
671 </th>
672 <td>
673 <?php
674 echo Give()->html->select(
675 array(
676 'options' => give_get_country_list(),
677 'name' => 'country',
678 'selected' => give_get_option( 'base_country' ),
679 'show_option_all' => false,
680 'show_option_none' => false,
681 'chosen' => true,
682 'placeholder' => esc_attr__( 'Select a country', 'give' ),
683 'data' => array( 'search-type' => 'no_ajax' ),
684 'autocomplete' => 'country',
685 )
686 );
687 ?>
688 </td>
689 </tr>
690 <tr>
691 <th class="col">
692 <label for="line1"><?php esc_html_e( 'Address 1:', 'give' ); ?></label>
693 </th>
694 <td>
695 <input id="line1" name="line1" type="text" class="medium-text"/>
696 </td>
697 </tr>
698 <tr>
699 <th class="col">
700 <label for="line2"><?php esc_html_e( 'Address 2:', 'give' ); ?></label>
701 </th>
702 <td>
703 <input id="line2" type="text" name="line2" value="" class="medium-text"/>
704
705 </td>
706 </tr>
707 <tr>
708 <th class="col">
709 <label for="city"><?php esc_html_e( 'City:', 'give' ); ?></label>
710 </th>
711 <td>
712 <input id="city" type="text" name="city" value="" class="medium-text"/>
713 </td>
714 </tr>
715 <?php
716 $no_states_country = give_no_states_country_list();
717 $base_country = give_get_option( 'base_country' );
718 if ( ! array_key_exists( $base_country, $no_states_country ) ) {
719 ?>
720 <tr class="give-field-wrap">
721 <th class="col">
722 <label
723 for="state"><?php esc_html_e( 'State / Province / County:', 'give' ); ?></label>
724 </th>
725 <td>
726 <?php
727 $states = give_get_states( $base_country );
728 $state_args = array(
729 'name' => 'state',
730 'class' => 'regular-text',
731 'autocomplete' => 'address-level1',
732 );
733
734 if ( empty( $states ) ) {
735
736 // Show Text field, if empty states.
737 $state_args = wp_parse_args(
738 $state_args,
739 array(
740 'value' => give_get_option( 'base_state' ),
741 )
742 );
743 echo Give()->html->text( $state_args );
744 } else {
745
746 // Show Chosen DropDown, if states are not empty.
747 $state_args = wp_parse_args(
748 $state_args,
749 array(
750 'options' => $states,
751 'selected' => give_get_option( 'base_state' ),
752 'show_option_all' => false,
753 'show_option_none' => false,
754 'chosen' => true,
755 'placeholder' => __( 'Select a state', 'give' ),
756 'data' => array( 'search-type' => 'no_ajax' ),
757 )
758 );
759 echo Give()->html->select( $state_args );
760 }
761 ?>
762 </td>
763 </tr>
764 <?php
765 }
766 ?>
767 <tr>
768 <th class="col">
769 <label for="zip"><?php esc_html_e( 'Zip / Postal Code:', 'give' ); ?></label>
770 </th>
771 <td>
772 <input id="zip" type="text" name="zip" value="" class="medium-text"/>
773 </td>
774 </tr>
775 <tr>
776 <td colspan="2">
777 <?php wp_nonce_field( 'give-manage-donor-addresses', '_wpnonce', false ); ?>
778 <input type="hidden" name="address-action" value="add">
779 <input type="hidden" name="address-id" value="">
780 <input type="submit" class="button button-primary js-save"
781 value="<?php _e( 'Save', 'give' ); ?>">&nbsp;&nbsp;<button
782 class="button js-cancel"><?php _e( 'Cancel', 'give' ); ?></button>
783 </td>
784 </tr>
785 </tbody>
786 </table>
787 </form>
788 </div>
789 </div>
790 </div>
791 </div>
792
793 <?php
794 /**
795 * Fires in donor profile screen, above the tables wrapper.
796 *
797 * @since 1.0
798 *
799 * @param Give_Donor $donor The donor object being displayed.
800 */
801 do_action( 'give_donor_before_tables_wrapper', $donor );
802 ?>
803
804 <div id="donor-tables-wrapper" class="donor-section">
805
806 <?php
807 /**
808 * Fires in donor profile screen, above the tables.
809 *
810 * @since 1.0
811 *
812 * @param object $donor The donor object being displayed.
813 */
814 do_action( 'give_donor_before_tables', $donor );
815 ?>
816
817 <h3><?php _e( 'Donor Emails', 'give' ); ?></h3>
818
819 <table class="wp-list-table widefat striped emails">
820 <thead>
821 <tr>
822 <th><?php _e( 'Email', 'give' ); ?></th>
823 <th><?php _e( 'Actions', 'give' ); ?></th>
824 </tr>
825 </thead>
826
827 <tbody>
828 <?php if ( ! empty( $donor->emails ) ) { ?>
829
830 <?php foreach ( $donor->emails as $key => $email ) : ?>
831 <tr data-key="<?php echo $key; ?>">
832 <td>
833 <?php echo $email; ?>
834 <?php if ( 'primary' === $key ) : ?>
835 <span class="dashicons dashicons-star-filled primary-email-icon"></span>
836 <?php endif; ?>
837 </td>
838 <td>
839 <?php if ( 'primary' !== $key ) : ?>
840 <?php
841 $base_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id );
842 $promote_url = wp_nonce_url(
843 add_query_arg(
844 array(
845 'email' => rawurlencode( $email ),
846 'give_action' => 'set_donor_primary_email',
847 ),
848 $base_url
849 ),
850 'give-set-donor-primary-email'
851 );
852 $remove_url = wp_nonce_url(
853 add_query_arg(
854 array(
855 'email' => rawurlencode( $email ),
856 'give_action' => 'remove_donor_email',
857 ),
858 $base_url
859 ),
860 'give-remove-donor-email'
861 );
862 ?>
863 <a href="<?php echo esc_url( $promote_url ); ?>"><?php _e( 'Make Primary', 'give' ); ?></a>
864 &nbsp;|&nbsp;
865 <a href="<?php echo esc_url( $remove_url ); ?>" class="delete"><?php _e( 'Remove', 'give' ); ?></a>
866 <?php endif; ?>
867 </td>
868 </tr>
869 <?php endforeach; ?>
870
871 <tr class="add-donor-email-row">
872 <td colspan="2" class="add-donor-email-td">
873 <div class="add-donor-email-wrapper">
874 <input type="hidden" name="donor-id" value="<?php echo $donor->id; ?>"/>
875 <?php wp_nonce_field( 'give_add_donor_email', 'add_email_nonce', false, true ); ?>
876 <input type="email" name="additional-email" value=""
877 placeholder="<?php _e( 'Email Address', 'give' ); ?>"/>&nbsp;
878 <input type="checkbox" name="make-additional-primary" value="1"
879 id="make-additional-primary"/>&nbsp;<label
880 for="make-additional-primary"><?php _e( 'Make Primary', 'give' ); ?></label>
881 <button class="button-secondary give-add-donor-email"
882 id="add-donor-email"><?php _e( 'Add Email', 'give' ); ?></button>
883 <span class="spinner"></span>
884 </div>
885 <div class="notice-wrap"></div>
886 </td>
887 </tr>
888 <?php } else { ?>
889 <tr>
890 <td colspan="2"><?php _e( 'No Emails Found', 'give' ); ?></td>
891 </tr>
892 <?php
893 }// End if().
894 ?>
895 </tbody>
896 </table>
897
898 <h3><?php _e( 'Recent Donations', 'give' ); ?></h3>
899 <?php
900 $payment_ids = explode( ',', $donor->payment_ids );
901 $payments = give_get_payments(
902 array(
903 'post__in' => $payment_ids,
904 )
905 );
906 $payments = array_slice( $payments, 0, 10 );
907 ?>
908 <table class="wp-list-table widefat striped payments">
909 <thead>
910 <tr>
911 <th scope="col"><?php _e( 'ID', 'give' ); ?></th>
912 <th scope="col"><?php _e( 'Amount', 'give' ); ?></th>
913 <th scope="col"><?php _e( 'Date', 'give' ); ?></th>
914 <th scope="col"><?php _e( 'Status', 'give' ); ?></th>
915 <th scope="col"><?php _e( 'Actions', 'give' ); ?></th>
916 </tr>
917 </thead>
918 <tbody>
919 <?php if ( ! empty( $payments ) ) { ?>
920 <?php foreach ( $payments as $payment ) : ?>
921 <tr>
922 <td><?php echo Give()->seq_donation_number->get_serial_code( $payment->ID ); ?></td>
923 <td>
924 <?php
925 echo give_donation_amount(
926 $payment->ID,
927 array(
928 'currency' => true,
929 'amount' => true,
930 'type' => 'donor',
931 )
932 );
933 ?>
934 </td>
935 <td><?php echo date_i18n( give_date_format(), strtotime( $payment->post_date ) ); ?></td>
936 <td><?php echo give_get_payment_status( $payment, true ); ?></td>
937 <td>
938 <?php
939 printf(
940 '<a href="%1$s" aria-label="%2$s">%3$s</a>',
941 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment->ID ),
942 sprintf(
943 /* translators: %s: Donation ID */
944 esc_attr__( 'View Donation %s.', 'give' ),
945 $payment->ID
946 ),
947 __( 'View Donation', 'give' )
948 );
949 ?>
950
951 <?php
952 /**
953 * Fires in donor profile screen, in the recent donations tables action links.
954 *
955 * Allows you to add more action links for each donation, after the 'View Donation' action link.
956 *
957 * @since 1.0
958 *
959 * @param object $donor The donor object being displayed.
960 * @param object $payment The payment object being displayed.
961 */
962 do_action( 'give_donor_recent_purchases_actions', $donor, $payment );
963 ?>
964 </td>
965 </tr>
966 <?php endforeach; ?>
967 <?php } else { ?>
968 <tr>
969 <td colspan="5"><?php _e( 'No donations found.', 'give' ); ?></td>
970 </tr>
971 <?php
972 }// End if().
973 ?>
974 </tbody>
975 </table>
976
977 <h3><?php _e( 'Completed Forms', 'give' ); ?></h3>
978 <?php
979 $donations = give_get_users_completed_donations( $donor->email );
980 ?>
981 <table class="wp-list-table widefat striped donations">
982 <thead>
983 <tr>
984 <th scope="col"><?php _e( 'Form', 'give' ); ?></th>
985 <th scope="col" width="120px"><?php _e( 'Actions', 'give' ); ?></th>
986 </tr>
987 </thead>
988 <tbody>
989 <?php if ( ! empty( $donations ) ) { ?>
990 <?php foreach ( $donations as $donation ) : ?>
991 <tr>
992 <td><?php echo $donation->post_title; ?></td>
993 <td>
994 <?php
995 printf(
996 '<a href="%1$s" aria-label="%2$s">%3$s</a>',
997 esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ),
998 sprintf(
999 /* translators: %s: form name */
1000 esc_attr__( 'View Form %s.', 'give' ),
1001 $donation->post_title
1002 ),
1003 __( 'View Form', 'give' )
1004 );
1005 ?>
1006 </td>
1007 </tr>
1008 <?php endforeach; ?>
1009 <?php } else { ?>
1010 <tr>
1011 <td colspan="2"><?php _e( 'No completed donations found.', 'give' ); ?></td>
1012 </tr>
1013 <?php } ?>
1014 </tbody>
1015 </table>
1016 <?php
1017 /**
1018 * Fires in donor profile screen, below the tables.
1019 *
1020 * @since 1.0
1021 *
1022 * @param object $donor The donor object being displayed.
1023 */
1024 do_action( 'give_donor_after_tables', $donor );
1025 ?>
1026
1027 </div>
1028
1029 <?php
1030 /**
1031 * Fires in donor profile screen, below the donor card.
1032 *
1033 * @since 1.0
1034 *
1035 * @param object $donor The donor object being displayed.
1036 */
1037 do_action( 'give_donor_card_bottom', $donor );
1038
1039 }
1040
1041 /**
1042 * View the notes of a donor.
1043 *
1044 * @since 4.6.0 Escape donor note
1045 * @since 1.0
1046 *
1047 * @param Give_Donor $donor The donor object being displayed.
1048 *
1049 * @return void
1050 */
1051 function give_donor_notes_view( $donor ) {
1052
1053 $paged = isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) ? $_GET['paged'] : 1;
1054 $paged = absint( $paged );
1055 $note_count = $donor->get_notes_count();
1056 $per_page = apply_filters( 'give_donor_notes_per_page', 20 );
1057 $total_pages = ceil( $note_count / $per_page );
1058 $donor_notes = $donor->get_notes( $per_page, $paged );
1059 ?>
1060
1061 <div id="donor-notes-wrapper">
1062 <div class="donor-notes-header">
1063 <?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
1064 </div>
1065 <h3><?php _e( 'Notes', 'give' ); ?></h3>
1066
1067 <?php if ( 1 == $paged ) : ?>
1068 <div style="display: block; margin-bottom: 55px;">
1069 <form id="give-add-donor-note" method="post"
1070 action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=notes&id=' . $donor->id ); ?>">
1071 <textarea id="donor-note" name="donor_note" class="donor-note-input" rows="10"></textarea>
1072 <br/>
1073 <input type="hidden" id="donor-id" name="customer_id" value="<?php echo $donor->id; ?>"/>
1074 <input type="hidden" name="give_action" value="add-donor-note"/>
1075 <?php wp_nonce_field( 'add-donor-note', 'add_donor_note_nonce', true, true ); ?>
1076 <input id="add-donor-note" class="right button-primary" type="submit" value="Add Note"/>
1077 </form>
1078 </div>
1079 <?php endif; ?>
1080
1081 <?php
1082 $pagination_args = array(
1083 'base' => '%_%',
1084 'format' => '?paged=%#%',
1085 'total' => $total_pages,
1086 'current' => $paged,
1087 'show_all' => true,
1088 );
1089
1090 echo paginate_links( $pagination_args );
1091 ?>
1092
1093 <div id="give-donor-notes" class="postbox">
1094 <?php if ( count( $donor_notes ) > 0 ) { ?>
1095 <?php foreach ( $donor_notes as $key => $note ) : ?>
1096 <div class="donor-note-wrapper dashboard-comment-wrap comment-item">
1097 <span class="note-content-wrap">
1098 <?php echo stripslashes( esc_html( $note ) ); ?>
1099 </span>
1100 </div>
1101 <?php endforeach; ?>
1102 <?php } else { ?>
1103 <div class="give-no-donor-notes">
1104 <?php _e( 'No donor notes found.', 'give' ); ?>
1105 </div>
1106 <?php } ?>
1107 </div>
1108
1109 <?php echo paginate_links( $pagination_args ); ?>
1110
1111 </div>
1112
1113 <?php
1114 }
1115
1116 /**
1117 * The donor delete view.
1118 *
1119 * @since 1.0
1120 *
1121 * @param object $donor The donor object being displayed.
1122 *
1123 * @return void
1124 */
1125 function give_donor_delete_view( $donor ) {
1126
1127 $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
1128
1129 /**
1130 * Fires in donor delete screen, above the content.
1131 *
1132 * @since 1.0
1133 *
1134 * @param object $donor The donor object being displayed.
1135 */
1136 do_action( 'give_donor_delete_top', $donor );
1137 ?>
1138
1139 <div class="info-wrapper donor-section">
1140
1141 <form id="delete-donor" method="post"
1142 action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor->id ); ?>">
1143
1144 <div class="donor-notes-header">
1145 <?php echo get_avatar( $donor->email, 30 ); ?> <span><?php echo $donor->name; ?></span>
1146 </div>
1147
1148
1149 <div class="donor-info delete-donor">
1150
1151 <span class="delete-donor-options">
1152 <p>
1153 <?php
1154 echo Give()->html->checkbox(
1155 array(
1156 'name' => 'give-donor-delete-confirm',
1157 )
1158 );
1159 ?>
1160 <label
1161 for="give-donor-delete-confirm"><?php _e( 'Are you sure you want to delete this donor?', 'give' ); ?></label>
1162 </p>
1163
1164 <p>
1165 <?php
1166 echo Give()->html->checkbox(
1167 array(
1168 'name' => 'give-donor-delete-records',
1169 'options' => array(
1170 'disabled' => true,
1171 ),
1172 )
1173 );
1174 ?>
1175 <label
1176 for="give-donor-delete-records"><?php _e( 'Delete all associated donations and records?', 'give' ); ?></label>
1177 </p>
1178
1179 <?php
1180 /**
1181 * Fires in donor delete screen, bellow the delete inputs.
1182 *
1183 * Allows you to add custom delete inputs.
1184 *
1185 * @since 1.0
1186 *
1187 * @param object $donor The donor object being displayed.
1188 */
1189 do_action( 'give_donor_delete_inputs', $donor );
1190 ?>
1191 </span>
1192
1193 <span id="donor-edit-actions">
1194 <input type="hidden" name="donor_id" value="<?php echo $donor->id; ?>"/>
1195 <?php wp_nonce_field( 'give-delete-donor', '_wpnonce', false, true ); ?>
1196 <input type="hidden" name="give_action" value="delete_donor"/>
1197 <input type="submit" disabled="disabled" id="give-delete-donor" class="button-primary"
1198 value="<?php _e( 'Delete Donor', 'give' ); ?>"/>
1199 <a id="give-delete-donor-cancel"
1200 href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=legacy-overview&id=' . $donor->id ); ?>"
1201 class="delete"><?php _e( 'Cancel', 'give' ); ?></a>
1202 </span>
1203
1204 </div>
1205
1206 </form>
1207 </div>
1208
1209 <?php
1210 /**
1211 * Fires in donor delete screen, bellow the content.
1212 *
1213 * @since 1.0
1214 *
1215 * @param object $donor The donor object being displayed.
1216 */
1217 do_action( 'give_donor_delete_bottom', $donor );
1218 }
1219