Skip to content

Commit

Permalink
Merge pull request #3988 from impress-org/issue/3971
Browse files Browse the repository at this point in the history
fix: ensure donor mailing addresses match when exporting to csv #3971
  • Loading branch information
Devin Walker committed Feb 6, 2019
2 parents 3cbc500 + a509d0b commit e256397
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions includes/donors/backward-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function __give_v20_bc_user_address( $meta_value, $user_id, $meta_key, $single )
give_has_upgrade_completed( 'v20_upgrades_user_address' ) &&
'_give_user_address' === $meta_key
) {
$meta_value = give_get_donor_address( $user_id );
$meta_value = give_get_donor_address( $user_id, array( 'by_user_id' => true ) );

if ( $single ) {
$meta_value = array( $meta_value );
Expand All @@ -26,4 +26,4 @@ function __give_v20_bc_user_address( $meta_value, $user_id, $meta_key, $single )
return $meta_value;
}

add_filter( 'get_user_metadata', '__give_v20_bc_user_address', 10, 4 );
add_filter( 'get_user_metadata', '__give_v20_bc_user_address', 10, 4 );
6 changes: 0 additions & 6 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,12 +1053,6 @@ function give_default_cc_address_fields( $form_id ) {
// Get user info.
$give_user_info = _give_get_prefill_form_field_values( $form_id );

$logged_in = is_user_logged_in();

if ( $logged_in ) {
$user_address = give_get_donor_address( get_current_user_id() );
}

ob_start();
?>
<fieldset id="give_cc_address" class="cc-address">
Expand Down
31 changes: 17 additions & 14 deletions includes/user-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,20 @@ function give_count_total_donors() {
* @since 1.0
*
* @param int/null $donor_id Donor ID.
* @param array $args donor args.
* @param array $args {
*
* @type bool $by_user_id Flag to validate find donor by donor ID or user ID
* @type string $address_type Optional. Which type of donor address this function will return.
* }
*
* @return array The donor's address, if any
*/
function give_get_donor_address( $donor_id = null, $args = array() ) {
if ( empty( $donor_id ) ) {
$donor_id = get_current_user_id();
}

$address = array();
$args = wp_parse_args(
$args,
array(
'address_type' => 'billing',
)
$default_args = array(
'by_user_id' => false,
'address_type' => 'billing',
);

$default_address = array(
'line1' => '',
'line2' => '',
Expand All @@ -491,9 +489,14 @@ function give_get_donor_address( $donor_id = null, $args = array() ) {
'zip' => '',
);

$address = array();
$args = wp_parse_args( $args, $default_args );

// Backward compatibility for user id param.
$by_user_id = get_user_by( 'id', $donor_id ) ? true : false;
// Set user id if donor is empty.
if ( empty( $donor_id ) ) {
$donor_id = get_current_user_id();
$args['by_user_id'] = true;
}

// Backward compatibility.
if ( ! give_has_upgrade_completed( 'v20_upgrades_user_address' ) && $by_user_id ) {
Expand All @@ -503,7 +506,7 @@ function give_get_donor_address( $donor_id = null, $args = array() ) {
);
}

$donor = new Give_Donor( $donor_id, $by_user_id );
$donor = new Give_Donor( $donor_id, (bool) $args['by_user_id'] );

if (
! $donor->id ||
Expand Down

0 comments on commit e256397

Please sign in to comment.