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