Commit 90ffc6d0 authored by Varun Sridharan's avatar Varun Sridharan

Issue Fix And Minor Changes

* Fixed #42
* Fixed #51
* Reorderd Menu
* Added New Function `wcqd_delete_donation_entry`
parent 89e790ef
......@@ -21,11 +21,18 @@ class WooCommerce_Quick_Donation_Admin_Function {
add_action( 'post_row_actions', array($this,'protect_donation_product'),99,2);
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_action( 'delete_post', array($this,'delete_donation'));
add_action( 'wp_ajax_CreateDonationProduct', array($this,'create_donation_product') );
}
public function delete_donation($id){
if('shop_order' == get_post_type($id)){
if(wcqd_is_donation($id)){
WC_QD()->db()->delete_donation_entry($id);
}
}
}
public function hide_donation_order_woocommerce_order($query) {
global $pagenow,$post_type;
......
......@@ -102,18 +102,24 @@ class WooCommerce_Quick_Donation_Admin {
$name = 'edit.php?post_type='.WC_QD_PT;
if(empty($submenu)){return $submenu;}
$arr = array();
$submenu[$name][18][2] = $submenu[$name][5][2].'&page='.$submenu[$name][18][2];
$arr[] = $submenu[$name][18];
$arr[] = $submenu[$name][19];
$arr[] = $submenu[$name][5];
$seperator = array();
$seperator[0] = '';
$seperator[1] = 'read';
$seperator[2] = 'separator10';
$seperator[3] = '';
$seperator[4] = 'wp-menu-separator';
$arr[] = $submenu[$name][5];
$arr[] = $submenu[$name][10];
$arr[] = $submenu[$name][15];
$arr[] = $submenu[$name][16];
$arr[] = $submenu[$name][17];
$arr[] = $seperator;
$arr[] = $submenu[$name][18];
$arr[] = $submenu[$name][19];
$arr[] = $seperator;
$arr[] = $submenu[$name][17];
$arr[] = $submenu[$name][20];
//var_dump($arr); exit;
$submenu[$name] = $arr;
$submenu[$name] = $arr;
return $menu_ord;
}
......
......@@ -427,8 +427,8 @@ class WP_Donors_Listing_Table extends WP_List_Table {
$price = array();
foreach($donation_ids as $donation){
$order = wc_get_order($donation);
if($order === false){ wcqd_delete_donation_entry($donation); continue;}
$prices = $order->get_total();
$currname = $order->get_order_currency();
if(! isset($price[$currname])){$price[$currname] = 0;}
......
......@@ -100,6 +100,13 @@ class WooCommerce_Quick_Donation_DB {
return array();
}
public function delete_donation_entry($id){
global $wpdb;
$db_request = $wpdb->delete( WC_QD_TB, array('donationid' => $id));
return $db_request;
}
public function extract_donation_id($ids){
$return_ids = array();
foreach($ids as $i){
......
......@@ -66,6 +66,7 @@ class WooCommerce_Quick_Donation_Functions {
add_action( 'woocommerce_available_payment_gateways',array($this,'remove_gateway'));
add_filter( 'woocommerce_locate_template' , array($this,'wc_locate_template'),10,3);
add_filter( 'the_title', array($this,'wc_page_endpoint_title' ),10,2);
add_filter( 'wp_count_posts', array($this,'modify_wp_count_posts'),99,3);
}
public function get_template_list(){
......@@ -315,4 +316,32 @@ class WooCommerce_Quick_Donation_Functions {
}
return $located;
}
public function modify_wp_count_posts($old_status,$type, $perm = '' ) {
global $wpdb;
if ( ! post_type_exists( $type ) ) { return new stdClass;}
$cache_key = _count_posts_cache_key( $type, $perm );
$counts = wp_cache_get( $cache_key, 'wc_qd_modified_wp_count_posts' );
if ( false !== $counts ) { return apply_filters( 'wc_qd_modified_wp_count_posts', $counts, $type, $perm ); }
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE ";
$query .= " ID NOT IN (SELECT donationid FROM `".WC_QD_TB."`) ";
$query .= " AND post_type = %s ";
if ( 'readable' == $perm && is_user_logged_in() ) {
$post_type_object = get_post_type_object($type);
if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
$query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
get_current_user_id()
);
}
}
$query .= ' GROUP BY post_status';
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
$counts = array_fill_keys( get_post_stati(), 0 );
foreach ( $results as $row ) { $counts[ $row['post_status'] ] = $row['num_posts']; }
$counts = (object) $counts;
wp_cache_set( $cache_key, $counts, 'wc_qd_modified_wp_count_posts' );
return apply_filters( 'wc_qd_modified_wp_count_posts', $counts, $type, $perm );
}
}
......@@ -62,5 +62,11 @@ if(! function_exists('wcqd_get_project_name')){
}
}
if(! function_exists('wcqd_delete_donation_entry')){
function wcqd_delete_donation_entry($id){
return WC_QD()->db()->delete_donation_entry($id);
}
}
?>
\ No newline at end of file
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