-
Notifications
You must be signed in to change notification settings - Fork 1
/
easy-digital-downloads-remove-past-transactions-and-logs.php
204 lines (163 loc) · 7.16 KB
/
easy-digital-downloads-remove-past-transactions-and-logs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
Plugin Name: Easy Digital Downloads - Remove Purchases
Plugin URI: http://www.nasteriadis.gr/easy-digital-downloads-remove-purchases
Description: This plugin is an extension of the easy digital downloads and enables the user to delete transactions stores in the db both completely or partially.
Version: 1.0
Author: Nick C. Asteriadis
Author URI: http://www.nasteriadis.gr/
Depends: Easy Digital Downloads
License:
Copyright 2013 ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once('helpers.php');
require_once('delete-functions.php');
add_action('init','check_edd_existance');
function check_edd_existance(){
$edd_slug = 'easy-digital-downloads';
if(!is_plugin_active_from_slug($edd_slug)){
if(is_admin())
// give admin notice
add_action('admin_notices', 'edd_does_not_exist_notice');
else
// halt plugin in front end
return;
}
}
add_filter('edd_reports_contextual_help', 'add_delete_help_screen',10,1);
function add_delete_help_screen($screen){
$screen->add_help_tab(
array(
'id' => 'edd-reports-delete',
'title' => __( 'Delete', 'eddrp' ),
'content' =>
'<p>' . __( 'This screen allows you to delete the past transaction.', 'edd' ) . '</p>' .
'<p>' . __( '<strong>All</strong> - You can delete all the past transaction from the db', 'edd' ) . '</p>' .
'<p>' . __( '<strong>Partial Delete</strong> - You can select which transaction you want to delete', 'edd' ) . '</p>'
)
);
}
add_action('admin_head', 'add_admin_head_styles');
function add_admin_head_styles(){
?>
<style>
.delete-items { margin: 0 10px 10px 0!important;}
.delete-button { margin-top: 20px!important; }
</style>
<?php
}
add_action('edd_reports_tabs', 'add_delete_screen_option');
function add_delete_screen_option(){
global $edd_options;
$current_page = admin_url( 'edit.php?post_type=download&page=edd-reports' );
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'reports';
?>
<a href="<?php echo add_query_arg( array( 'tab' => 'delete', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'delete' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Delete', 'edd' ); ?></a>
<?php
}
function edd_reports_tab_delete() {
?>
<div class="metabox-holder">
<div id="post-body">
<div id="post-body-content">
<?php do_action( 'edd_reports_tab_delete_content_top' ); ?>
<div class="postbox">
<h3><span><?php _e( 'Delete All Past Transaction & Logs', 'edd' ); ?></span></h3>
<div class="inside">
<p><?php _e( 'By clicking here you can delete all the past transction. <br/>Please ensure that you have a working backup in place. <br/>The action cannot be undone.', 'edd' ); ?></p>
<p><a class="button" href="<?php echo wp_nonce_url( add_query_arg( array( 'edd-action' => 'delete_transactions' ) ), 'edd_delete_transactions' ); ?>"><?php _e( 'Delete Transactions', 'edd' ); ?></a></p>
</div><!-- .inside -->
</div><!-- .postbox -->
<!--
<div class="postbox">
<h3><span><?php _e('Custom Delete of Purchases Data', 'edd'); ?></span></h3>
<div class="inside">
<p><?php _e( 'Select the data you want to delete from your database', 'edd' ); ?></p>
<p>
<form method="post">
<input type="checkbox" class='delete-items' name='delete[earnings]' value='1'><label>Delete Product Earnings</label><br/>
<input type="checkbox" class='delete-items' name='delete[purchase_meta]' value='1'><label>Delete Purchase Meta records</label><br/>
<input type="checkbox" class='delete-items' name='delete[log_meta]' value='1'><label>Delete Log Meta</label><br/>
<input type="checkbox" class='delete-items' name='delete[transaction_and_logs]' value='1'><label>Delete Transactions & Logs</label><br/>
<input type="hidden" name="edd-action" value="partially_delete_items"/>
<input type="submit" value="<?php _e( 'Delete Data', 'edd' ); ?>" class="button-secondary delete-button"/>
</form>
</p>
</div><!-- .inside
</div><!-- .postbox -->
<?php do_action( 'edd_reports_tab_delete_content_bottom' ); ?>
</div><!-- .post-body-content -->
</div><!-- .post-body -->
</div><!-- .metabox-holder -->
<?php
}
add_action( 'edd_reports_tab_delete', 'edd_reports_tab_delete' );
function edd_partially_delete_items($post_values){
if(!isset($post_values['delete']))
return;
if(isset($checked_options['earnings']))
delete_product_earnings_meta();
if(isset($checked_options['purchase_meta']))
delete_payment_meta();
if(isset($checked_options['log_meta']))
delete_log_meta();
if(isset($checked_options['transaction_and_logs']))
delete_transactions_and_logs();
}
add_action('edd_partially_delete_items', 'edd_partially_delete_items');
function edd_delete_transactions( $data ) {
$edd_delete_transaction = $_GET['_wpnonce'];
if ( wp_verify_nonce( $edd_delete_transaction, 'edd_delete_transactions' ) ) {
/**
* table: postmeta
* task: delete keys: _edd_download_earnings / _edd_download_sales
* connected with: download ids of the posts table
**/
update_product_earnings_meta();
/**
* table: postmeta
* task: delete keys: _edd_payment_gateway / _edd_payment_meta / _edd_payment_mode / _edd_payment_purchase_key / _edd_payment_total / _edd_payment_user_email / _edd_payment_user_id / _edd_payment_user_ip
* connected with: edd_payment ids of the posts table
**/
delete_payment_meta();
/**
* table: postmeta
* task: delete keys: _edd_log_payment_id / _edd_log_ip / _edd_log_file_id / _edd_log_user_id / _edd_log_user_info
* connected with: edd_log ids of the posts table
**/
delete_log_meta();
/**
* table: term_relationships
* task: delete all records
* connected with: edd_log ids of the posts table
**/
delete_taxonomy_records();
/**
* table: posts
* task: delete all records of the type edd_log and edd_payment
* connected with: no dependancies
**/
delete_transactions_and_logs();
/**
* table: term_taxonomy
* task: update all records in the table by making all values of the count column with edd_log_type identifier equal to 0
* connected with: no dependancies
**/
update_earning_count();
/* show a success message when everything is OK */
add_action('admin_notices', 'edd_successfull_deletion_of_all_records');
} else {
add_action('admin_notices', 'edd_unauthorised_nonce');
}
}
add_action( 'edd_delete_transactions', 'edd_delete_transactions' );