Skip to content

Commit

Permalink
Merge pull request #3784 from impress-org/issue/3781
Browse files Browse the repository at this point in the history
fix: remove `Anonymous Donor` field from donor details #3781
  • Loading branch information
Devin Walker committed Oct 19, 2018
2 parents 8f10420 + c85192e commit f488f74
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 268 deletions.
101 changes: 0 additions & 101 deletions includes/admin/donors/donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,45 +469,8 @@ function give_donor_view( $donor ) {
</span>
</td>
</tr>

<?php $anonymous_donor = absint( $donor->get_meta( '_give_anonymous_donor', true ) ); ?>
<tr class="alternate">
<th scope="col">
<label for="tablecell"><?php _e( 'Anonymous Donor:', 'give' ); ?></label>
</th>
<td>
<span class="donor-anonymous-donor info-item edit-item">
<ul class="give-radio-inline">
<li>
<label>
<input
name="give_anonymous_donor"
value="1"
type="radio"
<?php checked( 1, $anonymous_donor ) ?>
><?php _e( 'Yes', 'give' ); ?>
</label>
</li>
<li>
<label>
<input
name="give_anonymous_donor"
value="0"
type="radio"
<?php checked( 0, $anonymous_donor ) ?>
><?php _e( 'No', 'give' ); ?>
</label>
</li>
</ul>
</span>
<span class="donor-anonymous-donor info-item editable">
<?php echo( $anonymous_donor ? __( 'Yes', 'give' ) : __( 'No', 'give' ) ); ?>
</span>
</td>
</tr>
</tbody>
</table>

</div>

</div>
Expand Down Expand Up @@ -954,70 +917,6 @@ class="button js-cancel"><?php _e( 'Cancel', 'give' ); ?></button>
<?php } ?>
</tbody>
</table>

<h3><?php _e( 'Comments', 'give' ); ?></h3>
<?php
// @todo load comment by ajax to improve performance.
$donations = give_get_users_donations( $donor->email );
?>
<table class="wp-list-table widefat striped comments">
<thead>
<tr>
<th scope="col"><?php _e( 'Donation', 'give' ); ?></th>
<th scope="col"><?php _e( 'Anonymous', 'give' ); ?></th>
<th scope="col" colspan="3"><?php _e( 'Comment', 'give' ); ?></th>
</tr>
</thead>
<tbody>
<?php if ( ! empty( $donations ) && $donor->get_meta( '_give_has_comment', true ) ) : ?>
<?php foreach ( $donations as $donation ) : ?>
<?php
$comment = give_get_donor_donation_comment( $donation->ID, give_get_payment_donor_id( $donation->ID ) );

if ( ! ( $comment instanceof WP_Comment || $comment instanceof stdClass ) ) {
continue;
}
?>
<tr>
<td>
<?php
$donation_number = Give()->seq_donation_number->get_serial_code( $donation );
echo $donation_number;
?>
</td>
<td>
<?php
echo absint( give_get_payment_meta( $donation->ID, '_give_anonymous_donation' ) )
? __( 'Yes', 'give' )
: __( 'No', 'give' );
?>
</td>
<td>
<?php
echo apply_filters( 'the_content', $comment->comment_content );

echo sprintf(
'<a href="%1$s" aria-label="%2$s" target="_blank">%3$s</a>',
admin_url( "edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id={$donation->ID}#give-payment-donor-comment" ),
sprintf(
/* translators: %s: Comment ID */
esc_attr__( 'Edit Comment %s.', 'give' ),
$comment->comment_ID
),
__( 'Edit Comment', 'give' )
);
?>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="5"><?php _e( 'No comment found.', 'give' ); ?></td>
</tr>
<?php endif ?>
</tbody>
</table>

<?php
/**
* Fires in donor profile screen, below the tables.
Expand Down
68 changes: 0 additions & 68 deletions includes/admin/payments/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,59 +311,6 @@ function give_update_payment_details( $data ) {

if ( $has_anonymous_setting_field ) {
give_update_meta( $payment->ID, '_give_anonymous_donation', $payment->anonymous );

// Set donor as anonymous only if donor does not have any non anonymous donation.
$donations = Give()->donors->get_column_by( 'payment_ids', 'id', $payment->donor_id );
$donations = ! empty( $donations ) ? explode( ',', $donations ) : array();
$update_anonymous_donor_meta = false;

if( ! empty( $donations ) ) {
$non_anonymous_donations = new WP_Query( array(
'post_type' => 'give_payment',
'post_status' => 'publish',
'post__in' => $donations,
'fields' => 'ids',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_give_anonymous_donation',
'value' => 0,
),
array(
'key' => '_give_payment_form_id',
'value' => $payment->form_id,
),
),
) );

$update_anonymous_donor_meta = ! ( 0 < $non_anonymous_donations->found_posts );

if(
0 === absint( $non_anonymous_donations->found_posts )
&& $payment->anonymous
) {
$update_anonymous_donor_meta = true;
} elseif (
1 === absint( $non_anonymous_donations->found_posts )
&& ! $payment->anonymous
) {
$update_anonymous_donor_meta = true;
}
}

if ( $update_anonymous_donor_meta ) {
Give()->donor_meta->update_meta( $payment->donor_id, "_give_anonymous_donor_form_{$payment->form_id}", $payment->anonymous );
}

// Update comment meta if admin is not updating comment.
if( $comment_id ) {
if( ! give_has_upgrade_completed('v230_move_donation_note' ) ) {
// Backward compatibility.
update_comment_meta( $comment_id, '_give_anonymous_donation', $payment->anonymous );
} else{
Give()->comment->db_meta->update_meta( $comment_id, '_give_anonymous_donation', $payment->anonymous );
}
}
}

// Update comment.
Expand Down Expand Up @@ -392,21 +339,6 @@ function give_update_payment_details( $data ) {
$comment_args
);
}

if( $comment_id ) {
$donor_has_comment = empty( $data['give_comment'] )
? ( $latest_comment = give_get_donor_latest_comment( $payment->donor_id ) && empty( $latest_comment ) ? '0' : '1' )
: '1';

if ( ! give_has_upgrade_completed( 'v230_move_donation_note' ) ) {
// Backward compatibility.
update_comment_meta( $comment_id, '_give_anonymous_donation', $payment->anonymous );
} else {
Give()->comment->db_meta->update_meta( $comment_id, '_give_anonymous_donation', $payment->anonymous );
}

Give()->donor_meta->update_meta( $payment->donor_id, '_give_has_comment', $donor_has_comment );
}
}

/**
Expand Down
66 changes: 66 additions & 0 deletions includes/admin/upgrades/upgrade-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,34 @@ function give_show_upgrade_notices( $give_updates ) {
'callback' => 'give_v230_move_donation_note_callback',
)
);

// v2.3.0 remove donor wall related donor meta data.
$give_updates->register(
array(
'id' => 'v230_delete_donor_wall_related_donor_data',
'version' => '2.3.0',
'depend' => array(
'v224_update_donor_meta',
'v224_update_donor_meta_forms_id',
'v230_move_donor_note',
'v230_move_donation_note'
),
'callback' => 'give_v230_delete_dw_related_donor_data_callback',
)
);

// v2.3.0 remove donor wall related comment meta data.
$give_updates->register(
array(
'id' => 'v230_delete_donor_wall_related_comment_data',
'version' => '2.3.0',
'callback' => 'give_v230_delete_dw_related_comment_data_callback',
'depend' => array(
'v230_move_donor_note',
'v230_move_donation_note'
),
)
);
}

add_action( 'give_register_updates', 'give_show_upgrade_notices' );
Expand Down Expand Up @@ -3189,3 +3217,41 @@ function give_v230_move_donation_note_callback() {
give_set_upgrade_complete( 'v230_move_donation_note' );
}
}

/**
* Delete donor wall related donor meta data
*
* @since 2.3.0
*
*/
function give_v230_delete_dw_related_donor_data_callback(){
global $wpdb;

$give_updates = Give_Updates::get_instance();

$wpdb->query( "DELETE FROM {$wpdb->donormeta} WHERE meta_key LIKE '%_give_anonymous_donor%' OR meta_key='_give_has_comment';" );

$give_updates->percentage = 100;

// The Update Ran.
give_set_upgrade_complete( 'v230_delete_donor_wall_related_donor_data' );
}

/**
* Delete donor wall related comment meta data
*
* @since 2.3.0
*
*/
function give_v230_delete_dw_related_comment_data_callback(){
global $wpdb;

$give_updates = Give_Updates::get_instance();

$wpdb->query( "DELETE FROM {$wpdb->give_commentmeta} WHERE meta_key='_give_anonymous_donation';" );

$give_updates->percentage = 100;

// The Update Ran.
give_set_upgrade_complete( 'v230_delete_donor_wall_related_comment_data' );
}
5 changes: 0 additions & 5 deletions includes/class-give-donor.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,6 @@ public function create( $data = array() ) {
$this->setup_donor( $donor );

$created = $this->id;

// Set donor as non anonymous by default
if( $created ) {
Give()->donor_meta->update_meta( $this->id, '_give_anonymous_donor', 0 );
}
}

/**
Expand Down
85 changes: 85 additions & 0 deletions includes/deprecated/deprecated-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ function give_get_donor_donation_comments( $donor_id, $comment_args = array(), $
* Converts a PHP date format for use in JavaScript.
*
* @since 2.2.0
* @deprecated 2.3.0
*
* @param string $php_format The PHP date format.
*
Expand Down Expand Up @@ -926,6 +927,7 @@ function give_convert_php_date_format_to_js( $php_format ) {
* Get localized date format for use in JavaScript.
*
* @since 2.2.0
* @deprecated 2.3.0
*
* @return string.
*/
Expand All @@ -936,3 +938,86 @@ function give_get_localized_date_format_to_js() {

return give_convert_php_date_format_to_js( get_option( 'date_format' ) );
}

/**
* Get donor latest comment
*
* @since 2.2.0
* @deprecated 2.3.0
*
* @param int $donor_id
* @param int $form_id
*
* @return WP_Comment/stdClass/array
*/
function give_get_donor_latest_comment( $donor_id, $form_id = 0 ) {
global $wpdb;

_give_deprecated_function(
__FUNCTION__,
'2.3.0',
'Give()->comment->db'
);

// Backward compatibility.
if ( ! give_has_upgrade_completed( 'v230_move_donor_note' ) ) {

$comment_args = array(
'post_id' => 0,
'orderby' => 'comment_ID',
'order' => 'DESC',
'number' => 1,
'meta_query' => array(
'related' => 'AND',
array(
'key' => '_give_donor_id',
'value' => $donor_id
),
array(
'key' => '_give_anonymous_donation',
'value' => 0
)
)
);

// Get donor donation comment for specific form.
if ( $form_id ) {
$comment_args['parent'] = $form_id;
}

$comment = current( give_get_donor_donation_comments( $donor_id, $comment_args ) );

return $comment;
}

$comment_args = array(
'orderby' => 'comment_ID',
'order' => 'DESC',
'number' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_give_anonymous_donation',
'value' => 0,
),
array(
'key' => '_give_donor_id',
'value' => $donor_id,
),
),
);

// Get donor donation comment for specific form.
if ( $form_id ) {
$comment_args['meta_query'][] = array(
'key' => '_give_form_id',
'value' => $form_id,
);
}

$sql = Give()->comment->db->get_sql( $comment_args );

$comment = current( $wpdb->get_results( $sql ) );

return $comment;
}

0 comments on commit f488f74

Please sign in to comment.