Advanced Database Cleaner - Version 1.2.0

Version Description

  • Some optimizations and style modifications
  • New feature: Adding "Reset database"
Download this release

Release Info

Developer symptote
Plugin Icon 128x128 Advanced Database Cleaner
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.1 to 1.2.0

README.txt CHANGED
@@ -1,22 +1,25 @@
1
  === Advanced Database Cleaner ===
2
  Contributors: symptote
3
  Donate Link: https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=Azq_P8u-Dy9AZSB3bmJFsrGWImHWiCoHtSE8KuC2SNdGQpreQxG8dl2tVZK&dispatch=5885d80a13c0db1f8e263663d3faee8d0b9dcb01a9b6dc564e45f62871326a5e
4
- Tags: plugin, plugins, plugin wordpress, wordpress, database cleaner, clean database, database clean, database, clean, cleaner, delete orphan data, delete revisions, delete draft, delete trash, delete spam, delete auto drfat, delete postmeta, delete commentmeta, delete relationships, delete transient feed, optimize database, database optimize, optimize, admin
5
  Requires at least: 2.7
6
  Tested up to: 4.3
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Advanced Database Cleaner helps you remove all unused data such as "draft", "revision", etc. It helps also optimize your database.
12
 
13
  == Description ==
14
 
15
  <h4>Description</h4>
16
  <br>
17
  Advanced Database Cleaner is a must-have plugin that cleans your WP database by:<br><br>
18
- 1. Removing unused data such as "revision", "draft", "auto draft", "moderated comments", "spam comments", "trash comments", "orphan postmeta", "orphan commentmeta", "orphan relationships", "dashboard transient feed".<br>
19
- 2. It helps you optimize your Wordpress database and save space of your MySQL DB.
 
 
 
20
  <br><br>
21
  * It cleans your database by one click.<br>
22
  * The settings page allows you choose what data should be cleaned.<br>
@@ -32,16 +35,21 @@ This section describes how to install the plugin and get it working.
32
  == Screenshots ==
33
  1. "Clean database" admin page screenshot
34
  2. "Optimize database" admin page screenshot
 
35
 
36
  == Changelog ==
37
 
 
 
 
 
38
  = 1.1.1 =
39
  * Some optimizations and style modifications
40
  * Adding "Donate link"
41
 
42
  = 1.1.0 =
43
  * Some optimizations and style modifications
44
- * Adding "Optimize Database"
45
 
46
  = 1.0.0 =
47
- * First release
1
  === Advanced Database Cleaner ===
2
  Contributors: symptote
3
  Donate Link: https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=Azq_P8u-Dy9AZSB3bmJFsrGWImHWiCoHtSE8KuC2SNdGQpreQxG8dl2tVZK&dispatch=5885d80a13c0db1f8e263663d3faee8d0b9dcb01a9b6dc564e45f62871326a5e
4
+ Tags: plugin, plugins, plugin wordpress, wordpress, database cleaner, clean database, database clean, database, clean, cleaner, delete orphan data, orphan data, delete revisions, revision, delete draft, draft, delete trash, trash, delete spam, spam, delete auto drfat, auto draft, delete postmeta, postmeta, delete commentmeta, commentmeta, delete relationships, relationships, delete transient feed, transient feed, optimize database, database optimize, database optimizer, optimize, optimizer, reset database, database reset, reset, admin
5
  Requires at least: 2.7
6
  Tested up to: 4.3
7
+ Stable tag: 1.2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Clean up your database by deleting unused data such as 'draft', Optimize your database or reset it to its initial state.
12
 
13
  == Description ==
14
 
15
  <h4>Description</h4>
16
  <br>
17
  Advanced Database Cleaner is a must-have plugin that cleans your WP database by:<br><br>
18
+ 1. Removing unused data such as "revision", "draft", "auto draft", "moderated comments", "spam comments", "trash comments", "orphan postmeta", "orphan commentmeta", "orphan relationships", "dashboard transient feed".
19
+ <br><br>
20
+ 2. Optimizing your Wordpress database. This will help you reducing storage space and improving efficiency when accessing your tables.
21
+ <br><br>
22
+ 3. Resetting your database back to its original state. This will help you making a fresh installation and skip the "5 minutes wordpress installation steps".
23
  <br><br>
24
  * It cleans your database by one click.<br>
25
  * The settings page allows you choose what data should be cleaned.<br>
35
  == Screenshots ==
36
  1. "Clean database" admin page screenshot
37
  2. "Optimize database" admin page screenshot
38
+ 3. "Reset database" admin page screenshot
39
 
40
  == Changelog ==
41
 
42
+ = 1.2.0 =
43
+ * Some optimizations and style modifications
44
+ * New feature: Adding "Reset database"
45
+
46
  = 1.1.1 =
47
  * Some optimizations and style modifications
48
  * Adding "Donate link"
49
 
50
  = 1.1.0 =
51
  * Some optimizations and style modifications
52
+ * New feature: Adding "Optimize Database"
53
 
54
  = 1.0.0 =
55
+ * First release: Hello world!
advanced-db-cleaner-admin.php CHANGED
@@ -2,382 +2,99 @@
2
  add_action('admin_init', 'adv_db_cleaner_register_styles' );
3
  add_action('admin_menu', 'adv_db_cleaner_add_admin_menu');
4
 
5
- // Add 'DB Cleaner' to Wordpress settings menu
6
  function adv_db_cleaner_add_admin_menu() {
7
  $hook_adv_db_cleaner = add_options_page('Advanced DB Cleaner Options', 'Database Cleaner','manage_options', __FILE__, 'adv_db_cleaner_page');
8
  add_action('admin_print_styles-' . $hook_adv_db_cleaner, 'adv_db_cleaner_enqueue_styles');
9
  }
10
 
11
- /* Register stylesheet. */
12
  function adv_db_cleaner_register_styles() {
13
  wp_register_style('adv_db_cleaner_css', plugins_url() .'/'. dirname(plugin_basename(__FILE__)) . '/css/style.css');
14
  }
15
 
16
- /* Enqueue stylesheet. */
17
  function adv_db_cleaner_enqueue_styles() {
18
  wp_enqueue_style( 'adv_db_cleaner_css' );
19
  }
20
 
21
- /* The admin page content */
22
  function adv_db_cleaner_page(){
23
  ?>
24
  <div class="wrap">
25
  <h2>Advanced DB Cleaner</h2>
26
  <?php
27
- // Clean database and print result message
28
  $adv_db_cleaner_message = '';
 
29
  if(isset($_POST['adbc_post_type'])){
30
  foreach($_POST['adbc_post_type'] as $adbc_type) {
31
  adv_db_cleaner($adbc_type);
32
  }
33
- $adv_db_cleaner_message = __('Your database is now cleaned.', 'advanced-db-cleaner');
34
- }
35
-
36
- if(isset($_POST['aDBc_optimize_form'])){
37
  adv_db_cleaner_optimize();
38
- $adv_db_cleaner_message = __('Your database is now optimized.', 'advanced-db-cleaner');
39
- }
40
-
 
 
 
 
 
 
 
41
  if($adv_db_cleaner_message != ''){
42
- echo '<div id="adbc_message" class="updated settings-error notice is-dismissible"><p><strong>' . $adv_db_cleaner_message . '</strong></p></div>';
43
  }
44
  ?>
45
 
46
-
47
- <div class="tabBox">
48
- <?php
49
- $aDBc_tab_list = array(
50
- array("id"=>"aDBc-clean","title"=>"Clean Database"),
51
- array("id"=>"aDBc-optimize","title"=>"Optimize Database")
52
- );
 
53
 
54
- foreach ($aDBc_tab_list as $key => $value){
55
- $checked = "";
56
- if((!isset($_POST["aDBc_clean_form"]) && !isset($_POST["aDBc_optimize_form"]) && $value["id"] == "aDBc-clean")
57
- || (isset($_POST["aDBc_optimize_form"]) && $value["id"] == "aDBc-optimize")
58
- || (isset($_POST["aDBc_clean_form"]) && $value["id"] == "aDBc-clean")){
59
- $checked = 'checked = "checked"';
 
 
 
 
60
  }
61
- echo '<input '.$checked.' type="radio" id="'.$value["id"].'" name="tabGroup1">'."\n";
62
- echo '<label for="'.$value["id"].'">'.$value["title"].'</label>'."\n";
63
- }
64
- ?>
65
-
66
- <div class="tab1">
67
- <form action="" method="post">
68
- <p>
69
- <table class="widefat" style="width: 400px; border: 0px; box-shadow: 0 1px 0px #ccc;">
70
- <thead>
71
- <tr>
72
- <th scope="col"><b><?php _e('Type','advanced-db-cleaner'); ?></b></th>
73
- <th scope="col"><b><?php _e('Count','advanced-db-cleaner'); ?></b></th>
74
- <th scope="col"><b><?php _e('Select','advanced-db-cleaner'); ?></b></th>
75
- </tr>
76
- </thead>
77
- <tbody id="the-list">
78
- <tr class="alternate">
79
- <td class="column-name"><?php _e('Revision','advanced-db-cleaner'); ?></td>
80
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('revision'); ?></td>
81
- <td class="column-name">
82
- <div class="squaredFour">
83
- <input id="aDBc_check1" type="checkbox" name="adbc_post_type[]" value="revision" />
84
- <label for="aDBc_check1"></label>
85
- </div>
86
- </td>
87
- </tr>
88
- <tr class="alternate">
89
- <td class="column-name"><?php _e('Draft','advanced-db-cleaner'); ?></td>
90
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('draft'); ?></td>
91
- <td class="column-name">
92
- <div class="squaredFour">
93
- <input id="aDBc_check2" type="checkbox" name="adbc_post_type[]" value="draft" />
94
- <label for="aDBc_check2"></label>
95
- </div>
96
- </td>
97
- </tr>
98
- <tr class="alternate">
99
- <td class="column-name"><?php _e('Auto Draft','advanced-db-cleaner'); ?></td>
100
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('autodraft'); ?></td>
101
- <td class="column-name">
102
- <div class="squaredFour">
103
- <input id="aDBc_check3" type="checkbox" name="adbc_post_type[]" value="autodraft" />
104
- <label for="aDBc_check3"></label>
105
- </div>
106
- </td>
107
- </tr>
108
- <tr class="alternate">
109
- <td class="column-name"><?php _e('Moderated Comments','advanced-db-cleaner'); ?></td>
110
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('moderated'); ?></td>
111
- <td class="column-name">
112
- <div class="squaredFour">
113
- <input id="aDBc_check4" type="checkbox" name="adbc_post_type[]" value="moderated" />
114
- <label for="aDBc_check4"></label>
115
- </div>
116
- </td>
117
- </tr>
118
- <tr class="alternate">
119
- <td class="column-name"><?php _e('Spam Comments','advanced-db-cleaner'); ?></td>
120
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('spam'); ?></td>
121
- <td class="column-name">
122
- <div class="squaredFour">
123
- <input id="aDBc_check5" type="checkbox" name="adbc_post_type[]" value="spam" />
124
- <label for="aDBc_check5"></label>
125
- </div>
126
- </td>
127
- </tr>
128
- <tr class="alternate">
129
- <td class="column-name"><?php _e('Trash Comments','advanced-db-cleaner'); ?></td>
130
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('trash'); ?></td>
131
- <td class="column-name">
132
- <div class="squaredFour">
133
- <input id="aDBc_check6" type="checkbox" name="adbc_post_type[]" value="trash" />
134
- <label for="aDBc_check6"></label>
135
- </div>
136
- </td>
137
- </tr>
138
- <tr class="alternate">
139
- <td class="column-name"><?php _e('Orphan Postmeta','advanced-db-cleaner'); ?></td>
140
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('postmeta'); ?></td>
141
- <td class="column-name">
142
- <div class="squaredFour">
143
- <input id="aDBc_check7" type="checkbox" name="adbc_post_type[]" value="postmeta" />
144
- <label for="aDBc_check7"></label>
145
- </div>
146
- </td>
147
- </tr>
148
- <tr class="alternate">
149
- <td class="column-name"><?php _e('Orphan Commentmeta','advanced-db-cleaner'); ?></td>
150
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('commentmeta'); ?></td>
151
- <td class="column-name">
152
- <div class="squaredFour">
153
- <input id="aDBc_check8" type="checkbox" name="adbc_post_type[]" value="commentmeta" />
154
- <label for="aDBc_check8"></label>
155
- </div>
156
- </td>
157
- </tr>
158
- <tr class="alternate">
159
- <td class="column-name"><?php _e('Orphan Relationships','advanced-db-cleaner'); ?></td>
160
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('relationships'); ?></td>
161
- <td class="column-name">
162
- <div class="squaredFour">
163
- <input id="aDBc_check9" type="checkbox" name="adbc_post_type[]" value="relationships" />
164
- <label for="aDBc_check9"></label>
165
- </div>
166
- </td>
167
- </tr>
168
- <tr class="alternate">
169
- <td class="column-name"><?php _e('Dashboard Transient Feed','advanced-db-cleaner'); ?></td>
170
- <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('feed'); ?></td>
171
- <td class="column-name">
172
- <div class="squaredFour">
173
- <input id="aDBc_check10" type="checkbox" name="adbc_post_type[]" value="feed" />
174
- <label for="aDBc_check10"></label>
175
- </div>
176
- </td>
177
- </tr>
178
- </tbody>
179
- </table>
180
- </p>
181
- <p>
182
- <input type="hidden" name="aDBc_clean_form" value="" />
183
- <input type="submit" class="button-primary" value="<?php _e('Delete selected items','advanced-db-cleaner'); ?>" />
184
- </p>
185
- </form>
186
- </div>
187
 
188
- <div class="tab2">
189
- <form action="" method="post">
190
- <p>
191
- <table class="widefat" style="border: 0px; box-shadow: 0 1px 0px #ccc;">
192
- <thead>
193
- <tr>
194
- <th scope="col"><b><?php _e('#','advanced-db-cleaner'); ?></b></th>
195
- <th scope="col"><b><?php _e('Table','advanced-db-cleaner'); ?></b></th>
196
- <th scope="col" style="text-align:right; width:80px"><b><?php _e('Rows','advanced-db-cleaner'); ?></b></th>
197
- <th scope="col" style="text-align:right; width:100px"><b><?php _e('Size','advanced-db-cleaner'); ?></b></th>
198
- <th scope="col" style="text-align:right; width:80px"><b><?php _e('Lost','advanced-db-cleaner'); ?></b></th>
199
- </tr>
200
- </thead>
201
- <tbody id="the-list">
202
- <?php
203
- global $wpdb;
204
- $aDBc_tableID = 0;
205
- $total_rows = 0;
206
- $total_size = 0;
207
- $total_lost = 0;
208
- $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
209
- $result = $wpdb->get_results($adbc_sql);
210
- foreach($result as $row){
211
- $aDBc_tableID += 1;
212
- $total_rows += $row->Rows;
213
- $table_size = ($row->Data_length + $row->Index_length) / 1024;
214
- $total_size += $table_size;
215
- $total_lost += $row->Data_free;
216
- echo "<tr class='alternate'>
217
- <td class='column-name' style='width:30px'>". $aDBc_tableID ."</td>
218
- <td class='column-name'>". $row->Name ."</td>
219
- <td class='column-name' style='text-align:right'>". $row->Rows ."</td>
220
- <td class='column-name' style='text-align:right'>". sprintf("%0.2f", $table_size) ." KB</td>
221
- <td class='column-name' style='text-align:right'>". ($row->Data_free > 0 ? $row->Data_free . ' o' : '--') ."</td>
222
- </tr>\n";
223
- }
224
- ?>
225
- </tbody>
226
- <tfoot>
227
- <tr class="alternate">
228
- <th scope="col" style="font-size:12px"><?php _e('Total','advanced-db-cleaner'); ?></th>
229
- <th scope="col" style="text-align:left"><b><?php echo $aDBc_tableID; ?></b></th>
230
- <th scope="col" style="text-align:right"><b><?php echo $total_rows; ?></b></th>
231
- <th scope="col" style="text-align:right"><b><?php echo sprintf("%0.2f", $total_size).'</b> KB'; ?></th>
232
- <th scope="col" style="text-align:right"><b><?php echo $total_lost .'</b> o'; ?></th>
233
- </tr>
234
- </tfoot>
235
- </table>
236
- </p>
237
- <p>
238
- <input type="hidden" name="aDBc_optimize_form" value="" />
239
- <input type="submit" class="button-primary" value="<?php _e('Optimize database','advanced-db-cleaner'); ?>" />
240
- </p>
241
- </form>
242
- </div>
243
- </div>
244
-
245
- <div class="aDBcSidebar">
246
- <div>
247
- <center><h2>Advanced Database Cleaner</h2></center>
248
- <!--<p>See what is new in <a href="#">version 4.3.9</a></p>-->
249
-
250
- <p>Please donate to keep the development alive. Every contribution will be more than welcome.</p>
251
- <p style="text-align:right">Thank you!</p>
252
- <center>
253
- <!-- Donate -->
254
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
255
- <input type="hidden" name="cmd" value="_donations">
256
- <input type="hidden" name="business" value="younes.jfr@gmail.com">
257
- <input type="hidden" name="lc" value="US">
258
- <input type="hidden" name="item_name" value="Advanced Database Cleaner">
259
- <input type="hidden" name="no_note" value="0">
260
- <input type="hidden" name="currency_code" value="USD">
261
- <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
262
- <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
263
- <img alt="" border="0" src="https://www.paypalobjects.com/fr_XC/i/scr/pixel.gif" width="1" height="1">
264
- </form>
265
- </center>
266
-
267
 
 
 
 
268
 
 
 
 
 
269
  </div>
270
- <div style="background: #1A9AC9; border-top: 1px solid #ccc; text-align: center; color: #fff">
271
- &copy; <?php echo date("Y"); ?> Created by <b>Younes JFR</b>
 
272
  </div>
 
273
  </div>
274
 
275
  </div>
276
  <?php
277
  }
278
 
279
- function adv_db_cleaner($type){
280
- global $wpdb;
281
- switch($type){
282
- case "revision":
283
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
284
- $wpdb->query($adbc_sql);
285
- break;
286
- case "draft":
287
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
288
- $wpdb->query($adbc_sql);
289
- break;
290
- case "autodraft":
291
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
292
- $wpdb->query($adbc_sql);
293
- break;
294
- case "moderated":
295
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
296
- $wpdb->query($adbc_sql);
297
- break;
298
- case "spam":
299
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
300
- $wpdb->query($adbc_sql);
301
- break;
302
- case "trash":
303
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
304
- $wpdb->query($adbc_sql);
305
- break;
306
- case "postmeta":
307
- $adbc_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
308
- //$adbc_sql = "DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
309
- $wpdb->query($adbc_sql);
310
- break;
311
- case "commentmeta":
312
- $adbc_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
313
- $wpdb->query($adbc_sql);
314
- break;
315
- case "relationships":
316
- $adbc_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
317
- $wpdb->query($adbc_sql);
318
- break;
319
- case "feed":
320
- $adbc_sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
321
- $wpdb->query($adbc_sql);
322
- break;
323
- }
324
- }
325
 
326
- function adv_db_cleaner_count($type){
327
- global $wpdb;
328
- switch($type){
329
- case "revision":
330
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
331
- $count = $wpdb->get_var($adbc_sql);
332
- break;
333
- case "draft":
334
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
335
- $count = $wpdb->get_var($adbc_sql);
336
- break;
337
- case "autodraft":
338
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
339
- $count = $wpdb->get_var($adbc_sql);
340
- break;
341
- case "moderated":
342
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
343
- $count = $wpdb->get_var($adbc_sql);
344
- break;
345
- case "spam":
346
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
347
- $count = $wpdb->get_var($adbc_sql);
348
- break;
349
- case "trash":
350
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
351
- $count = $wpdb->get_var($adbc_sql);
352
- break;
353
- case "postmeta":
354
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
355
- //$adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
356
- $count = $wpdb->get_var($adbc_sql);
357
- break;
358
- case "commentmeta":
359
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
360
- $count = $wpdb->get_var($adbc_sql);
361
- break;
362
- case "relationships":
363
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
364
- $count = $wpdb->get_var($adbc_sql);
365
- break;
366
- case "feed":
367
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
368
- $count = $wpdb->get_var($adbc_sql);
369
- break;
370
- }
371
- return $count;
372
- }
373
-
374
- function adv_db_cleaner_optimize(){
375
- global $wpdb;
376
- $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
377
- $result = $wpdb->get_results($adbc_sql);
378
- foreach($result as $row){
379
- $adbc_sql = 'OPTIMIZE TABLE '.$row->Name;
380
- $wpdb->query($adbc_sql);
381
- }
382
- }
383
  ?>
2
  add_action('admin_init', 'adv_db_cleaner_register_styles' );
3
  add_action('admin_menu', 'adv_db_cleaner_add_admin_menu');
4
 
5
+ /* --- Add 'DB Cleaner' to Wordpress settings menu ---------- */
6
  function adv_db_cleaner_add_admin_menu() {
7
  $hook_adv_db_cleaner = add_options_page('Advanced DB Cleaner Options', 'Database Cleaner','manage_options', __FILE__, 'adv_db_cleaner_page');
8
  add_action('admin_print_styles-' . $hook_adv_db_cleaner, 'adv_db_cleaner_enqueue_styles');
9
  }
10
 
11
+ /* --- Register stylesheet ---------------------------------- */
12
  function adv_db_cleaner_register_styles() {
13
  wp_register_style('adv_db_cleaner_css', plugins_url() .'/'. dirname(plugin_basename(__FILE__)) . '/css/style.css');
14
  }
15
 
16
+ /* --- Enqueue stylesheet ----------------------------------- */
17
  function adv_db_cleaner_enqueue_styles() {
18
  wp_enqueue_style( 'adv_db_cleaner_css' );
19
  }
20
 
21
+ /* --- The admin page content ------------------------------- */
22
  function adv_db_cleaner_page(){
23
  ?>
24
  <div class="wrap">
25
  <h2>Advanced DB Cleaner</h2>
26
  <?php
27
+ // If one of the forms is sent, then process data and print results
28
  $adv_db_cleaner_message = '';
29
+ $adv_db_cleaner_message_class = 'updated settings-error notice is-dismissible';
30
  if(isset($_POST['adbc_post_type'])){
31
  foreach($_POST['adbc_post_type'] as $adbc_type) {
32
  adv_db_cleaner($adbc_type);
33
  }
34
+ $adv_db_cleaner_message = __('Database cleaned successfully!', 'advanced-db-cleaner');
35
+ }elseif(isset($_POST['aDBc_optimize_form'])){
 
 
36
  adv_db_cleaner_optimize();
37
+ $adv_db_cleaner_message = __('Database optimized successfully!', 'advanced-db-cleaner');
38
+ }elseif(isset($_POST['aDBc_reset_form'])){
39
+ if($_POST['aDBc_reset_comfirmation'] == 'reset'){
40
+ adv_db_cleaner_reset();
41
+ }else{
42
+ $adv_db_cleaner_message = __('Please type the word "reset" correctly in the text box below.', 'advanced-db-cleaner');
43
+ $adv_db_cleaner_message_class = 'error';
44
+ }
45
+ }
46
+ // Print message
47
  if($adv_db_cleaner_message != ''){
48
+ echo '<div id="adbc_message" class="'. $adv_db_cleaner_message_class .'"><p><strong>' . $adv_db_cleaner_message . '</strong></p></div>';
49
  }
50
  ?>
51
 
52
+ <div style="margin-right:300px">
53
+ <div class="tabBox">
54
+ <?php
55
+ $aDBc_tab_list = array(
56
+ array("id"=>"aDBc-clean","title"=>"Clean Database"),
57
+ array("id"=>"aDBc-optimize","title"=>"Optimize Database"),
58
+ array("id"=>"aDBc-reset","title"=>"Reset Database")
59
+ );
60
 
61
+ foreach ($aDBc_tab_list as $key => $value){
62
+ $checked = "";
63
+ if((!isset($_POST["aDBc_clean_form"]) && !isset($_POST["aDBc_optimize_form"]) && !isset($_POST["aDBc_reset_form"]) && $value["id"] == "aDBc-clean")
64
+ || (isset($_POST["aDBc_optimize_form"]) && $value["id"] == "aDBc-optimize")
65
+ || (isset($_POST["aDBc_clean_form"]) && $value["id"] == "aDBc-clean")
66
+ || (isset($_POST["aDBc_reset_form"]) && $value["id"] == "aDBc-reset")){
67
+ $checked = 'checked = "checked"';
68
+ }
69
+ echo '<input '.$checked.' type="radio" id="'.$value["id"].'" name="tabGroup1">'."\n";
70
+ echo '<label for="'.$value["id"].'">'.$value["title"].'</label>'."\n";
71
  }
72
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ <div class="tab1">
75
+ <?php include_once 'includes/clean-db.php'; ?>
76
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
+ <div class="tab2">
79
+ <?php include_once 'includes/optimize-db.php'; ?>
80
+ </div>
81
 
82
+ <div class="tab3">
83
+ <?php include_once 'includes/reset-db.php'; ?>
84
+ </div>
85
+
86
  </div>
87
+
88
+ <div class="aDBcSidebar">
89
+ <?php include_once 'includes/sidebar.php'; ?>
90
  </div>
91
+
92
  </div>
93
 
94
  </div>
95
  <?php
96
  }
97
 
98
+ include_once 'includes/functions.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  ?>
advanced-db-cleaner.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
  /*
3
  Plugin Name: Advanced Database Cleaner
4
- Description: Clean your database and save space by removing unused data such as "draft", "Spam Comments", "Orphan Postmeta", etc.
5
- Version: 1.1.1
6
  Author: Younes JFR.
7
  Contributors: symptote
8
  Text Domain: advanced-db-cleaner
1
  <?php
2
  /*
3
  Plugin Name: Advanced Database Cleaner
4
+ Description: Clean up your database by deleting unused data such as 'draft', Optimize your database or reset it to its initial state.
5
+ Version: 1.2.0
6
  Author: Younes JFR.
7
  Contributors: symptote
8
  Text Domain: advanced-db-cleaner
css/style.css CHANGED
@@ -1,8 +1,8 @@
1
  .tabBox {
2
  border-radius: 4px;
3
  margin: 10px 0 40px 0;
4
- height: auto;
5
  float: left;
 
6
  }
7
 
8
  .tabBox > input[type="radio"] {
@@ -18,10 +18,10 @@
18
  -moz-border-radius: 5px 5px 0 0;
19
  -webkit-border-radius: 5px 5px 0 0;
20
  border-bottom: 0;
21
- padding: 10px 10px;
22
  background-color:#ddd;
23
- color: #555;
24
- font-size: 14px;
25
  }
26
 
27
  .tabBox > input[type="radio"]:checked + label {
@@ -46,7 +46,7 @@
46
  -webkit-border-radius: 0 5px 5px 5px;
47
  }
48
 
49
- #aDBc-clean:checked ~ .tab1, #aDBc-optimize:checked ~ .tab2, #aDBc-stats:checked ~ .tab3{
50
  display: block;
51
  }
52
 
@@ -116,7 +116,8 @@ input[type=checkbox] {
116
  float:right;
117
  border: 1px solid #ccc;
118
  background: #fff;
119
- margin: 10px 0 0 0;
 
120
  width: 280px;
121
  border-radius: 5px 5px 0 0;
122
  -moz-border-radius: 5px 5px 0 0;
1
  .tabBox {
2
  border-radius: 4px;
3
  margin: 10px 0 40px 0;
 
4
  float: left;
5
+ width: 100%;
6
  }
7
 
8
  .tabBox > input[type="radio"] {
18
  -moz-border-radius: 5px 5px 0 0;
19
  -webkit-border-radius: 5px 5px 0 0;
20
  border-bottom: 0;
21
+ padding: 8px 10px;
22
  background-color:#ddd;
23
+ color: #111;
24
+ font-size: 13px;
25
  }
26
 
27
  .tabBox > input[type="radio"]:checked + label {
46
  -webkit-border-radius: 0 5px 5px 5px;
47
  }
48
 
49
+ #aDBc-clean:checked ~ .tab1, #aDBc-optimize:checked ~ .tab2, #aDBc-reset:checked ~ .tab3{
50
  display: block;
51
  }
52
 
116
  float:right;
117
  border: 1px solid #ccc;
118
  background: #fff;
119
+ margin-right: -300px;
120
+ margin-top:44px;
121
  width: 280px;
122
  border-radius: 5px 5px 0 0;
123
  -moz-border-radius: 5px 5px 0 0;
includes/clean-db.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form action="" method="post">
2
+ <p>
3
+ <table class="widefat" style="width: 400px; border: 0px; box-shadow: 0 1px 0px #ccc;">
4
+ <thead>
5
+ <tr>
6
+ <th scope="col"><b><?php _e('Type','advanced-db-cleaner'); ?></b></th>
7
+ <th scope="col"><b><?php _e('Count','advanced-db-cleaner'); ?></b></th>
8
+ <th scope="col"><b><?php _e('Select','advanced-db-cleaner'); ?></b></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody id="the-list">
12
+ <tr class="alternate">
13
+ <td class="column-name"><?php _e('Revision','advanced-db-cleaner'); ?></td>
14
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('revision'); ?></td>
15
+ <td class="column-name">
16
+ <div class="squaredFour">
17
+ <input id="aDBc_check1" type="checkbox" name="adbc_post_type[]" value="revision" />
18
+ <label for="aDBc_check1"></label>
19
+ </div>
20
+ </td>
21
+ </tr>
22
+ <tr class="alternate">
23
+ <td class="column-name"><?php _e('Draft','advanced-db-cleaner'); ?></td>
24
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('draft'); ?></td>
25
+ <td class="column-name">
26
+ <div class="squaredFour">
27
+ <input id="aDBc_check2" type="checkbox" name="adbc_post_type[]" value="draft" />
28
+ <label for="aDBc_check2"></label>
29
+ </div>
30
+ </td>
31
+ </tr>
32
+ <tr class="alternate">
33
+ <td class="column-name"><?php _e('Auto Draft','advanced-db-cleaner'); ?></td>
34
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('autodraft'); ?></td>
35
+ <td class="column-name">
36
+ <div class="squaredFour">
37
+ <input id="aDBc_check3" type="checkbox" name="adbc_post_type[]" value="autodraft" />
38
+ <label for="aDBc_check3"></label>
39
+ </div>
40
+ </td>
41
+ </tr>
42
+ <tr class="alternate">
43
+ <td class="column-name"><?php _e('Moderated Comments','advanced-db-cleaner'); ?></td>
44
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('moderated'); ?></td>
45
+ <td class="column-name">
46
+ <div class="squaredFour">
47
+ <input id="aDBc_check4" type="checkbox" name="adbc_post_type[]" value="moderated" />
48
+ <label for="aDBc_check4"></label>
49
+ </div>
50
+ </td>
51
+ </tr>
52
+ <tr class="alternate">
53
+ <td class="column-name"><?php _e('Spam Comments','advanced-db-cleaner'); ?></td>
54
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('spam'); ?></td>
55
+ <td class="column-name">
56
+ <div class="squaredFour">
57
+ <input id="aDBc_check5" type="checkbox" name="adbc_post_type[]" value="spam" />
58
+ <label for="aDBc_check5"></label>
59
+ </div>
60
+ </td>
61
+ </tr>
62
+ <tr class="alternate">
63
+ <td class="column-name"><?php _e('Trash Comments','advanced-db-cleaner'); ?></td>
64
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('trash'); ?></td>
65
+ <td class="column-name">
66
+ <div class="squaredFour">
67
+ <input id="aDBc_check6" type="checkbox" name="adbc_post_type[]" value="trash" />
68
+ <label for="aDBc_check6"></label>
69
+ </div>
70
+ </td>
71
+ </tr>
72
+ <tr class="alternate">
73
+ <td class="column-name"><?php _e('Orphan Postmeta','advanced-db-cleaner'); ?></td>
74
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('postmeta'); ?></td>
75
+ <td class="column-name">
76
+ <div class="squaredFour">
77
+ <input id="aDBc_check7" type="checkbox" name="adbc_post_type[]" value="postmeta" />
78
+ <label for="aDBc_check7"></label>
79
+ </div>
80
+ </td>
81
+ </tr>
82
+ <tr class="alternate">
83
+ <td class="column-name"><?php _e('Orphan Commentmeta','advanced-db-cleaner'); ?></td>
84
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('commentmeta'); ?></td>
85
+ <td class="column-name">
86
+ <div class="squaredFour">
87
+ <input id="aDBc_check8" type="checkbox" name="adbc_post_type[]" value="commentmeta" />
88
+ <label for="aDBc_check8"></label>
89
+ </div>
90
+ </td>
91
+ </tr>
92
+ <tr class="alternate">
93
+ <td class="column-name"><?php _e('Orphan Relationships','advanced-db-cleaner'); ?></td>
94
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('relationships'); ?></td>
95
+ <td class="column-name">
96
+ <div class="squaredFour">
97
+ <input id="aDBc_check9" type="checkbox" name="adbc_post_type[]" value="relationships" />
98
+ <label for="aDBc_check9"></label>
99
+ </div>
100
+ </td>
101
+ </tr>
102
+ <tr class="alternate">
103
+ <td class="column-name"><?php _e('Dashboard Transient Feed','advanced-db-cleaner'); ?></td>
104
+ <td class="column-name aDBcCount"><?php echo adv_db_cleaner_count('feed'); ?></td>
105
+ <td class="column-name">
106
+ <div class="squaredFour">
107
+ <input id="aDBc_check10" type="checkbox" name="adbc_post_type[]" value="feed" />
108
+ <label for="aDBc_check10"></label>
109
+ </div>
110
+ </td>
111
+ </tr>
112
+ </tbody>
113
+ </table>
114
+ </p>
115
+ <p>
116
+ <input type="hidden" name="aDBc_clean_form" value="" />
117
+ <input type="submit" class="button-primary" value="<?php _e('Delete selected items','advanced-db-cleaner'); ?>" />
118
+ </p>
119
+ </form>
includes/functions.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function adv_db_cleaner($type){
4
+ global $wpdb;
5
+ switch($type){
6
+ case "revision":
7
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
8
+ $wpdb->query($adbc_sql);
9
+ break;
10
+ case "draft":
11
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
12
+ $wpdb->query($adbc_sql);
13
+ break;
14
+ case "autodraft":
15
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
16
+ $wpdb->query($adbc_sql);
17
+ break;
18
+ case "moderated":
19
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
20
+ $wpdb->query($adbc_sql);
21
+ break;
22
+ case "spam":
23
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
24
+ $wpdb->query($adbc_sql);
25
+ break;
26
+ case "trash":
27
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
28
+ $wpdb->query($adbc_sql);
29
+ break;
30
+ case "postmeta":
31
+ $adbc_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
32
+ //$adbc_sql = "DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
33
+ $wpdb->query($adbc_sql);
34
+ break;
35
+ case "commentmeta":
36
+ $adbc_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
37
+ $wpdb->query($adbc_sql);
38
+ break;
39
+ case "relationships":
40
+ $adbc_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
41
+ $wpdb->query($adbc_sql);
42
+ break;
43
+ case "feed":
44
+ $adbc_sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
45
+ $wpdb->query($adbc_sql);
46
+ break;
47
+ }
48
+ }
49
+
50
+ function adv_db_cleaner_count($type){
51
+ global $wpdb;
52
+ switch($type){
53
+ case "revision":
54
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
55
+ $count = $wpdb->get_var($adbc_sql);
56
+ break;
57
+ case "draft":
58
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
59
+ $count = $wpdb->get_var($adbc_sql);
60
+ break;
61
+ case "autodraft":
62
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
63
+ $count = $wpdb->get_var($adbc_sql);
64
+ break;
65
+ case "moderated":
66
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
67
+ $count = $wpdb->get_var($adbc_sql);
68
+ break;
69
+ case "spam":
70
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
71
+ $count = $wpdb->get_var($adbc_sql);
72
+ break;
73
+ case "trash":
74
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
75
+ $count = $wpdb->get_var($adbc_sql);
76
+ break;
77
+ case "postmeta":
78
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
79
+ //$adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
80
+ $count = $wpdb->get_var($adbc_sql);
81
+ break;
82
+ case "commentmeta":
83
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
84
+ $count = $wpdb->get_var($adbc_sql);
85
+ break;
86
+ case "relationships":
87
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
88
+ $count = $wpdb->get_var($adbc_sql);
89
+ break;
90
+ case "feed":
91
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
92
+ $count = $wpdb->get_var($adbc_sql);
93
+ break;
94
+ }
95
+ return $count;
96
+ }
97
+
98
+ function adv_db_cleaner_optimize(){
99
+ global $wpdb;
100
+ $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
101
+ $result = $wpdb->get_results($adbc_sql);
102
+ foreach($result as $row){
103
+ $adbc_sql = 'OPTIMIZE TABLE '.$row->Name;
104
+ $wpdb->query($adbc_sql);
105
+ }
106
+ }
107
+
108
+ function adv_db_cleaner_reset(){
109
+ require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
110
+ global $current_user, $wpdb;
111
+ $blogname = get_option( 'blogname' );
112
+ $admin_email = get_option( 'admin_email' );
113
+ $blog_public = get_option( 'blog_public' );
114
+ if ( $current_user->user_login != 'admin' ){
115
+ $user = get_user_by( 'login', 'admin' );
116
+ }
117
+ if ( empty( $user->user_level ) || $user->user_level < 10 ){
118
+ $user = $current_user;
119
+ }
120
+ $prefix = str_replace( '_', '\_', $wpdb->prefix );
121
+ $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$prefix}%'" );
122
+ foreach ( $tables as $table ) {
123
+ $wpdb->query( "DROP TABLE $table" );
124
+ }
125
+ // Install wordpress
126
+ $result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public);
127
+ extract( $result, EXTR_SKIP );
128
+ // Set user password
129
+ $query = $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id );
130
+ $wpdb->query( $query );
131
+ // Test for functions
132
+ $get_user_meta = function_exists( 'get_user_meta' ) ? 'get_user_meta' : 'get_usermeta';
133
+ $update_user_meta = function_exists( 'update_user_meta' ) ? 'update_user_meta' : 'update_usermeta';
134
+ // Say to wordpress that we will not use generated password
135
+ if ( $get_user_meta( $user_id, 'default_password_nag' ) ){
136
+ $update_user_meta( $user_id, 'default_password_nag', false );
137
+ }
138
+ if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) ){
139
+ $update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
140
+ }
141
+ // Reactivate the plugin (TODO)
142
+ //activate_plugin( 'plugins/advanced-db-cleaner/advanced-db-cleaner.php' );
143
+ // Clear all cookies associated with authentication
144
+ wp_clear_auth_cookie();
145
+ // Set the authentication cookies based User ID
146
+ wp_set_auth_cookie( $user_id );
147
+ // Redirect user to admin pannel
148
+ wp_redirect( admin_url());
149
+ }
150
+
151
+
152
+ ?>
includes/optimize-db.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form action="" method="post">
2
+ <p>
3
+ <table class="widefat" style="width: 600px; border: 0px; box-shadow: 0 1px 0px #ccc;">
4
+ <thead>
5
+ <tr>
6
+ <th scope="col"><b><?php _e('#','advanced-db-cleaner'); ?></b></th>
7
+ <th scope="col"><b><?php _e('Table','advanced-db-cleaner'); ?></b></th>
8
+ <th scope="col" style="text-align:right; width:80px"><b><?php _e('Rows','advanced-db-cleaner'); ?></b></th>
9
+ <th scope="col" style="text-align:right; width:100px"><b><?php _e('Size','advanced-db-cleaner'); ?></b></th>
10
+ <th scope="col" style="text-align:right; width:80px"><b><?php _e('Lost','advanced-db-cleaner'); ?></b></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody id="the-list">
14
+ <?php
15
+ global $wpdb;
16
+ $aDBc_tableID = 0;
17
+ $total_rows = 0;
18
+ $total_size = 0;
19
+ $total_lost = 0;
20
+ $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
21
+ $result = $wpdb->get_results($adbc_sql);
22
+ foreach($result as $row){
23
+ $aDBc_tableID += 1;
24
+ $total_rows += $row->Rows;
25
+ $table_size = ($row->Data_length + $row->Index_length) / 1024;
26
+ $total_size += $table_size;
27
+ $total_lost += $row->Data_free;
28
+ echo "<tr class='alternate'>
29
+ <td class='column-name' style='width:30px'>". $aDBc_tableID ."</td>
30
+ <td class='column-name'>". $row->Name ."</td>
31
+ <td class='column-name' style='text-align:right'>". $row->Rows ."</td>
32
+ <td class='column-name' style='text-align:right'>". sprintf("%0.2f", $table_size) ." KB</td>
33
+ <td class='column-name' style='text-align:right'>". ($row->Data_free > 0 ? $row->Data_free . ' o' : '--') ."</td>
34
+ </tr>\n";
35
+ }
36
+ ?>
37
+ </tbody>
38
+ <tfoot>
39
+ <tr class="alternate">
40
+ <th scope="col" style="font-size:12px"><?php _e('Total','advanced-db-cleaner'); ?></th>
41
+ <th scope="col" style="text-align:left"><b><?php echo $aDBc_tableID; ?></b></th>
42
+ <th scope="col" style="text-align:right"><b><?php echo $total_rows; ?></b></th>
43
+ <th scope="col" style="text-align:right"><b><?php echo sprintf("%0.2f", $total_size).'</b> KB'; ?></th>
44
+ <th scope="col" style="text-align:right"><b><?php echo $total_lost .'</b> o'; ?></th>
45
+ </tr>
46
+ </tfoot>
47
+ </table>
48
+ </p>
49
+ <p>
50
+ <input type="hidden" name="aDBc_optimize_form" value="" />
51
+ <input type="submit" class="button-primary" value="<?php _e('Optimize database','advanced-db-cleaner'); ?>" />
52
+ </p>
53
+ </form>
includes/reset-db.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ global $current_user;
3
+ $aDBc_admin = get_user_by( 'login', 'admin' );
4
+ $aDBc_admin_exists = 1;
5
+ if (!isset($aDBc_admin->user_login ) || $aDBc_admin->user_level < 10 ){
6
+ $aDBc_admin_exists = 0;
7
+ }
8
+ ?>
9
+
10
+
11
+
12
+ <h4 style="color:#32373c; font-size:15px">Details about the reset:</h4>
13
+
14
+ <ul style="list-style: square outside none; margin-left:40px;">
15
+ <li><font color="red"><b>ANY</b></font> data in your database will be lost. The reset makes a fresh installation of your database.</li>
16
+ <li>The reset does not delete or modify any of your plugins files or server files.</li>
17
+ <li>All your plugins will be deactivated (including this one). You should activate them manually after the reset.</li>
18
+ <?php if ($aDBc_admin_exists) { ?>
19
+ <li>The '<strong>admin</strong>' user exists and will be recreated with its <strong>current password</strong>.</li>
20
+ <?php } else {?>
21
+ <li>The 'admin' user does not exist. The user '<strong><?php echo esc_html( $current_user->user_login ); ?></strong>' will be recreated with its <strong>current password</strong> with user level 10.</li>
22
+ <?php } ?>
23
+ <li>After the reset, you will be redirected to the admin login page.</li>
24
+ </ul>
25
+ <br/>
26
+ <h3 style="color:#32373c">Go reset</h3>
27
+ <p>Type '<strong>reset</strong>' in the confirmation field below to confirm the reset and then click the reset button.</p>
28
+
29
+ <form id="wordpress_reset_form" action="" method="post">
30
+ <input type="hidden" name="aDBc_reset_form" value="" />
31
+ <input type="text" name="aDBc_reset_comfirmation" value="" />
32
+ <p class="submit">
33
+ <input type="submit" class="button-primary" value="Reset database" style="width: 130px; height: 50px; text-align:center; font-weight:bold"/>
34
+ </p>
35
+ </form>
includes/sidebar.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div>
2
+ <center><h2>Advanced Database Cleaner</h2></center>
3
+ <!--<p>See what is new in <a href="#">version 4.3.9</a></p>-->
4
+
5
+ <p style="text-align: justify">If you love this plugin and would like to make a donation, then you're awesome.</p>
6
+ <p style="text-align:right">Thank you!</p>
7
+ <center>
8
+ <!-- Donate -->
9
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
10
+ <input type="hidden" name="cmd" value="_donations">
11
+ <input type="hidden" name="business" value="younes.jfr@gmail.com">
12
+ <input type="hidden" name="lc" value="US">
13
+ <input type="hidden" name="item_name" value="Advanced Database Cleaner">
14
+ <input type="hidden" name="no_note" value="0">
15
+ <input type="hidden" name="currency_code" value="USD">
16
+ <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest">
17
+ <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
18
+ <img alt="" border="0" src="https://www.paypalobjects.com/fr_XC/i/scr/pixel.gif" width="1" height="1">
19
+ </form>
20
+ </center>
21
+
22
+ </div>
23
+ <div style="background: #1A9AC9; border-top: 1px solid #ccc; text-align: center; color: #fff">
24
+ &copy; <?php echo date("Y"); ?> Created by <b>Younes JFR</b>
25
+ </div>
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png ADDED
Binary file