Commit 18dc04d8 authored by Varun Sridharan's avatar Varun Sridharan

#58 Fixed and minor changes done

* Fixed Empty Trash Issue
* Fixed  #58
* Added  Option To Clear Donation Log In system tools menu
parent f3266f8b
...@@ -22,7 +22,10 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -22,7 +22,10 @@ class WooCommerce_Quick_Donation_Admin_Function {
add_action( 'parse_query', array( $this, 'hide_donation_order_woocommerce_order' ) ); add_action( 'parse_query', array( $this, 'hide_donation_order_woocommerce_order' ) );
add_filter( 'wc_order_types',array($this,'add_wc_order_types'),1,2); add_filter( 'wc_order_types',array($this,'add_wc_order_types'),1,2);
add_action( 'delete_post', array($this,'delete_donation')); add_action( 'delete_post', array($this,'delete_donation'));
add_action( 'wp_ajax_CreateDonationProduct', array($this,'create_donation_product') ); add_action( 'wp_ajax_CreateDonationProduct', array($this,'create_donation_product') );
add_action( 'wp_ajax_ClearDonationLog', array($this,'clear_wc_qd_logs') );
} }
...@@ -123,7 +126,7 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -123,7 +126,7 @@ class WooCommerce_Quick_Donation_Admin_Function {
public function create_donation_product(){ public function create_donation_product(){
if(! isset($_REQUEST['_wpnonce'])) { if(! isset($_REQUEST['_wpnonce'])) {
echo '<span class="wc_qd_error">Invalid Nonce. kindly try again</span>'; echo '<span class="wc_qd_error">'.__('Invalid Nonce. kindly try again',WC_QD_TXT).'</span>';
exit; exit;
} }
...@@ -134,14 +137,14 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -134,14 +137,14 @@ class WooCommerce_Quick_Donation_Admin_Function {
$donation_exist = $install::check_donation_exists(); $donation_exist = $install::check_donation_exists();
if(isset($_REQUEST['force'])){ if(isset($_REQUEST['force'])){
$post_id = $install::$callBack_function(); $post_id = $install->$callBack_function();
update_option(WC_QD_DB.'product_id',$post_id); update_option(WC_QD_DB.'product_id',$post_id);
echo '<span class="wcqdsuccess">'.__('Donation Product Created',WC_QD_TXT).'</span>'; echo '<span class="wcqdsuccess">'.__('Donation Product Created',WC_QD_TXT).'</span>';
exit; exit;
} }
if(! $donation_exist){ if(! $donation_exist){
$post_id = $install::$callBack_function(); $post_id = $install->$callBack_function();
update_option(WC_QD_DB.'product_id',$post_id); update_option(WC_QD_DB.'product_id',$post_id);
echo '<span class="wcqdsuccess">'.__('Donation Product Created',WC_QD_TXT).'</span>'; echo '<span class="wcqdsuccess">'.__('Donation Product Created',WC_QD_TXT).'</span>';
} else { } else {
...@@ -154,4 +157,18 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -154,4 +157,18 @@ class WooCommerce_Quick_Donation_Admin_Function {
exit; exit;
} }
public function clear_wc_qd_logs(){
if(! isset($_REQUEST['_wpnonce'])) {
echo '<span class="wc_qd_error">'.__('Invalid Nonce. kindly try again',WC_QD_TXT).'</span>';
exit;
}
if(wp_verify_nonce($_REQUEST['_wpnonce'], 'ClearDonationLog')){
$delete = WC_QD()->db()->delete_donation_logs();
echo '<span class="wcqdsuccess">'.sprintf(__('%s Records Deleted',WC_QD_TXT),$delete).'</span>';
}
exit;
}
} }
\ No newline at end of file
...@@ -177,7 +177,7 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -177,7 +177,7 @@ class WooCommerce_Quick_Donation_Admin {
define('WC_QD_QRY_OVERRIDE',true); define('WC_QD_QRY_OVERRIDE',true);
$order_ids = WC_QD()->db()->get_donation_order_ids(); $order_ids = WC_QD()->db()->get_donation_order_ids();
$order_ids = WC_QD()->db()->extract_donation_id($order_ids); $order_ids = WC_QD()->db()->extract_donation_id($order_ids);
if(empty($order_ids)) { $order_ids[] = 0;}
$args = array('posts_per_page' => '0', $args = array('posts_per_page' => '0',
'post_type' => 'shop_order', 'post_type' => 'shop_order',
'post_status' => array_keys(wc_get_order_statuses()), 'post_status' => array_keys(wc_get_order_statuses()),
...@@ -197,9 +197,9 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -197,9 +197,9 @@ class WooCommerce_Quick_Donation_Admin {
$args['meta_query'][]['value'] = $_GET['dproj']; $args['meta_query'][]['value'] = $_GET['dproj'];
$args['meta_query'][]['compare'] = '='; $args['meta_query'][]['compare'] = '=';
} }
if(isset($_GET['post_status'])){ $args['post_status'] = $_GET['post_status'];} if(isset($_GET['post_status'])){ $args['post_status'] = $_GET['post_status'];}
$wp_query = new WP_Query($args);
$wp_query = new WP_Query($args);
tt_render_list_page($wp_query); tt_render_list_page($wp_query);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
$links = ''; $links = '';
foreach($pages as $pageid => $page){ foreach($pages as $pageid => $page){
$class = 'nav-tab '; $class = 'nav-tab ';
$url = menu_page_url($pageid, false ); $url = menu_page_url($pageid, false );
if($active == $pageid){$class .= ' nav-tab-active'; } if($active == $pageid){$class .= ' nav-tab-active'; }
......
...@@ -19,11 +19,24 @@ if(! WC_QD()->donation_product_exist_public()){ ...@@ -19,11 +19,24 @@ if(! WC_QD()->donation_product_exist_public()){
<td><?php _e('Reinstall Donation Product',WC_QD_TXT); ?> </td> <td><?php _e('Reinstall Donation Product',WC_QD_TXT); ?> </td>
<td> <td>
<p> <p>
<button type="button" class="wcqdAjaxCall button clear_transients" href="<?php echo wp_nonce_url(admin_url('admin-ajax.php?action=CreateDonationProduct'),'CreateDonationProduct'); ?>"><?php _e('Create Donation Product',WC_QD_TXT); ?></button> <button type="button" class="wcqdAjaxCall button clear_transients"
href="<?php echo wp_nonce_url(admin_url('admin-ajax.php?action=CreateDonationProduct'),'CreateDonationProduct'); ?>"><?php _e('Create Donation Product',WC_QD_TXT); ?></button>
<span class="description"><?php echo $product_exist; ?></span> <span class="description"><?php echo $product_exist; ?></span>
</p> </p>
</td> </td>
</tr> </tr>
<tr class="clear_transients">
<td><?php _e('Clear Donation Log',WC_QD_TXT); ?> </td>
<td>
<p>
<button type="button" class="ConfirmAction wcqdAjaxCall button"
data-alert-text="Are You Sure Want To Clear All Logs"
href="<?php echo wp_nonce_url(admin_url('admin-ajax.php?action=ClearDonationLog'),'ClearDonationLog'); ?>"><?php _e('Clear Log',WC_QD_TXT); ?></button>
<span class="description"><?php _e('Clear Logs From WC Donation Table. which resets user donation count & other logs'); ?></span>
</p>
</td>
</tr>
</tbody> </tbody>
......
...@@ -116,121 +116,140 @@ class WC_Quick_Donation_Listing_Table extends WP_List_Table { ...@@ -116,121 +116,140 @@ class WC_Quick_Donation_Listing_Table extends WP_List_Table {
} }
public function process_bulk_action() { public function process_bulk_action() {
global $pagenow; global $pagenow, $wpdb;
if(!isset($_REQUEST['_wpnonce'])){return;} if(!isset($_REQUEST['_wpnonce'])){return;}
$nonce = esc_attr( $_REQUEST['_wpnonce'] ); $nonce = esc_attr( $_REQUEST['_wpnonce'] );
if ( ! wp_verify_nonce( $nonce, 'bulk-donations') ) { if ( ! wp_verify_nonce( $nonce, 'bulk-donations') ) {
wp_die( __('Invalid Nonce for deleting WC Donation Orders', WC_QD_TXT)); wp_die( __('Invalid Nonce for deleting WC Donation Orders', WC_QD_TXT));
} }
//check_admin_referer('bulk-posts'); $doaction = $this->current_action();
$pagenum = $this->get_pagenum(); if($doaction){
$sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer() ); $pagenum = $this->get_pagenum();
if ( ! $sendback ) $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer() );
$sendback = admin_url( $parent_file ); if ( ! $sendback )
$sendback = add_query_arg( 'paged', $pagenum, $sendback ); $sendback = admin_url( $parent_file );
if ( strpos($sendback, 'post.php') !== false ) $sendback = add_query_arg( 'paged', $pagenum, $sendback );
$sendback = admin_url($post_new_file); if ( strpos($sendback, 'post.php') !== false )
$sendback = admin_url($post_new_file);
$post_ids = array_map('intval', $_REQUEST['post']);
$total_post = count($post_ids); if(isset($_REQUEST['post'])){
$ids = implode(', ',$post_ids); $post_ids = array_map('intval', $_REQUEST['post']);
$doaction = $this->current_action();
$Notice_Txt = '';
switch ( $doaction ) {
case 'trash':
$trashed = $locked = 0;
foreach( (array) $post_ids as $post_id ) {
if ( !current_user_can( 'delete_post', $post_id) )
wp_die( __('You are not allowed to move this item to the Trash.'));
if ( wp_check_post_lock( $post_id ) ) {
$locked++;
continue;
}
if ( !wp_trash_post($post_id) )
wp_die( __('Error in moving to Trash.') );
$trashed++;
$Notice_Txt = ' Trashed ';
}
$sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback );
wc_qd_notice(
sprintf(
_n( '%s Donation Order Trashed ( %s )',
'%s Donation Orders Trashed ( %s )' , $total_post, $ids, WC_QD_TXT ),
$total_post,$ids
)
);
break; }
case 'untrash': var_dump($this->screen);
$untrashed = 0;
foreach( (array) $post_ids as $post_id ) { if ( 'delete_all' == $doaction ) {
if ( !current_user_can( 'delete_post', $post_id) ) // Prepare for deletion of all posts with a specified post status (i.e. Empty trash).
wp_die( __('You are not allowed to restore this item from the Trash.') ); $post_status = preg_replace('/[^a-z0-9_-]+/i', '', 'trash');
// Validate the post status exists.
if ( !wp_untrash_post($post_id) ) if ( get_post_status_object( $post_status ) ) {
wp_die( __('Error in restoring from Trash.') ); $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", 'shop_order', $post_status ) );
}
$untrashed++; $doaction = 'delete';
} }
$sendback = add_query_arg('untrashed', $untrashed, $sendback);
$total_post = count($post_ids);
wc_qd_notice( $ids = implode(', ',$post_ids);
sprintf(
_n( '%s Donation Order restored from trash ( %s )', $Notice_Txt = '';
'%s Donation Orders restored from trash ( %s )' , $total_post, $ids, WC_QD_TXT ), switch ( $doaction ) {
$total_post, case 'trash':
$ids $trashed = $locked = 0;
)
); foreach( (array) $post_ids as $post_id ) {
if ( !current_user_can( 'delete_post', $post_id) )
break; wp_die( __('You are not allowed to move this item to the Trash.'));
case 'delete':
$deleted = 0; if ( wp_check_post_lock( $post_id ) ) {
foreach( (array) $post_ids as $post_id ) { $locked++;
$post_del = get_post($post_id); continue;
}
if ( !current_user_can( 'delete_post', $post_id ) )
wp_die( __('You are not allowed to delete this item.') ); if ( !wp_trash_post($post_id) )
wp_die( __('Error in moving to Trash.') );
if ( $post_del->post_type == 'attachment' ) {
if ( ! wp_delete_attachment($post_id) ) $trashed++;
wp_die( __('Error in deleting.') ); $Notice_Txt = ' Trashed ';
} else { }
if ( !wp_delete_post($post_id) )
wp_die( __('Error in deleting.') ); $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback );
}
$deleted++; wc_qd_notice(
} sprintf(
$sendback = add_query_arg('deleted', $deleted, $sendback); _n( '%s Donation Order Trashed ( %s )',
wc_qd_notice( '%s Donation Orders Trashed ( %s )' , $total_post, $ids, WC_QD_TXT ),
sprintf( $total_post,$ids
_n( '%s Donation Order permanently deleted ( %s )', )
'%s Donation Orders permanently deleted ( %s )' , $total_post, $ids, WC_QD_TXT ), );
$total_post,
$ids break;
) case 'untrash':
); $untrashed = 0;
break; foreach( (array) $post_ids as $post_id ) {
case 'edit': if ( !current_user_can( 'delete_post', $post_id) )
if ( isset($_REQUEST['bulk_edit']) ) { wp_die( __('You are not allowed to restore this item from the Trash.') );
$done = bulk_edit_posts($_REQUEST);
if ( !wp_untrash_post($post_id) )
if ( is_array($done) ) { wp_die( __('Error in restoring from Trash.') );
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] ); $untrashed++;
$done['locked'] = count( $done['locked'] ); }
$sendback = add_query_arg( $done, $sendback ); $sendback = add_query_arg('untrashed', $untrashed, $sendback);
}
} wc_qd_notice(
break; sprintf(
} _n( '%s Donation Order restored from trash ( %s )',
'%s Donation Orders restored from trash ( %s )' , $total_post, $ids, WC_QD_TXT ),
$total_post,
$ids
)
);
break;
case 'delete':
$deleted = 0;
foreach( (array) $post_ids as $post_id ) {
$post_del = get_post($post_id);
if ( !current_user_can( 'delete_post', $post_id ) )
wp_die( __('You are not allowed to delete this item.') );
if ( $post_del->post_type == 'attachment' ) {
if ( ! wp_delete_attachment($post_id) )
wp_die( __('Error in deleting.') );
} else {
if ( !wp_delete_post($post_id) )
wp_die( __('Error in deleting.') );
}
$deleted++;
}
$sendback = add_query_arg('deleted', $deleted, $sendback);
wc_qd_notice(
sprintf(
_n( '%s Donation Order permanently deleted ( %s )',
'%s Donation Orders permanently deleted ( %s )' , $total_post, $ids, WC_QD_TXT ),
$total_post,
$ids
)
);
break;
case 'edit':
if ( isset($_REQUEST['bulk_edit']) ) {
$done = bulk_edit_posts($_REQUEST);
if ( is_array($done) ) {
$done['updated'] = count( $done['updated'] );
$done['skipped'] = count( $done['skipped'] );
$done['locked'] = count( $done['locked'] );
$sendback = add_query_arg( $done, $sendback );
}
}
break;
}
}
$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback ); $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
wp_redirect($sendback); wp_redirect($sendback);
...@@ -334,8 +353,7 @@ class WC_Quick_Donation_Listing_Table extends WP_List_Table { ...@@ -334,8 +353,7 @@ class WC_Quick_Donation_Listing_Table extends WP_List_Table {
foreach ( $results as $row ) {$counts[ $row['post_status'] ] = $row['num_posts'];} foreach ( $results as $row ) {$counts[ $row['post_status'] ] = $row['num_posts'];}
$counts = (object) $counts; $counts = (object) $counts;
wp_cache_set( $cache_key.'_donation', $counts, 'counts' ); wp_cache_set( $cache_key.'_donation', $counts, 'counts' );
return $counts; return $counts;
} }
/** /**
......
...@@ -105,7 +105,13 @@ class WooCommerce_Quick_Donation_DB { ...@@ -105,7 +105,13 @@ class WooCommerce_Quick_Donation_DB {
$db_request = $wpdb->delete( WC_QD_TB, array('donationid' => $id)); $db_request = $wpdb->delete( WC_QD_TB, array('donationid' => $id));
return $db_request; return $db_request;
} }
public function delete_donation_logs(){
global $wpdb;
$db_request = $wpdb->query("DELETE FROM ".WC_QD_TB);
return $db_request;
}
public function extract_donation_id($ids){ public function extract_donation_id($ids){
$return_ids = array(); $return_ids = array();
......
...@@ -6,6 +6,13 @@ jQuery(document).ready(function(){ ...@@ -6,6 +6,13 @@ jQuery(document).ready(function(){
if(jQuery(this).hasClass('wcqdAutoRemove')){ if(jQuery(this).hasClass('wcqdAutoRemove')){
autoRemove = true; autoRemove = true;
} }
if(jQuery(this).hasClass('ConfirmAction')){
var r = confirm(jQuery(this).attr('data-alert-text'));
if (r != true) { return ; }
}
var Spinner = jQuery('<span class="spinner WCQDSpinner"></span>'); var Spinner = jQuery('<span class="spinner WCQDSpinner"></span>');
var Clicked = jQuery(this); var Clicked = jQuery(this);
var POST_URL = jQuery(this).attr('href'); var POST_URL = jQuery(this).attr('href');
......
...@@ -5,8 +5,8 @@ Tags: WooCommerce,Quick Dontion,quick donation,online donation,wordpress donatio ...@@ -5,8 +5,8 @@ Tags: WooCommerce,Quick Dontion,quick donation,online donation,wordpress donatio
Requires at least: 3.0 or higher Requires at least: 3.0 or higher
Tested up to: 4.4 Tested up to: 4.4
WC requires at least: 1.0 WC requires at least: 1.0
WC tested up to: 2.4.8 WC tested up to: 2.4.10
Stable tag: 1.3.7 Beta Stable tag: 1.3.7.1 Beta
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
...@@ -120,6 +120,12 @@ Yes you can! Join in on our <a href="https://github.com/technofreaky/woocomerce- ...@@ -120,6 +120,12 @@ Yes you can! Join in on our <a href="https://github.com/technofreaky/woocomerce-
== Changelog == == Changelog ==
= 1.3.7.1 =
* **Fixed** - Fixed Empty Trash Issue
* **Fixed** - [`T_PAAMAYIM_NEKUDOTAYIM` Critical: Update to latest kills admin area] (https://github.com/technofreaky/woocomerce-quick-donation/issues/58) After Last UPDATE [1.3.7]
* **Added** - Option To Clear Donation Log In system tools menu
= 1.3.7 = = 1.3.7 =
* **Added** - French translation * **Added** - French translation
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* @author Varun Sridharan * @author Varun Sridharan
* @package WooCommerce Quick Donation/Templates/fields * @package WooCommerce Quick Donation/Templates/fields
* @version 0.2 * @version 0.3
*/ */
?> ?>
...@@ -22,7 +22,7 @@ foreach($project_list as $id => $val){ ...@@ -22,7 +22,7 @@ foreach($project_list as $id => $val){
} }
$field_output .= ' </optgroup>'; $field_output .= ' </optgroup>';
} else { } else {
if($pre_selected == $k){$attr = 'selected';} if($pre_selected == $id){$attr = 'selected';}
$field_output .= '<option value="'.$id.'" '.$attr.'>'.$val.'</option>'; $field_output .= '<option value="'.$id.'" '.$attr.'>'.$val.'</option>';
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Quick Donation * Plugin Name: WooCommerce Quick Donation
* Plugin URI: http://wordpress.org/plugins/woocommerce-quick-donation/ * Plugin URI: http://wordpress.org/plugins/woocommerce-quick-donation/
* Description: Turns WooCommerce Into Online Donation * Description: Turns WooCommerce Into Online Donation
* Version: 1.3.7 BETA * Version: 1.3.7.1 BETA
* Author: Varun Sridharan * Author: Varun Sridharan
* Author URI: http://varunsridharan.in * Author URI: http://varunsridharan.in
* Text Domain: woocommerce-quick-donation * Text Domain: woocommerce-quick-donation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment