Advanced Database Cleaner - Version 1.0.0

Version Description

Download this release

Release Info

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

Version 1.0.0

README.txt ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Advanced Database Cleaner ===
2
+ Contributors: symptote
3
+ Tags: wordpress database cleaner, clean database, database, clean, cleaner, delete orphan data, delete revisions, delete draft, delete trash, delete spam, delete auto drfat, delete postmeta, commentmeta, relationships, transient feed, optimize database, optimize
4
+ Requires at least: 2.7
5
+ Tested up to: 4.3
6
+ Stable tag: 1.0.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Advanced Database Cleaner helps you remove all unused data such as "draft", "Spam Comments", "Orphan Postmeta", etc.
11
+
12
+ == Description ==
13
+ Advanced Database Cleaner is a must-have plugin that cleans your Wordpress database by removing unused data such as "revision", "draft", "auto draft", "moderated comments", "spam comments", "trash comments", "orphan postmeta", "orphan commentmeta", "orphan relationships", "dashboard transient feed".
14
+ It helps you optimize your Wordpress database and save space of your MySQL DB.
15
+ It cleans your database by one click.
16
+ The settings page allows you choose what data should be cleaned.
17
+ It is a must-have plugin to keep your database clean.
18
+
19
+ == Installation ==
20
+ This section describes how to install the plugin and get it working.
21
+
22
+ WordPress:
23
+
24
+ 1. Download and extract 'advanced-db-cleaner' to 'wp-content/plugins/'
25
+ 2. In wordpress 'Plugins' page, choose 'Activate'
26
+ 3. Go to "Dashboard" -> "Settings" -> "DB Cleaner"
27
+
28
+ == Screenshots ==
29
+ 1. Admin page screenshot
30
+
31
+ == Changelog ==
32
+ = 1.0.0 =
33
+ * First release
advanced-db-cleaner-admin.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action('admin_menu', 'adv_db_cleaner_admin');
4
+
5
+ // Add 'DB Cleaner' option page under settings in wordpress admin pannel
6
+ function adv_db_cleaner_admin() {
7
+ add_options_page('Advanced DB Cleaner Options', 'DB Cleaner','manage_options', __FILE__, 'adv_db_cleaner_page');
8
+ }
9
+
10
+ function adv_db_cleaner_page(){
11
+ ?>
12
+ <div class="wrap">
13
+ <h2>Advanced DB Cleaner</h2>
14
+ <?php
15
+ // Clean database and print result message
16
+ $adv_db_cleaner_message = '';
17
+ if(isset($_POST['adbc_post_type'])){
18
+ foreach($_POST['adbc_post_type'] as $adbc_type) {
19
+ adv_db_cleaner($adbc_type);
20
+ }
21
+ $adv_db_cleaner_message = __('Your database is now cleaned.', 'advanced-db-cleaner');
22
+ }
23
+ if($adv_db_cleaner_message != ''){
24
+ echo '<div id="adbc_message" class="updated settings-error notice is-dismissible"><p><strong>' . $adv_db_cleaner_message . '</strong></p></div>';
25
+ }
26
+ ?>
27
+ <form action="" method="post">
28
+ <p>
29
+ <table class="widefat" style="width:419px;">
30
+ <thead>
31
+ <tr>
32
+ <th scope="col"><?php _e('Type','advanced-db-cleaner'); ?></th>
33
+ <th scope="col"><?php _e('Count','advanced-db-cleaner'); ?></th>
34
+ <th scope="col"><?php _e('Select','advanced-db-cleaner'); ?></th>
35
+ </tr>
36
+ </thead>
37
+ <tbody id="the-list">
38
+ <tr class="alternate">
39
+ <td class="column-name"><?php _e('Revision','advanced-db-cleaner'); ?></td>
40
+ <td class="column-name"><?php echo adv_db_cleaner_count('revision'); ?></td>
41
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="revision"></td>
42
+ </tr>
43
+ <tr>
44
+ <td class="column-name"><?php _e('Draft','advanced-db-cleaner'); ?></td>
45
+ <td class="column-name"><?php echo adv_db_cleaner_count('draft'); ?></td>
46
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="draft"></td>
47
+ </tr>
48
+ <tr class="alternate">
49
+ <td class="column-name"><?php _e('Auto Draft','advanced-db-cleaner'); ?></td>
50
+ <td class="column-name"><?php echo adv_db_cleaner_count('autodraft'); ?></td>
51
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="autodraft"></td>
52
+ </tr>
53
+ <tr>
54
+ <td class="column-name"><?php _e('Moderated Comments','advanced-db-cleaner'); ?></td>
55
+ <td class="column-name"><?php echo adv_db_cleaner_count('moderated'); ?></td>
56
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="moderated"></td>
57
+ </tr>
58
+ <tr class="alternate">
59
+ <td class="column-name"><?php _e('Spam Comments','advanced-db-cleaner'); ?></td>
60
+ <td class="column-name"><?php echo adv_db_cleaner_count('spam'); ?></td>
61
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="spam"></td>
62
+ </tr>
63
+ <tr>
64
+ <td class="column-name"><?php _e('Trash Comments','advanced-db-cleaner'); ?></td>
65
+ <td class="column-name"><?php echo adv_db_cleaner_count('trash'); ?></td>
66
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="trash"></td>
67
+ </tr>
68
+ <tr class="alternate">
69
+ <td class="column-name"><?php _e('Orphan Postmeta','advanced-db-cleaner'); ?></td>
70
+ <td class="column-name"><?php echo adv_db_cleaner_count('postmeta'); ?></td>
71
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="postmeta"></td>
72
+ </tr>
73
+ <tr>
74
+ <td class="column-name"><?php _e('Orphan Commentmeta','advanced-db-cleaner'); ?></td>
75
+ <td class="column-name"><?php echo adv_db_cleaner_count('commentmeta'); ?></td>
76
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="commentmeta"></td>
77
+ </tr>
78
+ <tr class="alternate">
79
+ <td class="column-name"><?php _e('Orphan Relationships','advanced-db-cleaner'); ?></td>
80
+ <td class="column-name"><?php echo adv_db_cleaner_count('relationships'); ?></td>
81
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="relationships"></td>
82
+ </tr>
83
+ <tr>
84
+ <td class="column-name"><?php _e('Dashboard Transient Feed','advanced-db-cleaner'); ?></td>
85
+ <td class="column-name"><?php echo adv_db_cleaner_count('feed'); ?></td>
86
+ <td class="column-name"><input type="checkbox" name="adbc_post_type[]" value="feed"></td>
87
+ </tr>
88
+ </tbody>
89
+ </table>
90
+ </p>
91
+ <p>
92
+ <input type="submit" class="button-primary" value="<?php _e('Delete selected items','advanced-db-cleaner'); ?>" />
93
+ </p>
94
+ </form>
95
+ <br />
96
+ <div style="text-align:center">&copy; <?php echo date("Y"); ?> By Symptote</div>
97
+ </div>
98
+ <?php
99
+ }
100
+
101
+ function adv_db_cleaner($type){
102
+ global $wpdb;
103
+ switch($type){
104
+ case "revision":
105
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
106
+ $wpdb->query($adbc_sql);
107
+ break;
108
+ case "draft":
109
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
110
+ $wpdb->query($adbc_sql);
111
+ break;
112
+ case "autodraft":
113
+ $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
114
+ $wpdb->query($adbc_sql);
115
+ break;
116
+ case "moderated":
117
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
118
+ $wpdb->query($adbc_sql);
119
+ break;
120
+ case "spam":
121
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
122
+ $wpdb->query($adbc_sql);
123
+ break;
124
+ case "trash":
125
+ $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
126
+ $wpdb->query($adbc_sql);
127
+ break;
128
+ case "postmeta":
129
+ $adbc_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
130
+ //$adbc_sql = "DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
131
+ $wpdb->query($adbc_sql);
132
+ break;
133
+ case "commentmeta":
134
+ $adbc_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
135
+ $wpdb->query($adbc_sql);
136
+ break;
137
+ case "relationships":
138
+ $adbc_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
139
+ $wpdb->query($adbc_sql);
140
+ break;
141
+ case "feed":
142
+ $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_%'";
143
+ $wpdb->query($adbc_sql);
144
+ break;
145
+ }
146
+ }
147
+
148
+ function adv_db_cleaner_count($type){
149
+ global $wpdb;
150
+ switch($type){
151
+ case "revision":
152
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
153
+ $count = $wpdb->get_var($adbc_sql);
154
+ break;
155
+ case "draft":
156
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
157
+ $count = $wpdb->get_var($adbc_sql);
158
+ break;
159
+ case "autodraft":
160
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
161
+ $count = $wpdb->get_var($adbc_sql);
162
+ break;
163
+ case "moderated":
164
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
165
+ $count = $wpdb->get_var($adbc_sql);
166
+ break;
167
+ case "spam":
168
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
169
+ $count = $wpdb->get_var($adbc_sql);
170
+ break;
171
+ case "trash":
172
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
173
+ $count = $wpdb->get_var($adbc_sql);
174
+ break;
175
+ case "postmeta":
176
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
177
+ //$adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
178
+ $count = $wpdb->get_var($adbc_sql);
179
+ break;
180
+ case "commentmeta":
181
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
182
+ $count = $wpdb->get_var($adbc_sql);
183
+ break;
184
+ case "relationships":
185
+ $adbc_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
186
+ $count = $wpdb->get_var($adbc_sql);
187
+ break;
188
+ case "feed":
189
+ $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_%'";
190
+ $count = $wpdb->get_var($adbc_sql);
191
+ break;
192
+ }
193
+ return $count;
194
+ }
195
+ ?>
advanced-db-cleaner.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.0.0
6
+ Author: Jaafar Y.
7
+ Contributors: symptote
8
+ Text Domain: advanced-db-cleaner
9
+ Domain Path: /languages/
10
+ License: GPLv2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
+ */
13
+
14
+ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
15
+
16
+ add_action('init','load_db_cleaner_language');
17
+ function load_db_cleaner_language(){
18
+ $activeLocale = get_locale();
19
+ if(!empty($activeLocale)){
20
+ $langFile = dirname(__FILE__) . "/languages/" . $activeLocale . ".mo";
21
+ if(@file_exists($langFile) && is_readable($langFile)){
22
+ load_textdomain('advanced-db-cleaner', $langFile);
23
+ }
24
+ }
25
+ }
26
+
27
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'db_cleaner_add_action_links');
28
+ function db_cleaner_add_action_links($links){
29
+ $adc_settings_link = '<a href = "options-general.php?page=' . dirname(plugin_basename(__FILE__)) . '/advanced-db-cleaner-admin.php">' . __('Settings', 'advanced-db-cleaner') . '</a>';
30
+ array_unshift($links, $adc_settings_link);
31
+ return $links;
32
+ }
33
+
34
+ if(is_admin()){require_once('advanced-db-cleaner-admin.php');}
35
+
36
+ ?>
screenshot-1.png ADDED
Binary file