Skip to content

Commit

Permalink
Merge pull request #3269 from mehul0810/issue/2347
Browse files Browse the repository at this point in the history
refactor(donor): create singular method to delete donor #2347
  • Loading branch information
Devin Walker committed Jun 7, 2018
2 parents dbf25bc + 6a9be31 commit e97b77a
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 177 deletions.
8 changes: 4 additions & 4 deletions assets/src/js/admin/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2084,19 +2084,19 @@ var give_setting_edit = false;
});

// CheckBox click event to confirm deletion of donor.
$body.on('click', '#give-delete-donor-confirm', function () {
$body.on('click', '#give-bulk-delete .give-donor-delete-confirm', function () {
if ($(this).is(':checked')) {
$('#give-bulk-delete-button').removeAttr('disabled');
} else {
$('#give-bulk-delete-button').attr('disabled', true);
$('#give-delete-donor-records').removeAttr('checked');
$('#give-bulk-delete .give-donor-delete-records').removeAttr('checked');
}
});

// CheckBox click event to delete records with donor.
$body.on('click', '#give-delete-donor-records', function () {
$body.on('click', '#give-bulk-delete .give-donor-delete-records', function () {
if ($(this).is(':checked')) {
$('#give-delete-donor-confirm').attr('checked', 'checked');
$('#give-bulk-delete .give-donor-delete-confirm').attr('checked', 'checked');
$('#give-bulk-delete-button').removeAttr('disabled');
}
});
Expand Down
18 changes: 11 additions & 7 deletions includes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
*/
function give_get_actions() {

$_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null;
$get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok.

// Add backward compatibility to give-action param ( $_GET )
$_get_action = ! empty( $get_data['give_action'] ) ? $get_data['give_action'] : null;

// Add backward compatibility to give-action param ( $_GET ).
if ( empty( $_get_action ) ) {
$_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null;
$_get_action = ! empty( $get_data['give-action'] ) ? $get_data['give-action'] : null;
}

if ( isset( $_get_action ) ) {
Expand All @@ -40,7 +42,7 @@ function give_get_actions() {
*
* @param array $_GET Array of HTTP GET variables.
*/
do_action( "give_{$_get_action}", $_GET );
do_action( "give_{$_get_action}", $get_data );
}

}
Expand All @@ -58,11 +60,13 @@ function give_get_actions() {
*/
function give_post_actions() {

$_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null;
$post_data = give_clean( $_POST ); // WPCS: input var ok, sanitization ok, CSRF ok.

$_post_action = ! empty( $post_data['give_action'] ) ? $post_data['give_action'] : null;

// Add backward compatibility to give-action param ( $_POST ).
if ( empty( $_post_action ) ) {
$_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null;
$_post_action = ! empty( $post_data['give-action'] ) ? $post_data['give-action'] : null;
}

if ( isset( $_post_action ) ) {
Expand All @@ -73,7 +77,7 @@ function give_post_actions() {
*
* @param array $_POST Array of HTTP POST variables.
*/
do_action( "give_{$_post_action}", $_POST );
do_action( "give_{$_post_action}", $post_data );
}

}
Expand Down
28 changes: 17 additions & 11 deletions includes/admin/donors/class-donor-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ public function display() {
$this->display_tablenav( 'top' );

$this->screen->render_screen_reader_content( 'heading_list' );

$get_data = give_clean( $_GET ); // WPCS: input var ok, sanitization ok, CSRF ok.

$search_keyword = ! empty( $get_data['s'] ) ? $get_data['s'] : '';
$order = ! empty( $get_data['order'] ) ? $get_data['order'] : 'DESC';
$order_by = ! empty( $get_data['orderby'] ) ? $get_data['orderby'] : 'ID';
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>
Expand All @@ -445,7 +451,7 @@ public function display() {
<td colspan="6" class="colspanchange">

<fieldset class="inline-edit-col-left">
<legend class="inline-edit-legend"><?php _e( 'BULK DELETE', 'give' ); ?></legend>
<legend class="inline-edit-legend"><?php esc_attr_e( 'BULK DELETE', 'give' ); ?></legend>
<div class="inline-edit-col">
<div id="bulk-titles">
<div id="give-bulk-donors" class="give-bulk-donors">
Expand All @@ -457,23 +463,23 @@ public function display() {
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label>
<input id="give-delete-donor-confirm" type="checkbox" name="give-delete-donor-confirm"/>
<?php _e( 'Are you sure you want to delete the selected donor(s)?', 'give' ); ?>
<input class="give-donor-delete-confirm" type="checkbox" name="give-donor-delete-confirm"/>
<?php esc_attr_e( 'Are you sure you want to delete the selected donor(s)?', 'give' ); ?>
</label>
<label>
<input id="give-delete-donor-records" type="checkbox" name="give-delete-donor-records"/>
<?php _e( 'Delete all associated donations and records?', 'give' ); ?>
<input class="give-donor-delete-records" type="checkbox" name="give-donor-delete-records"/>
<?php esc_attr_e( 'Delete all associated donations and records?', 'give' ); ?>
</label>
</div>
</fieldset>

<p class="submit inline-edit-save">
<input type="hidden" name="give_action" value="delete_donor"/>
<input type="hidden" name="s" value="<?php echo ( ! empty( $_GET['s'] ) ) ? $_GET['s'] : ''; ?>"/>
<input type="hidden" name="orderby" value="<?php echo ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id'; ?>"/>
<input type="hidden" name="order" value="<?php echo ( ! empty( $_GET['order'] ) ) ? $_GET['order'] : 'desc'; ?>"/>
<button type="button" id="give-bulk-delete-cancel" class="button cancel alignleft"><?php _e( 'Cancel', 'give' ); ?></button>
<input type="submit" id="give-bulk-delete-button" disabled class="button button-primary alignright" value="<?php _e( 'Delete', 'give' ); ?>">
<input type="hidden" name="give_action" value="delete_bulk_donor"/>
<input type="hidden" name="s" value="<?php echo esc_html( $search_keyword ); ?>"/>
<input type="hidden" name="orderby" value="<?php echo esc_html( $order_by ); ?>"/>
<input type="hidden" name="order" value="<?php echo esc_html( $order ); ?>"/>
<button type="button" id="give-bulk-delete-cancel" class="button cancel alignleft"><?php esc_attr_e( 'Cancel', 'give' ); ?></button>
<input type="submit" id="give-bulk-delete-button" disabled class="button button-primary alignright" value="<?php esc_attr_e( 'Delete', 'give' ); ?>">
<br class="clear">
</p>
</td>
Expand Down
Loading

0 comments on commit e97b77a

Please sign in to comment.