| Conditions | 22 |
| Paths | 2304 |
| Total Lines | 436 |
| Code Lines | 242 |
| Lines | 6 |
| Ratio | 1.38 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 192 | function give_donor_view( $donor ) { |
||
| 193 | |||
| 194 | $donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' ); |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Fires in donor profile screen, above the donor card. |
||
| 198 | * |
||
| 199 | * @since 1.0 |
||
| 200 | * |
||
| 201 | * @param object $donor The donor object being displayed. |
||
| 202 | */ |
||
| 203 | do_action( 'give_donor_card_top', $donor ); |
||
| 204 | ?> |
||
| 205 | |||
| 206 | <div id="donor-summary" class="info-wrapper donor-section postbox"> |
||
| 207 | |||
| 208 | <form id="edit-donor-info" method="post" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ); ?>"> |
||
| 209 | |||
| 210 | <div class="donor-info"> |
||
| 211 | |||
| 212 | <div class="donor-bio-header clearfix"> |
||
| 213 | |||
| 214 | <div class="avatar-wrap left" id="donor-avatar"> |
||
| 215 | <?php echo get_avatar( $donor->email ); ?> |
||
| 216 | </div> |
||
| 217 | |||
| 218 | <div id="donor-name-wrap" class="left"> |
||
| 219 | <span class="donor-id">#<?php echo $donor->id; ?></span> |
||
| 220 | <span class="donor-name info-item edit-item"><input size="15" data-key="name" name="customerinfo[name]" type="text" value="<?php echo esc_attr( $donor->name ); ?>" placeholder="<?php esc_attr_e( 'Donor Name', 'give' ); ?>" /></span> |
||
| 221 | <span class="donor-name info-item editable"><span data-key="name"><?php echo $donor->name; ?></span></span> |
||
| 222 | </div> |
||
| 223 | <p class="donor-since info-item"> |
||
| 224 | <?php esc_html_e( 'Donor since', 'give' ); ?> |
||
| 225 | <?php echo date_i18n( give_date_format(), strtotime( $donor->date_created ) ) ?> |
||
| 226 | </p> |
||
| 227 | <?php if ( current_user_can( $donor_edit_role ) ) : ?> |
||
| 228 | <a href="#" id="edit-donor" class="button info-item editable donor-edit-link"><?php esc_html_e( 'Edit Donor', 'give' ); ?></a> |
||
| 229 | <?php endif; ?> |
||
| 230 | </div> |
||
| 231 | <!-- /donor-bio-header --> |
||
| 232 | |||
| 233 | <div class="donor-main-wrapper"> |
||
| 234 | |||
| 235 | <table class="widefat"> |
||
| 236 | <tbody> |
||
| 237 | <tr class="alternate"> |
||
| 238 | <th scope="col"><label for="tablecell"><?php esc_html_e( 'User:', 'give' ); ?></label></th> |
||
| 239 | <td> |
||
| 240 | <span class="donor-user-id info-item edit-item"> |
||
| 241 | <?php |
||
| 242 | |||
| 243 | $user_id = $donor->user_id > 0 ? $donor->user_id : ''; |
||
| 244 | |||
| 245 | $data_atts = array( |
||
| 246 | 'key' => 'user_login', |
||
| 247 | 'search-type' => 'user', |
||
| 248 | ); |
||
| 249 | $user_args = array( |
||
| 250 | 'name' => 'customerinfo[user_id]', |
||
| 251 | 'class' => 'give-user-dropdown', |
||
| 252 | 'data' => $data_atts, |
||
| 253 | ); |
||
| 254 | |||
| 255 | if ( ! empty( $user_id ) ) { |
||
| 256 | $userdata = get_userdata( $user_id ); |
||
| 257 | $user_args['selected'] = $user_id; |
||
| 258 | } |
||
| 259 | |||
| 260 | echo Give()->html->ajax_user_search( $user_args ); |
||
| 261 | ?> |
||
| 262 | </span> |
||
| 263 | |||
| 264 | <span class="donor-user-id info-item editable"> |
||
| 265 | <?php if ( ! empty( $userdata ) ) { ?> |
||
| 266 | <span data-key="user_id">#<?php echo $donor->user_id . ' - ' . $userdata->display_name; ?></span> |
||
| 267 | <?php } else { ?> |
||
| 268 | <span data-key="user_id"><?php esc_html_e( 'None', 'give' ); ?></span> |
||
| 269 | <?php } ?> |
||
| 270 | <?php if ( current_user_can( $donor_edit_role ) && intval( $donor->user_id ) > 0 ) { ?> |
||
| 271 | <span class="disconnect-user"> - <a id="disconnect-donor" href="#disconnect" aria-label="<?php esc_attr_e( 'Disconnects the current user ID from this donor record.', 'give' ); ?>"><?php esc_html_e( 'Disconnect User', 'give' ); ?></a></span> |
||
| 272 | <?php } ?> |
||
| 273 | </span> |
||
| 274 | </td> |
||
| 275 | </tr> |
||
| 276 | <?php if ( isset( $donor->user_id ) && $donor->user_id > 0 ) : ?> |
||
| 277 | |||
| 278 | <tr> |
||
| 279 | <th scope="col"><?php esc_html_e( 'Address:', 'give' ); ?></th> |
||
| 280 | <td class="row-title"> |
||
| 281 | |||
| 282 | <div class="donor-address-wrapper"> |
||
| 283 | |||
| 284 | <?php |
||
| 285 | $address = get_user_meta( $donor->user_id, '_give_user_address', true ); |
||
| 286 | $defaults = array( |
||
| 287 | 'line1' => '', |
||
| 288 | 'line2' => '', |
||
| 289 | 'city' => '', |
||
| 290 | 'state' => '', |
||
| 291 | 'country' => '', |
||
| 292 | 'zip' => '', |
||
| 293 | ); |
||
| 294 | |||
| 295 | $address = wp_parse_args( $address, $defaults ); |
||
| 296 | ?> |
||
| 297 | |||
| 298 | <?php if ( ! empty( $address ) ) { ?> |
||
| 299 | <span class="donor-address info-item editable"> |
||
| 300 | <span class="info-item" data-key="line1"><?php echo $address['line1']; ?></span> |
||
| 301 | <span class="info-item" data-key="line2"><?php echo $address['line2']; ?></span> |
||
| 302 | <span class="info-item" data-key="city"><?php echo $address['city']; ?></span> |
||
| 303 | <span class="info-item" data-key="state"><?php echo $address['state']; ?></span> |
||
| 304 | <span class="info-item" data-key="country"><?php echo $address['country']; ?></span> |
||
| 305 | <span class="info-item" data-key="zip"><?php echo $address['zip']; ?></span> |
||
| 306 | </span> |
||
| 307 | <?php } ?> |
||
| 308 | <span class="donor-address info-item edit-item"> |
||
| 309 | <input class="info-item" type="text" data-key="line1" name="customerinfo[line1]" placeholder="<?php esc_attr_e( 'Address 1', 'give' ); ?>" value="<?php echo $address['line1']; ?>" /> |
||
| 310 | <input class="info-item" type="text" data-key="line2" name="customerinfo[line2]" placeholder="<?php esc_attr_e( 'Address 2', 'give' ); ?>" value="<?php echo $address['line2']; ?>" /> |
||
| 311 | <input class="info-item" type="text" data-key="city" name="customerinfo[city]" placeholder="<?php esc_attr_e( 'City', 'give' ); ?>" value="<?php echo $address['city']; ?>" /> |
||
| 312 | <select data-key="country" name="customerinfo[country]" id="billing_country" class="billing_country give-select edit-item"> |
||
| 313 | <?php |
||
| 314 | |||
| 315 | $selected_country = $address['country']; |
||
| 316 | |||
| 317 | $countries = give_get_country_list(); |
||
| 318 | View Code Duplication | foreach ( $countries as $country_code => $country ) { |
|
| 319 | echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>'; |
||
| 320 | } |
||
| 321 | ?> |
||
| 322 | </select> |
||
| 323 | <?php |
||
| 324 | $selected_state = give_get_state(); |
||
| 325 | $states = give_get_states( $selected_country ); |
||
| 326 | |||
| 327 | $selected_state = isset( $address['state'] ) ? $address['state'] : $selected_state; |
||
| 328 | |||
| 329 | if ( ! empty( $states ) ) { |
||
| 330 | ?> |
||
| 331 | <select data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-select info-item"> |
||
| 332 | <?php |
||
| 333 | View Code Duplication | foreach ( $states as $state_code => $state ) { |
|
| 334 | echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>'; |
||
| 335 | } |
||
| 336 | ?> |
||
| 337 | </select> |
||
| 338 | <?php |
||
| 339 | } else { |
||
| 340 | ?> |
||
| 341 | <input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item" placeholder="<?php esc_attr_e( 'State / Province / County', 'give' ); ?>" /> |
||
| 342 | <?php |
||
| 343 | } |
||
| 344 | ?> |
||
| 345 | <input class="info-item" type="text" data-key="zip" name="customerinfo[zip]" placeholder="<?php esc_attr_e( 'Zip / Postal Code', 'give' ); ?>" value="<?php echo $address['zip']; ?>" /> |
||
| 346 | </span> |
||
| 347 | |||
| 348 | </div> |
||
| 349 | </td> |
||
| 350 | </tr> |
||
| 351 | <?php endif; ?> |
||
| 352 | </tbody> |
||
| 353 | </table> |
||
| 354 | |||
| 355 | </div> |
||
| 356 | |||
| 357 | </div> |
||
| 358 | |||
| 359 | <span id="donor-edit-actions" class="edit-item"> |
||
| 360 | <input type="hidden" data-key="id" name="customerinfo[id]" value="<?php echo $donor->id; ?>" /> |
||
| 361 | <?php wp_nonce_field( 'edit-donor', '_wpnonce', false, true ); ?> |
||
| 362 | <input type="hidden" name="give_action" value="edit-donor" /> |
||
| 363 | <input type="submit" id="give-edit-donor-save" class="button-secondary" value="<?php esc_attr_e( 'Update Donor', 'give' ); ?>" /> |
||
| 364 | <a id="give-edit-donor-cancel" href="" class="delete"><?php esc_html_e( 'Cancel', 'give' ); ?></a> |
||
| 365 | </span> |
||
| 366 | |||
| 367 | </form> |
||
| 368 | |||
| 369 | </div> |
||
| 370 | |||
| 371 | <?php |
||
| 372 | /** |
||
| 373 | * Fires in donor profile screen, above the stats list. |
||
| 374 | * |
||
| 375 | * @since 1.0 |
||
| 376 | * |
||
| 377 | * @param object $donor The donor object being displayed. |
||
| 378 | */ |
||
| 379 | do_action( 'give_donor_before_stats', $donor ); |
||
| 380 | ?> |
||
| 381 | |||
| 382 | <div id="donor-stats-wrapper" class="donor-section postbox clear"> |
||
| 383 | <ul> |
||
| 384 | <li> |
||
| 385 | <a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $donor->id ) ); ?>"> |
||
| 386 | <span class="dashicons dashicons-heart"></span> |
||
| 387 | <?php |
||
| 388 | // Completed Donations |
||
| 389 | $completed_donations_text = sprintf( _n( '%d Completed Donation', '%d Completed Donations', $donor->purchase_count, 'give' ), $donor->purchase_count ); |
||
| 390 | echo apply_filters( 'give_donor_completed_donations', $completed_donations_text, $donor ); |
||
| 391 | ?> |
||
| 392 | </a> |
||
| 393 | </li> |
||
| 394 | <li> |
||
| 395 | <span class="dashicons dashicons-chart-area"></span> |
||
| 396 | <?php echo give_currency_filter( give_format_amount( $donor->purchase_value, array( 'sanitize' => false ) ) ); ?> <?php esc_html_e( 'Lifetime Donations', 'give' ); ?> |
||
| 397 | </li> |
||
| 398 | <?php |
||
| 399 | /** |
||
| 400 | * Fires in donor profile screen, in the stats list. |
||
| 401 | * |
||
| 402 | * Allows you to add more list items to the stats list. |
||
| 403 | * |
||
| 404 | * @since 1.0 |
||
| 405 | * |
||
| 406 | * @param object $donor The donor object being displayed. |
||
| 407 | */ |
||
| 408 | do_action( 'give_donor_stats_list', $donor ); |
||
| 409 | ?> |
||
| 410 | </ul> |
||
| 411 | </div> |
||
| 412 | |||
| 413 | <?php |
||
| 414 | /** |
||
| 415 | * Fires in donor profile screen, above the tables wrapper. |
||
| 416 | * |
||
| 417 | * @since 1.0 |
||
| 418 | * |
||
| 419 | * @param object $donor The donor object being displayed. |
||
| 420 | */ |
||
| 421 | do_action( 'give_donor_before_tables_wrapper', $donor ); |
||
| 422 | ?> |
||
| 423 | |||
| 424 | <div id="donor-tables-wrapper" class="donor-section"> |
||
| 425 | |||
| 426 | <?php |
||
| 427 | /** |
||
| 428 | * Fires in donor profile screen, above the tables. |
||
| 429 | * |
||
| 430 | * @since 1.0 |
||
| 431 | * |
||
| 432 | * @param object $donor The donor object being displayed. |
||
| 433 | */ |
||
| 434 | do_action( 'give_donor_before_tables', $donor ); |
||
| 435 | ?> |
||
| 436 | |||
| 437 | <h3><?php _e( 'Donor Emails', 'give' ); ?></h3> |
||
| 438 | |||
| 439 | <table class="wp-list-table widefat striped emails"> |
||
| 440 | <thead> |
||
| 441 | <tr> |
||
| 442 | <th><?php _e( 'Email', 'give' ); ?></th> |
||
| 443 | <th><?php _e( 'Actions', 'give' ); ?></th> |
||
| 444 | </tr> |
||
| 445 | </thead> |
||
| 446 | |||
| 447 | <tbody> |
||
| 448 | <?php if ( ! empty( $donor->emails ) ) { ?> |
||
| 449 | |||
| 450 | <?php foreach ( $donor->emails as $key => $email ) : ?> |
||
| 451 | <tr data-key="<?php echo $key; ?>"> |
||
| 452 | <td> |
||
| 453 | <?php echo $email; ?> |
||
| 454 | <?php if ( 'primary' === $key ) : ?> |
||
| 455 | <span class="dashicons dashicons-star-filled primary-email-icon"></span> |
||
| 456 | <?php endif; ?> |
||
| 457 | </td> |
||
| 458 | <td> |
||
| 459 | <?php if ( 'primary' !== $key ) : ?> |
||
| 460 | <?php |
||
| 461 | $base_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ); |
||
| 462 | $promote_url = wp_nonce_url( add_query_arg( array( |
||
| 463 | 'email' => rawurlencode( $email ), |
||
| 464 | 'give_action' => 'set_donor_primary_email', |
||
| 465 | ), $base_url ), 'give-set-donor-primary-email' ); |
||
| 466 | $remove_url = wp_nonce_url( add_query_arg( array( |
||
| 467 | 'email' => rawurlencode( $email ), |
||
| 468 | 'give_action' => 'remove_donor_email', |
||
| 469 | ), $base_url ), 'give-remove-donor-email' ); |
||
| 470 | ?> |
||
| 471 | <a href="<?php echo $promote_url; ?>"><?php _e( 'Make Primary', 'give' ); ?></a> |
||
| 472 | | |
||
| 473 | <a href="<?php echo $remove_url; ?>" class="delete"><?php _e( 'Remove', 'give' ); ?></a> |
||
| 474 | <?php endif; ?> |
||
| 475 | </td> |
||
| 476 | </tr> |
||
| 477 | <?php endforeach; ?> |
||
| 478 | |||
| 479 | <tr class="add-donor-email-row"> |
||
| 480 | <td colspan="2" class="add-donor-email-td"> |
||
| 481 | <div class="add-donor-email-wrapper"> |
||
| 482 | <input type="hidden" name="donor-id" value="<?php echo $donor->id; ?>" /> |
||
| 483 | <?php wp_nonce_field( 'give_add_donor_email', 'add_email_nonce', false, true ); ?> |
||
| 484 | <input type="email" name="additional-email" value="" placeholder="<?php _e( 'Email Address', 'give' ); ?>" /> |
||
| 485 | <input type="checkbox" name="make-additional-primary" value="1" id="make-additional-primary" /> <label for="make-additional-primary"><?php _e( 'Make Primary', 'give' ); ?></label> |
||
| 486 | <button class="button-secondary give-add-donor-email" id="add-donor-email"><?php _e( 'Add Email', 'give' ); ?></button> |
||
| 487 | <span class="spinner"></span> |
||
| 488 | </div> |
||
| 489 | <div class="notice-wrap"></div> |
||
| 490 | </td> |
||
| 491 | </tr> |
||
| 492 | <?php } else { ?> |
||
| 493 | <tr><td colspan="2"><?php _e( 'No Emails Found', 'give' ); ?></td></tr> |
||
| 494 | <?php }// End if(). |
||
| 495 | ?> |
||
| 496 | </tbody> |
||
| 497 | </table> |
||
| 498 | |||
| 499 | <h3><?php esc_html_e( 'Recent Donations', 'give' ); ?></h3> |
||
| 500 | <?php |
||
| 501 | $payment_ids = explode( ',', $donor->payment_ids ); |
||
| 502 | $payments = give_get_payments( array( |
||
| 503 | 'post__in' => $payment_ids, |
||
| 504 | ) ); |
||
| 505 | $payments = array_slice( $payments, 0, 10 ); |
||
| 506 | ?> |
||
| 507 | <table class="wp-list-table widefat striped payments"> |
||
| 508 | <thead> |
||
| 509 | <tr> |
||
| 510 | <th scope="col"><?php esc_html_e( 'ID', 'give' ); ?></th> |
||
| 511 | <th scope="col"><?php esc_html_e( 'Amount', 'give' ); ?></th> |
||
| 512 | <th scope="col"><?php esc_html_e( 'Date', 'give' ); ?></th> |
||
| 513 | <th scope="col"><?php esc_html_e( 'Status', 'give' ); ?></th> |
||
| 514 | <th scope="col"><?php esc_html_e( 'Actions', 'give' ); ?></th> |
||
| 515 | </tr> |
||
| 516 | </thead> |
||
| 517 | <tbody> |
||
| 518 | <?php if ( ! empty( $payments ) ) { ?> |
||
| 519 | <?php foreach ( $payments as $payment ) : ?> |
||
| 520 | <tr> |
||
| 521 | <td><?php echo $payment->ID; ?></td> |
||
| 522 | <td><?php echo give_payment_amount( $payment->ID ); ?></td> |
||
| 523 | <td><?php echo date_i18n( give_date_format(), strtotime( $payment->post_date ) ); ?></td> |
||
| 524 | <td><?php echo give_get_payment_status( $payment, true ); ?></td> |
||
| 525 | <td> |
||
| 526 | <?php |
||
| 527 | printf( |
||
| 528 | '<a href="%1$s" aria-label="%2$s">%3$s</a>', |
||
| 529 | admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment->ID ), |
||
| 530 | sprintf( |
||
| 531 | /* translators: %s: Donation ID */ |
||
| 532 | esc_attr__( 'View Donation %s.', 'give' ), |
||
| 533 | $payment->ID |
||
| 534 | ), |
||
| 535 | esc_html__( 'View Donation', 'give' ) |
||
| 536 | ); |
||
| 537 | ?> |
||
| 538 | |||
| 539 | <?php |
||
| 540 | /** |
||
| 541 | * Fires in donor profile screen, in the recent donations tables action links. |
||
| 542 | * |
||
| 543 | * Allows you to add more action links for each donation, after the 'View Donation' action link. |
||
| 544 | * |
||
| 545 | * @since 1.0 |
||
| 546 | * |
||
| 547 | * @param object $donor The donor object being displayed. |
||
| 548 | * @param object $payment The payment object being displayed. |
||
| 549 | */ |
||
| 550 | do_action( 'give_donor_recent_purchases_actions', $donor, $payment ); |
||
| 551 | ?> |
||
| 552 | </td> |
||
| 553 | </tr> |
||
| 554 | <?php endforeach; ?> |
||
| 555 | <?php } else { ?> |
||
| 556 | <tr> |
||
| 557 | <td colspan="5"><?php esc_html_e( 'No donations found.', 'give' ); ?></td> |
||
| 558 | </tr> |
||
| 559 | <?php }// End if(). |
||
| 560 | ?> |
||
| 561 | </tbody> |
||
| 562 | </table> |
||
| 563 | |||
| 564 | <h3><?php esc_html_e( 'Completed Forms', 'give' ); ?></h3> |
||
| 565 | <?php |
||
| 566 | $donations = give_get_users_completed_donations( $donor->email ); |
||
| 567 | ?> |
||
| 568 | <table class="wp-list-table widefat striped donations"> |
||
| 569 | <thead> |
||
| 570 | <tr> |
||
| 571 | <th scope="col"><?php esc_html_e( 'Form', 'give' ); ?></th> |
||
| 572 | <th scope="col" width="120px"><?php esc_html_e( 'Actions', 'give' ); ?></th> |
||
| 573 | </tr> |
||
| 574 | </thead> |
||
| 575 | <tbody> |
||
| 576 | <?php if ( ! empty( $donations ) ) { ?> |
||
| 577 | <?php foreach ( $donations as $donation ) : ?> |
||
| 578 | <tr> |
||
| 579 | <td><?php echo $donation->post_title; ?></td> |
||
| 580 | <td> |
||
| 581 | <?php |
||
| 582 | printf( |
||
| 583 | '<a href="%1$s" aria-label="%2$s">%3$s</a>', |
||
| 584 | esc_url( admin_url( 'post.php?action=edit&post=' . $donation->ID ) ), |
||
| 585 | sprintf( |
||
| 586 | /* translators: %s: form name */ |
||
| 587 | esc_attr__( 'View Form %s.', 'give' ), |
||
| 588 | $donation->post_title |
||
| 589 | ), |
||
| 590 | esc_html__( 'View Form', 'give' ) |
||
| 591 | ); |
||
| 592 | ?> |
||
| 593 | </td> |
||
| 594 | </tr> |
||
| 595 | <?php endforeach; ?> |
||
| 596 | <?php } else { ?> |
||
| 597 | <tr> |
||
| 598 | <td colspan="2"><?php esc_html_e( 'No completed donations found.', 'give' ); ?></td> |
||
| 599 | </tr> |
||
| 600 | <?php } ?> |
||
| 601 | </tbody> |
||
| 602 | </table> |
||
| 603 | |||
| 604 | <?php |
||
| 605 | /** |
||
| 606 | * Fires in donor profile screen, below the tables. |
||
| 607 | * |
||
| 608 | * @since 1.0 |
||
| 609 | * |
||
| 610 | * @param object $donor The donor object being displayed. |
||
| 611 | */ |
||
| 612 | do_action( 'give_donor_after_tables', $donor ); |
||
| 613 | ?> |
||
| 614 | |||
| 615 | </div> |
||
| 616 | |||
| 617 | <?php |
||
| 618 | /** |
||
| 619 | * Fires in donor profile screen, below the donor card. |
||
| 620 | * |
||
| 621 | * @since 1.0 |
||
| 622 | * |
||
| 623 | * @param object $donor The donor object being displayed. |
||
| 624 | */ |
||
| 625 | do_action( 'give_donor_card_bottom', $donor ); |
||
| 626 | |||
| 627 | } |
||
| 628 | |||
| 791 |